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 andrei.avk
Recipients andrei.avk, aroberge, lukasz.langa
Date 2021-07-16.14:55:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>

Thanks for looking at this!

 - I agree OSError is not ideal, but I chose it because it's consistent with how inspect reports similar errors. For example, see all instances of OSError, except for first, in this function:

I think it's an implementation detail that class source is not available on interactive prompt, for example function source is available via `inspect.getsource()`.

If a user can do getsource(func) and getsource(cls) in a file, and getsource(func) on interactive prompt, it seems wrong to return a ValueError when the user is trying to getsource(cls) in interactive.

I'm open to change it to ValueError though because I think the err message here is more important to avoid user confusion.

 - good point about files, I didn't remember about them. However they will have the __file__ attribute set, so they will return that right above the check for '__main__' in my patch.

I tested it to make sure:
import inspect
class A: 0

./python.exe ~/temp/                                                 
class A: 0
Date User Action Args
2021-07-16 14:55:37andrei.avksetrecipients: + andrei.avk, aroberge, lukasz.langa
2021-07-16 14:55:37andrei.avksetmessageid: <>
2021-07-16 14:55:37andrei.avklinkissue44648 messages
2021-07-16 14:55:37andrei.avkcreate