Message245872
Here's an update on #24485 regression.
Looks like getsource() is now using code objects instead of tokenizer to determine blocks first/last lines.
The problem with this particular case is that "inner" function's code object is completely independent from "outer"'s.
So, for an outer() function below:
def outer():
def inner():
never_reached1
never_reached2
the code object contains the following opcodes:
71 0 LOAD_CONST 1 (<code object inner ...>)
3 LOAD_CONST 2 ('outer1.<locals>.inner')
6 MAKE_FUNCTION 0
9 STORE_FAST 0 (inner)
12 LOAD_CONST 0 (None)
15 RETURN_VALUE
The correct solution is to use co_lnotab along with co_firstlineno to iterate through opcodes recursively accounting for MAKE_FUNCTION's code objects.
*However*, I don't think we can solve this for classes, i.e.
def outer_with_class():
class Foo:
b = 1
a = 2
there is no way (as far as I know) to get information about the Foo class start/end lineno.
I think that the only way we can solve this is to revert the patch for this issue. |
|
Date |
User |
Action |
Args |
2015-06-26 22:22:48 | yselivanov | set | recipients:
+ yselivanov, terry.reedy, ncoghlan, pitrou, Claudiu.Popa, python-dev, akaptur, ballingt |
2015-06-26 22:22:48 | yselivanov | set | messageid: <1435357368.83.0.672370132709.issue21217@psf.upfronthosting.co.za> |
2015-06-26 22:22:48 | yselivanov | link | issue21217 messages |
2015-06-26 22:22:48 | yselivanov | create | |
|