bpo-45406: make inspect.getmodule() return None when getabsfile() raises FileNotFoundError (GH-28824)
(cherry picked from commit a459a81530de700b3d3faeb827b22ed1c9985812)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 531b891..6d43d8d 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -859,7 +859,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])