This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author yselivanov
Recipients Claudiu.Popa, akaptur, ballingt, ncoghlan, pitrou, python-dev, terry.reedy, yselivanov
Date 2015-06-26.22:22:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1435357368.83.0.672370132709.issue21217@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-06-26 22:22:48yselivanovsetrecipients: + yselivanov, terry.reedy, ncoghlan, pitrou, Claudiu.Popa, python-dev, akaptur, ballingt
2015-06-26 22:22:48yselivanovsetmessageid: <1435357368.83.0.672370132709.issue21217@psf.upfronthosting.co.za>
2015-06-26 22:22:48yselivanovlinkissue21217 messages
2015-06-26 22:22:48yselivanovcreate