mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-42133: update parts of the stdlib to fall back to __spec__.loader
when __loader__
is missing (#22929)
This commit is contained in:
parent
7c01f1540f
commit
825ac38332
6 changed files with 59 additions and 14 deletions
|
@ -707,10 +707,13 @@ def getsourcefile(object):
|
|||
if os.path.exists(filename):
|
||||
return filename
|
||||
# only return a non-existent filename if the module has a PEP 302 loader
|
||||
if getattr(getmodule(object, filename), '__loader__', None) is not None:
|
||||
module = getmodule(object, filename)
|
||||
if getattr(module, '__loader__', None) is not None:
|
||||
return filename
|
||||
elif getattr(getattr(module, "__spec__", None), "loader", None) is not None:
|
||||
return filename
|
||||
# or it is in the linecache
|
||||
if filename in linecache.cache:
|
||||
elif filename in linecache.cache:
|
||||
return filename
|
||||
|
||||
def getabsfile(object, _filename=None):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue