Closed rajasaur closed 3 years ago
There seems to be quite a few issues around inspect.py and the closest i found is : https://bugs.python.org/issue29354 but that doesnt seem to be the issue here. Im not too familiar with python internals, but if we arent going to use that whole logic, could we just use the same logic as that of Py3 ?
On py2 I use inspect because py2 has that argument tuple unpacking thing (which was removed on py3), and inspect handles that. Or, well, it tries - cause that's exactly where it's failing.
Anyway, I am not able to reproduce your issue on Python 2.7.18 - need details on specific package versions and run instructions I guess.
Thanks for checking. This is the sequence of steps:
curl http://localhost:5000
I had python 2.7.16 on OSX but upgraded to 2.7.18 just to be sure but had the same problem.
Alright, got it reproduced. Looks like I have to rework that function completely - it doesn't work well with unpacking regardless.
I implemented a fix for this, give it a try with some more complicated routing - not sure if it will work properly. For your reproducer it would output
Thread-1 <werkzeug routing>:1 call => <builder:'/'>(.self=<werkzeug.routing.Rule object at 0x7efc067468d0>, **.kwargs={})
Thread-1 <werkzeug routing>:1 line ??? NO SOURCE: Source code string for '<werkzeug routing>' is empty.
Thread-1 <werkzeug routing>:1 return <= <builder:'/'>: ('', '/')
I guess it's a fair compromise for werkzeug's ast/bytecode frankenstein.
Note that v3.3.1 with the fix was just released.
Python Hunter version: 3.2.2 Python Version : 2.7
When trying a simple Todo Flask app (The code is from https://github.com/mikicaivosevic/flask-simple-todo.git) and running hunter on it (Tried with both hunter-trace and setting env variables), it errors with a
Investigating it a bit, it comes from the werkezeug
code = compile(module, "<werkzeug routing>", "exec")
(https://github.com/pallets/werkzeug/blob/master/src/werkzeug/routing.py#L1069)Not sure if its because of the compile from code that its causing a problem in that the inspect.py is not able to get the stack.
Running the same on Python3 seems to be fine because it looks like inspect isnt used if its Python3 (https://github.com/ionelmc/python-hunter/blob/master/src/hunter/util.py#L101). It worked fine on Python 3 though.