Cyberbrain
Cyberbrain copied to clipboard
More accurate function definition lineno
Now frame.defined_lineno
is the line of the first decorator. Ideally it should be the line where def
is at.
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
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