This commit is contained in:
Waylon Walker 2022-03-31 20:20:07 -05:00
commit 38355d2442
No known key found for this signature in database
GPG key ID: 66E2BF2B4190EFE4
9083 changed files with 1225834 additions and 0 deletions

View file

@ -0,0 +1,21 @@
"""Generic node traverser visitor"""
from mypy.traverser import TraverserVisitor
from mypy.nodes import Block, MypyFile
class TreeFreer(TraverserVisitor):
def visit_block(self, block: Block) -> None:
super().visit_block(block)
block.body.clear()
def free_tree(tree: MypyFile) -> None:
"""Free all the ASTs associated with a module.
This needs to be done recursively, since symbol tables contain
references to definitions, so those won't be freed but we want their
contents to be.
"""
tree.accept(TreeFreer())
tree.defs.clear()