You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Base.replace, the method checks that self.parent is not None -
however, it (unfortunately), breaks this very property itself if self is
new, or self in new.
In particular, some fixers return node from transform if they don't want
to do anything. In that case, self.parent gets set to None, even though
new (which is self) is still connected to the tree.
This patch
a) short-cuts the case that self is new
b) arranges to set parent of the new nodes only after clearing parent of
self
Activity
loewis commentedon Sep 13, 2009
In Base.replace, the method checks that self.parent is not None -
however, it (unfortunately), breaks this very property itself if self is
new, or self in new.
In particular, some fixers return node from transform if they don't want
to do anything. In that case, self.parent gets set to None, even though
new (which is self) is still connected to the tree.
This patch
a) short-cuts the case that self is new
b) arranges to set parent of the new nodes only after clearing parent of
self
benjaminp commentedon Sep 13, 2009
Looks good, but it needs some tests.
meadori commentedon Jan 31, 2010
I updated the patch with a few unit tests:
euclid:trunk minge$ ./python.exe Lib/test/test_lib2to3.py
...
======================================================================
FAIL: test_replace (lib2to3.tests.test_pytree.TestNodes)
----------------------------------------------------------------------
======================================================================
FAIL: test_replace_with_list (lib2to3.tests.test_pytree.TestNodes)
----------------------------------------------------------------------
Ran 541 tests in 19.328s
FAILED (failures=2)
...
euclid:trunk minge$ patch -p0 < python.patch
patching file Lib/lib2to3/pytree.py
Hunk #1 succeeded at 132 (offset 2 lines).
Hunk #2 succeeded at 151 (offset 2 lines).
euclid:trunk minge$ ./python.exe Lib/test/test_lib2to3.py
...
----------------------------------------------------------------------
Ran 541 tests in 19.642s
OK