4 ms·
What are your thoughts on purely static tools on that for Python? Basically my latest project that I was thinking about is to write a symbolic executor for pyt
by heavenlyblue 7y ago
What are your thoughts on purely static tools on that for Python?
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?
- BiteCode_dev 7y agoI'm not sure, but maybe you can have a look at the following projects to have an idea of prior art: - jedi: https://github.com/davidhalter/jedi https://github.com/davidhalter/jedi - nuitka: nuitka.net/ - python language server: https://github.com/palantir/python-language-server https://github.com/palantir/python-language-server - pyright: https://github.com/microsoft/pyright https://github.com/microsoft/pyright - pyre: https://pyre-check.org/ https://pyre-check.org/ - and of course mypy: http://mypy-lang.org/ 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/ https://pypi.org/project/baron/ Good luck.
- carapace 7y agoGreat list! There's also something called PySonar but you have to dig around for it.
- chrisseaton 7y ago> simply preserve all of the required-type information for all of the execution paths of the program 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!
- heavenlyblue 7y agoa) No they won’t come out as Any. Most of them won’t. b) You’re doing metaprogramming wrong if it goes against the assumptions of the initial language you started from.
- chrisseaton 7y agoWhat depth of context are you expecting to have to use to avoid megamorphisation? 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?
- heavenlyblue 7y ago>> How do you accomodate the fact that while your routine is running someone could be redefining all your methods on another thread? 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”.
- chrisseaton 7y ago> You accommodate that by not doing that because you’re not an idiot. There's no need to be abusive. > 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”. It's not like that, because your language semantic model doesn't include random bit flips, so you can ignore that as hardware failure. But your language semantic model does include redefining methods on a concurrent thread. So you need to handle that. Otherwise you aren't statically typing Python, you're statically typing a new language that looks a bit like Python, but really is something else.
- tln 7y agoI wrote something like this. It used the bytecode, simulating types on the stack. 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