diff options
author | Philipp A <flying-sheep@web.de> | 2019-06-08 14:05:46 +0200 |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-06-08 05:05:46 -0700 |
commit | d407d2a7265f6102e51a1d62b3fd28b4f7a78d16 (patch) | |
tree | 6e52402cf0cdff805922a75e13822d54a0acb3f0 /Lib/inspect.py | |
parent | 65e5860fcc8ffe66f3c325d5484112f3b6540e8c (diff) | |
download | cpython-git-d407d2a7265f6102e51a1d62b3fd28b4f7a78d16.tar.gz |
bpo-37173: Show passed class in inspect.getfile error (GH-13861)
Currently, inspect.getfile(str) will report nonsense:
```pytb
>>> inspect.getfile(str)
TypeError: <module 'builtins' (built-in)> is a built-in class
```
This fixes that
https://bugs.python.org/issue37173
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 91d209dc64..99a580bd2f 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -659,9 +659,9 @@ def getfile(object): raise TypeError('{!r} is a built-in module'.format(object)) if isclass(object): if hasattr(object, '__module__'): - object = sys.modules.get(object.__module__) - if getattr(object, '__file__', None): - return object.__file__ + module = sys.modules.get(object.__module__) + if getattr(module, '__file__', None): + return module.__file__ raise TypeError('{!r} is a built-in class'.format(object)) if ismethod(object): object = object.__func__ |