diff --git a/Lib/lib2to3/fixes/fix_unicode.py b/Lib/lib2to3/fixes/fix_unicode.py index c7982c2b97c3e1c..425c3250bb75716 100644 --- a/Lib/lib2to3/fixes/fix_unicode.py +++ b/Lib/lib2to3/fixes/fix_unicode.py @@ -36,7 +36,7 @@ def transform(self, node, results): if val[0] in 'uU': val = val[1:] if val == node.value: - return node + return None new = node.clone() new.value = val return new diff --git a/Lib/lib2to3/pytree.py b/Lib/lib2to3/pytree.py index 2a6ef2ef5240a2b..08861af3f2a6440 100644 --- a/Lib/lib2to3/pytree.py +++ b/Lib/lib2to3/pytree.py @@ -115,11 +115,12 @@ def replace(self, new): else: l_children.append(ch) assert found, (self.children, self, new) - self.parent.changed() - self.parent.children = l_children + parent = self.parent + self.parent = None + parent.children = l_children for x in new: - x.parent = self.parent - self.parent = None + x.parent = parent + parent.changed() def get_lineno(self): """Return the line number which generated the invocant node."""