File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change 39
39
40
40
41
41
class AstRewriter (ast .NodeTransformer ):
42
+ gc_bookkeeping = True
43
+
42
44
def __init__ (
43
45
self ,
44
46
tracers : "List[BaseTracer]" ,
@@ -112,7 +114,7 @@ def visit(self, node: ast.AST):
112
114
new_bookkeeper = last_tracer .ast_bookkeeper_by_fname [
113
115
self ._path
114
116
] = AstBookkeeper .create (self ._path , module_id )
115
- if old_bookkeeper is not None :
117
+ if old_bookkeeper is not None and self . gc_bookkeeping :
116
118
last_tracer .remove_bookkeeping (old_bookkeeper , module_id )
117
119
BookkeepingVisitor (
118
120
new_bookkeeper .ast_node_by_id ,
Original file line number Diff line number Diff line change @@ -207,14 +207,17 @@ def __init__(self, is_reset: bool = False):
207
207
self ._post_init_hook_start ()
208
208
209
209
@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 :
211
213
clear_keys (cls .ast_node_by_id , bookkeeper .ast_node_by_id )
212
214
clear_keys (cls .containing_ast_by_id , bookkeeper .containing_ast_by_id )
213
215
clear_keys (cls .containing_stmt_by_id , bookkeeper .containing_stmt_by_id )
214
216
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
+ )
218
221
for spec , node_ids in cls .augmented_node_ids_by_spec .items ():
219
222
clear_keys (node_ids , bookkeeper .ast_node_by_id )
220
223
You can’t perform that action at this time.
0 commit comments