skip assignment in dfs() to avoid PatternLockedError on unmodified patterns

This commit is contained in:
Jan Petykiewicz 2020-10-10 19:12:17 -07:00
parent 5bc82b9d49
commit 7ed3b26b02

View File

@ -291,11 +291,14 @@ class Pattern(LockableImpl, AnnotatableImpl, metaclass=AutoSlots):
sp_transform = False
if subpattern.pattern is not None:
subpattern.pattern = subpattern.pattern.dfs(visit_before=visit_before,
visit_after=visit_after,
transform=sp_transform,
memo=memo,
hierarchy=hierarchy + (self,))
result = subpattern.pattern.dfs(visit_before=visit_before,
visit_after=visit_after,
transform=sp_transform,
memo=memo,
hierarchy=hierarchy + (self,))
if result is not subpattern.pattern:
# skip assignment to avoid PatternLockedError unless modified
subpattern.pattern = result
if visit_after is not None:
pat = visit_after(pat, hierarchy=hierarchy, memo=memo, transform=transform) # type: ignore