Skip to content

Commit 26cba3b

Browse files
committed
make gc ast bookkeeping optional
1 parent d882378 commit 26cba3b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

pyccolo/ast_rewriter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040

4141
class AstRewriter(ast.NodeTransformer):
42+
gc_bookkeeping = True
43+
4244
def __init__(
4345
self,
4446
tracers: "List[BaseTracer]",
@@ -112,7 +114,7 @@ def visit(self, node: ast.AST):
112114
new_bookkeeper = last_tracer.ast_bookkeeper_by_fname[
113115
self._path
114116
] = AstBookkeeper.create(self._path, module_id)
115-
if old_bookkeeper is not None:
117+
if old_bookkeeper is not None and self.gc_bookkeeping:
116118
last_tracer.remove_bookkeeping(old_bookkeeper, module_id)
117119
BookkeepingVisitor(
118120
new_bookkeeper.ast_node_by_id,

pyccolo/tracer.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,17 @@ def __init__(self, is_reset: bool = False):
207207
self._post_init_hook_start()
208208

209209
@classmethod
210-
def remove_bookkeeping(cls, bookkeeper: AstBookkeeper, module_id: int) -> None:
210+
def remove_bookkeeping(
211+
cls, bookkeeper: AstBookkeeper, module_id: Optional[int]
212+
) -> None:
211213
clear_keys(cls.ast_node_by_id, bookkeeper.ast_node_by_id)
212214
clear_keys(cls.containing_ast_by_id, bookkeeper.containing_ast_by_id)
213215
clear_keys(cls.containing_stmt_by_id, bookkeeper.containing_stmt_by_id)
214216
clear_keys(cls.parent_stmt_by_id, bookkeeper.parent_stmt_by_id)
215-
clear_keys(
216-
cls.stmt_by_lineno_by_module_id[module_id], bookkeeper.stmt_by_lineno
217-
)
217+
if module_id is not None:
218+
clear_keys(
219+
cls.stmt_by_lineno_by_module_id[module_id], bookkeeper.stmt_by_lineno
220+
)
218221
for spec, node_ids in cls.augmented_node_ids_by_spec.items():
219222
clear_keys(node_ids, bookkeeper.ast_node_by_id)
220223

0 commit comments

Comments
 (0)