diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-09-02 11:07:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-02 11:07:08 (GMT) |
commit | 2b4c31d87d6fe9ec7cdc88eb6139ce9370666739 (patch) | |
tree | 8cb12a16715991260b3cd0aadac5828639980293 /Lib/inspect.py | |
parent | 8b6dd92db78cd2c0170e30d9e2fd2851b7f60b13 (diff) | |
download | cpython-2b4c31d87d6fe9ec7cdc88eb6139ce9370666739.zip cpython-2b4c31d87d6fe9ec7cdc88eb6139ce9370666739.tar.gz cpython-2b4c31d87d6fe9ec7cdc88eb6139ce9370666739.tar.bz2 |
[3.13] gh-122981: Fix inspect.getsource() for generated classes with Python base classes (GH-123001) (#123182)
gh-122981: Fix inspect.getsource() for generated classes with Python base classes (GH-123001)
Look up __firstlineno__ only in the class' dict, without searching in
base classes.
(cherry picked from commit f88c14d412522587085ae039ebe70b91d5b4e226)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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 845d55f..9499dc5 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1082,10 +1082,10 @@ def findsource(object): if isclass(object): try: - firstlineno = object.__firstlineno__ - except AttributeError: + firstlineno = vars(object)['__firstlineno__'] + except (TypeError, KeyError): raise OSError('source code not available') - return lines, object.__firstlineno__ - 1 + return lines, firstlineno - 1 if ismethod(object): object = object.__func__ |