You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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...
importast# note that lru_cache(maxsize=None) works for python < 3.9 compatfromfunctoolsimportcache@cachedefkind(self: ast.AST) ->str: returnself.__class__.__name__.lower()
kind(ast.parse("1 + 1"))
Otherwise, maybe patch_ast() could be run inside things like temporary_visited_module()?
The text was updated successfully, but these errors were encountered:
Actually @machow I tried your suggestion to use functions rather than patching AST classes. It led me to a rabbit hole of refactors and optimizations, and really paid off I think: the code is faster, uses much less memory, is better typed, and the lib is easier to use. So thanks! I'll push soon (and you'll be able to see the amount of changes if you're interested hehe), and if you could try the main branch then, to make sure there's no regressions, that would be great 🙂 (I couldn't identify any myself, through the tests suite and fuzzing on 415 installed packages). I'll notify you here!
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_ast
mutates attributes etc.. ontoast
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...
Otherwise, maybe
patch_ast()
could be run inside things liketemporary_visited_module()
?The text was updated successfully, but these errors were encountered: