Skip to content

Base.replace breaks tree #51148

Closed
Closed

Description

@loewis
mannequin
BPO 6899
Nosy @loewis, @benjaminp, @meadori
Superseder
  • bpo-45544: Close 2to3 issues and list them here
  • Files
  • python.patch
  • issue-6899.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-10-20.23:05:13.996>
    created_at = <Date 2009-09-13.08:50:39.464>
    labels = ['3.8', 'type-bug', 'expert-2to3', '3.9', '3.10']
    title = 'Base.replace breaks tree'
    updated_at = <Date 2021-10-20.23:05:13.996>
    user = 'https://github.com/loewis'

    bugs.python.org fields:

    activity = <Date 2021-10-20.23:05:13.996>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-20.23:05:13.996>
    closer = 'iritkatriel'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2009-09-13.08:50:39.464>
    creator = 'loewis'
    dependencies = []
    files = ['14883', '16061']
    hgrepos = []
    issue_num = 6899
    keywords = ['patch']
    message_count = 3.0
    messages = ['92563', '92566', '98584']
    nosy_count = 3.0
    nosy_names = ['loewis', 'benjamin.peterson', 'meador.inge']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = '45544'
    type = 'behavior'
    url = 'https://bugs.python.org/issue6899'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    Activity

    1. loewis commented on Sep 13, 2009

      loewismannequin
      MannequinAuthor

      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

    2. benjaminp commented on Sep 13, 2009

      @benjaminp
      Contributor

      Looks good, but it needs some tests.

    3. meadori commented on Jan 31, 2010

      @meadori
      Member

      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

    4. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions