Kaydet (Commit) c5d5b3cd authored tarafından esupoff's avatar esupoff Kaydeden (comit) Berker Peksag

Fix TypeError when accessing TreeWalk().__dict__ (#137)

Fixes #136
üst 70b5924e
......@@ -30,6 +30,9 @@ class MetaFlatten(type):
if base not in newbases:
newdict.update(vars(base))
newdict.update(clsdict)
# These are class-bound, we should let Python recreate them.
newdict.pop('__dict__', None)
newdict.pop('__weakref__', None)
# Delegate the real work to type
return type.__new__(clstype, name, newbases, newdict)
......
......@@ -53,6 +53,13 @@ Bug fixes
.. _`Issue 127`: https://github.com/berkerpeksag/astor/issues/127
.. _`PR 130`: https://github.com/berkerpeksag/astor/pull/130
* Fixed :class:`astor.tree_walk.TreeWalk` when attempting to access attributes
created by Python's type system (such as ``__dict__`` and ``__weakref__``)
(Reported and fixed by esupoff in `Issue 136`_ and `PR 137`_.)
.. _`Issue 136`: https://github.com/berkerpeksag/astor/issues/136
.. _`PR 137`: https://github.com/berkerpeksag/astor/pull/137
0.7.1 - 2018-07-06
------------------
......
......@@ -64,5 +64,17 @@ class FastCompareTestCase(unittest.TestCase):
check('a = 3 - (3, 4, 5)', 'a = 3 - (3, 4, 6)')
class TreeWalkTestCase(unittest.TestCase):
def test_auto_generated_attributes(self):
# See #136 for more details.
treewalk = astor.TreeWalk()
self.assertIsInstance(treewalk.__dict__, dict)
# Check that the inital state of the instance is empty.
self.assertEqual(treewalk.__dict__['nodestack'], [])
self.assertEqual(treewalk.__dict__['pre_handlers'], {})
self.assertEqual(treewalk.__dict__['post_handlers'], {})
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment