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 Steven.Barker
Recipients Claudiu.Popa, Naddiseo, Steven.Barker, eric.araujo, ned.deily, nikitakit, zorceta
Date 2016-05-18.06:45:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The problem being discussed here just came up on Stack Overflow today:

The cause of the incorrect error message is pretty clear. The relevant code from `inspect.getfile` should do something better when the object has a `__module__` attribute, but the module named (when looked up in `sys.modules`) does not have a `__file__` attribute. Currently it says the module is a builtin class, which is total nonsense.

A very basic fix would be to have an extra error case:

    if isclass(object):
        if hasattr(object, '__module__'):
            object = sys.modules.get(object.__module__)
            if hasattr(object, '__file__'):
                return object.__file__
            raise TypeError()              # need a relevant message here!!!
        raise TypeError('{!r} is a built-in class'.format(object))

It might be easier to make a meaningful message if the code after the first `if` didn't overwrite `object` with the module.

But, really, it would be nice to figure out a better fix, which would make the relevant inspect functions actually work for classes defined interactively in the `__main__` module.
Date User Action Args
2016-05-18 06:45:42Steven.Barkersetrecipients: + Steven.Barker, ned.deily, eric.araujo, Claudiu.Popa, Naddiseo, zorceta, nikitakit
2016-05-18 06:45:42Steven.Barkersetmessageid: <>
2016-05-18 06:45:42Steven.Barkerlinkissue12920 messages
2016-05-18 06:45:42Steven.Barkercreate