Cyberbrain icon indicating copy to clipboard operation
Cyberbrain copied to clipboard

More accurate function definition lineno

Open laike9m opened this issue 3 years ago • 2 comments

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

image

laike9m avatar May 12 '21 05:05 laike9m

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

victorjzsun avatar May 18 '21 18:05 victorjzsun

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

laike9m avatar May 18 '21 19:05 laike9m