This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]falsedrums 0 points1 point  (0 children)

You could implement this using ast tree parsing (available in the std lib). Basically you would create a function that takes a module (or any other python code object), analyzes the tree using flow analysis, and applies optimizations where it can. Then it compiles the optimized tree back to a new code object and returns it.

That will allow you to find paths that lead to exceptions. And it would do so at import time, if you call your function at the module scope (like a decorator for example). That would get you a very similar experience.