Describe the bug
It looks like outside of using the pytest plugin and creating a loader--which both run patch_ast--running temporary_visited_module() will fail with a message like below.
AttributeError: 'Module' object has no attribute 'kind'
It looks like patch_ast mutates attributes etc.. onto ast classes that the visitor needs.
I wonder if turning the AstNode methods into function might help avoid some of the trickiness of chasing down the patching / making sure it's applied before anything that needs it? E.g. something like...
import ast
# note that lru_cache(maxsize=None) works for python < 3.9 compat
from functools import cache
@cache
def kind(self: ast.AST) -> str: return self.__class__.__name__.lower()
kind(ast.parse("1 + 1"))
Otherwise, maybe patch_ast() could be run inside things like temporary_visited_module()?
Describe the bug
It looks like outside of using the pytest plugin and creating a loader--which both run
patch_ast--runningtemporary_visited_module()will fail with a message like below.It looks like
patch_astmutates attributes etc.. ontoastclasses that the visitor needs.I wonder if turning the AstNode methods into function might help avoid some of the trickiness of chasing down the patching / making sure it's applied before anything that needs it? E.g. something like...
Otherwise, maybe
patch_ast()could be run inside things liketemporary_visited_module()?