mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
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.
This commit is contained in:
parent
bb1d30336e
commit
f88c14d412
4 changed files with 66 additions and 4 deletions
|
|
@ -970,10 +970,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__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue