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 xtreak
Recipients Windson Yang, pablogsal, xtreak, yselivanov
Date 2018-11-03.05:59:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1541224752.49.0.788709270274.issue35113@psf.upfronthosting.co.za>
In-reply-to
Content
I tried ast module and it passes my test cases but I found another case since object.__name__ returns unqualified name thus matching against nested class names might conflict with the ones on the top level. Example is below where there is Spam at the module level and NestedA.Spam which is defined inside another class. getsource(NestedA.Spam) returns the source for Spam which is also unexpected. It seems ast module also doesn't call visit_ClassDef on nested class definitions thus my approach also couldn't detect NestedA.Spam and returns source for Spam. I wish class objects also had some kind of code attribute similar to functions so that line number is attached. I don't know the internals so I might be wrong here. I am adding Yury.

import inspect

class Egg:

    def func(self):
        pass

class NestedA:

    class Egg:
        pass


print(inspect.getsource(NestedA.Egg))
print(inspect.getsource(Egg))

# Output

class Egg:

    def func(self):
        pass

class Egg:

    def func(self):
        pass
History
Date User Action Args
2018-11-03 05:59:12xtreaksetrecipients: + xtreak, yselivanov, pablogsal, Windson Yang
2018-11-03 05:59:12xtreaksetmessageid: <1541224752.49.0.788709270274.issue35113@psf.upfronthosting.co.za>
2018-11-03 05:59:12xtreaklinkissue35113 messages
2018-11-03 05:59:11xtreakcreate