bpo-45406: make inspect.getmodule() return None when getabsfile() raises FileNotFoundError (GH-28824)

This commit is contained in:
Irit Katriel 2021-11-02 21:55:51 +00:00 committed by GitHub
parent 48824fa1e2
commit a459a81530
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

View file

@ -858,7 +858,7 @@ def getmodule(object, _filename=None):
# Try the cache again with the absolute file name
try:
file = getabsfile(object, _filename)
except TypeError:
except (TypeError, FileNotFoundError):
return None
if file in modulesbyfile:
return sys.modules.get(modulesbyfile[file])