GH-65961: Stop setting __cached__ on modules

This commit is contained in:
Brett Cannon 2025-12-01 15:23:16 -08:00
parent e32c975640
commit 28f1334f1a
32 changed files with 93 additions and 240 deletions

View file

@ -111,7 +111,7 @@ def makepath(*paths):
def abs_paths():
"""Set all module __file__ and __cached__ attributes to an absolute path"""
"""Set __file__ to an absolute path."""
for m in set(sys.modules.values()):
loader_module = None
try:
@ -127,10 +127,6 @@ def abs_paths():
m.__file__ = os.path.abspath(m.__file__)
except (AttributeError, OSError, TypeError):
pass
try:
m.__cached__ = os.path.abspath(m.__cached__)
except (AttributeError, OSError, TypeError):
pass
def removeduppaths():
@ -699,7 +695,7 @@ def main():
known_paths = removeduppaths()
if orig_path != sys.path:
# removeduppaths() might make sys.path absolute.
# fix __file__ and __cached__ of already imported modules too.
# Fix __file__ of already imported modules too.
abs_paths()
known_paths = venv(known_paths)