Bug report
Bug description:
Consider the scenario where updatecache is called with a frozen module and module_globals is None.
In that case, _source_unavailable returns false because it is a frozen module, but because module_globals is None, the code carries on to look for the 'file' <frozen module> everywhere in sys.path. Compare that to the behavior prior to #132662 where that frozen module would simply return unavailable. I would recommend the following change:
if filename.startswith("<frozen ") and module_globals is not None:
# This is a frozen module, so we need to use the filename
# from the module globals.
fullname = module_globals.get("__file__")
if fullname is None:
print("fullname none")
return []
Into
if filename.startswith("<frozen "):
if module_globals is None:
return []
# This is a frozen module, so we need to use the filename
# from the module globals.
fullname = module_globals.get("__file__")
if fullname is None:
print("fullname none")
return []
For context, this is a problem for us because we run in a sandbox which restricts many OS operations, and this is performing useless os operations where it didn't prior to 3.14.
If there is agreement and it is helpful, happy to contribute a PR for this small change.
CPython versions tested on:
3.14
Operating systems tested on:
macOS, Windows, Linux
Linked PRs
Bug report
Bug description:
Consider the scenario where
updatecacheis called with a frozen module andmodule_globalsisNone.In that case,
_source_unavailablereturns false because it is a frozen module, but becausemodule_globalsisNone, the code carries on to look for the 'file'<frozen module>everywhere insys.path. Compare that to the behavior prior to #132662 where that frozen module would simply return unavailable. I would recommend the following change:Into
For context, this is a problem for us because we run in a sandbox which restricts many OS operations, and this is performing useless os operations where it didn't prior to
3.14.If there is agreement and it is helpful, happy to contribute a PR for this small change.
CPython versions tested on:
3.14
Operating systems tested on:
macOS, Windows, Linux
Linked PRs