mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-123339: Fix cases of inconsistency of __module__ and __firstlineno__ in classes (GH-123613)
* Setting the __module__ attribute for a class now removes the __firstlineno__ item from the type's dict. * The _collections_abc and _pydecimal modules now completely replace the collections.abc and decimal modules after importing them. This allows to get the source of classes and functions defined in these modules. * inspect.findsource() now checks whether the first line number for a class is out of bound.
This commit is contained in:
parent
dc12237ab0
commit
69a4063ca5
11 changed files with 110 additions and 12 deletions
|
@ -970,10 +970,12 @@ def findsource(object):
|
|||
|
||||
if isclass(object):
|
||||
try:
|
||||
firstlineno = vars(object)['__firstlineno__']
|
||||
lnum = vars(object)['__firstlineno__'] - 1
|
||||
except (TypeError, KeyError):
|
||||
raise OSError('source code not available')
|
||||
return lines, firstlineno - 1
|
||||
if lnum >= len(lines):
|
||||
raise OSError('lineno is out of bounds')
|
||||
return lines, lnum
|
||||
|
||||
if ismethod(object):
|
||||
object = object.__func__
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue