laike9m / Cyberbrain

Python debugging, redefined.
http://bit.ly/cyberbrain-features
MIT License
2.51k stars 159 forks source link

More accurate function definition lineno #124

Open laike9m opened 3 years ago

laike9m commented 3 years ago

Now frame.defined_lineno is the line of the first decorator. Ideally it should be the line where def is at.

image

victorjzsun commented 3 years ago

I'm not sure if this is possible without analyzing source code. Since there is nothing actually happening on the def line, it is omitted in the bytecode. You also cannot use a previous or next line in the bytecode and then just add/subtract a line since comments can exist between decorators, def line, and function body which are also omitted in the bytecode

laike9m commented 3 years ago

Comments between decorators should be very rare. For the normal cases, potentially we can imitate what the undecorated lib is doing and count the number of decorators, then add the number of lines:

https://github.com/iartarisi/undecorated/blob/master/undecorated.py