This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Base.replace breaks tree
Type: behavior Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: wont fix
Dependencies: Superseder: Close 2to3 issues and list them here
View: 45544
Assigned To: Nosy List: benjamin.peterson, loewis, meador.inge
Priority: normal Keywords: patch

Created on 2009-09-13 08:50 by loewis, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
python.patch loewis, 2009-09-13 08:50 review
issue-6899.patch meador.inge, 2010-01-31 00:27 review
Messages (3)
msg92563 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-09-13 08:50
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
msg92566 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-09-13 13:19
Looks good, but it needs some tests.
msg98584 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2010-01-31 00:27
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)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/minge/Research/Languages/python/trunk/Lib/lib2to3/tests/test_pytree.py", line 161, in test_replace
    self.assertEqual(l2.parent, n1)
AssertionError: None != Node(1000, [Leaf(100, 'foo'), Leaf(100, '+'), Leaf(100, 'bar')])

======================================================================
FAIL: test_replace_with_list (lib2to3.tests.test_pytree.TestNodes)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/minge/Research/Languages/python/trunk/Lib/lib2to3/tests/test_pytree.py", line 179, in test_replace_with_list
    self.assertEqual(l1.parent, n1)
AssertionError: None != Node(1000, [Leaf(100, 'foo'), Leaf(100, '+'), Leaf(100, 'baz'), Leaf(100, '*'), Leaf(100, '*'), Leaf(100, 'bar')])

----------------------------------------------------------------------
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
History
Date User Action Args
2022-04-11 14:56:52adminsetgithub: 51148
2021-10-20 23:05:13iritkatrielsetstatus: open -> closed
superseder: Close 2to3 issues and list them here
resolution: wont fix
stage: patch review -> resolved
2020-11-10 18:37:46iritkatrielsetversions: + Python 3.8, Python 3.9, Python 3.10, - Python 2.7, Python 3.2, Python 3.3
2011-11-29 13:17:09eric.araujosetversions: + Python 2.7, Python 3.2, Python 3.3
2011-11-29 06:37:39ezio.melottisettype: behavior
stage: patch review
2010-01-31 00:27:31meador.ingesetfiles: + issue-6899.patch
nosy: + meador.inge
messages: + msg98584

2009-09-13 13:19:14benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg92566
2009-09-13 08:50:39loewiscreate