Skip to content

Commit 038cba5

Browse files
Speed up flake8-async by telling libcst to skip deepcopy. (#438)
* Speed up flake8-async by telling libcst to skip deepcopy. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent eebb1b5 commit 038cba5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

flake8_async/runner.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,14 @@ def __init__(self, options: Options, module: Module):
138138

139139
def run(self) -> Iterable[Error]:
140140
for v in (*self.utility_visitors, *self.visitors):
141-
self.module = cst.MetadataWrapper(self.module).visit(v)
141+
# The default deepcopy guards against the same CST node object
142+
# appearing at two positions in the tree (metadata is keyed by node
143+
# identity). Parser output and the result of a prior .visit() never
144+
# share nodes, so the copy is wasted work. This stays safe as long
145+
# as no visitor returns a cached CST node from multiple leave_* calls.
146+
self.module = cst.MetadataWrapper(self.module, unsafe_skip_copy=True).visit(
147+
v
148+
)
142149

143150
yield from self.state.problems
144151

0 commit comments

Comments
 (0)