From 3d8240b14fb24f92a33395a98e0d2879ea5fb193 Mon Sep 17 00:00:00 2001 From: gzchengxin2015 Date: Fri, 20 Aug 2021 15:38:45 +0800 Subject: [PATCH] fix fix_unicode may delete STRING's parentw --- Lib/lib2to3/fixes/fix_unicode.py | 2 +- Lib/lib2to3/pytree.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Lib/lib2to3/fixes/fix_unicode.py b/Lib/lib2to3/fixes/fix_unicode.py index c7982c2b97c3e1..425c3250bb7571 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 2a6ef2ef5240a2..08861af3f2a644 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."""