by heavenlyblue · 6y ago · 0 comments
Basically my latest project that I was thinking about is to write a symbolic executor for python that would simply preserve all of the required-type information for all of the execution paths of the program.
Also the other project is to write a tool that allows you to walk all of the possible executions of a given piece of code to find which functions are being called from it - incredibly useful for refactoring of the old code.
Does something like this exists already that you've used and found useful?
- jedi: https://github.com/davidhalter/jedi
- nuitka: nuitka.net/
- python language server: https://github.com/palantir/python-language-server
- pyright: https://github.com/microsoft/pyright
- pyre: https://pyre-check.org/
- and of course mypy: http://mypy-lang.org/
I don't think any of them qualify, but they may all have little pieces.
Also, if you need to analyze Python syntax, baron will help: https://pypi.org/project/baron/
Good luck.
A type-flow analysis? Due to Python language features such a meta-programming and runtime code execution, you may find that at the end of this all your reported types will come out as 'Any' and the tool will be useless!
b) You’re doing metaprogramming wrong if it goes against the assumptions of the initial language you started from.
The literature tells us more than a couple of levels is likely not tractable. That’s not going to enough is it?
I'm not an expert in Python, but I am in dynamic analysis of other similar languages. Python lets you redefine methods, doesn't it? How do you accomodate the fact that while your routine is running someone could be redefining all your methods on another thread?
Nobody's yet managed what you're suggesting being able to do. Maybe you've got some new idea that nobody's even thought of before?
You accommodate that by not doing that because you’re not an idiot.
It’s like asking “why do you need static analysis tools when at any point in time your RAM bit can flip and now you need to model that, too”.
Functions with annotations had to be called with compatible types, functions without annotations were symbolically executed for each call site. Constructors were special cased so that the object attributes were set up correctly. Types for a stack slot or local could diverge and be narrowed depending on the path through the program.
The amount of metaprogramming used in practice in python made using it for real programs feel insurmountable. Also, I'm pretty sure performance would have been a problem beyond the toy programs I got it working on. But it was a fun exercise.
I'll have to dig up that code