Fix DictsView.dicts instance attr shadowing Table.dicts() method#697
Fix DictsView.dicts instance attr shadowing Table.dicts() method#697gaoflow wants to merge 2 commits into
Conversation
DictsView (returned by fromdicts()) stored its input data as self.dicts, which shadowed the dicts() method inherited from Table. Calling .dicts() on a fromdicts() result raised TypeError because Python found the instance attribute (the raw dicts data) instead of the method. Rename the internal attribute to self._dicts throughout DictsView and DictsGeneratorView, consistent with the existing _header convention. Fixes petl-developers#643.
PR Summary by QodoFix fromdicts() DictsView attribute shadowing inherited Table.dicts() Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1.
|
|
Thanks, that is a good catch. I pushed dummy = dummytable(numrows=3, seed=42)
actual = fromdicts(dummy.dicts())
list(actual.dicts())Local verification: I also checked the current red 3.8/3.9 CI jobs. They fail before pytest runs, while building the package via |
Problem
fromdicts()returns aDictsView(inpetl/io/json.py) that stores itsinput data as
self.dicts. That name clashes with thedicts()methodinherited from
Table, which is bound at the class level viaTable.dicts = dictsinpetl/util/base.py.The instance attribute wins in Python's attribute-lookup order, so any
.dicts()call on the result raises:Minimal reproducer (reported in #643):
Fix
Rename the internal attribute
self.dicts→self._dictsin bothDictsViewandDictsGeneratorView, consistent with the existingself._headerconvention. Five call-sites updated (two in__init__, one inDictsView.__iter__, two inDictsGeneratorView.__iter__/_determine_header).A regression test is added to
petl/test/io/test_json.py.Fixes #643.
This pull request was prepared with the assistance of AI, under my direction and review.