Repository navigation
Syntax warnings are duplicated in zipimport #141276
Description
Activity
- added3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes
on Nov 9, 2025 - addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Nov 9, 2025 The warnings are emitted both in
_frozen_importlib._find_specand_frozen_importlib._load_unlocked.I think warnings are not supposed to be emitted in
_frozen_importlib._find_spec.
cpython/Lib/importlib/_bootstrap_external.py
Lines 576 to 586 in 92741c5
if location is None: # The caller may simply want a partially populated location- # oriented spec. So we set the location to a bogus value and # fill in as much as we can. location = '<unknown>' if hasattr(loader, 'get_filename'): # ExecutionLoader try: location = loader.get_filename(name) except ImportError: pass
_frozen_importlib._find_specacquired the filename byget_filename
Lines 158 to 167 in 92741c5
def get_filename(self, fullname): """get_filename(fullname) -> filename string. Return the filename for the specified module or raise ZipImportError if it couldn't be imported. """ # Deciding the filename requires working out where the code # would come from if the module was actually loaded code, ispackage, modpath = _get_module_code(self, fullname) return modpath
however it triggered the compile action which may be not intended?
Lines 809 to 824 in 92741c5
modpath = toc_entry[0] data = _get_data(self.archive, toc_entry) code = None if isbytecode: try: code = _unmarshal_code(self, modpath, fullpath, fullname, data) except ImportError as exc: import_error = exc else: code = _compile_source(modpath, data) if code is None: # bad magic number or non-matching mtime # in byte code, try next continue modpath = toc_entry[0] return code, ispackage, modpath If all we want is just the filename, there's no need to compile the code right?
@serhiy-storchaka Sorry to bother you. I has found the root cause, but don't know whether to fix it or the best approach to fix it. Could you take a look at it?
I happened to stumble across this when noticing that modules loaded from pyc's with zipimport go through lookup and unmarshalling twice (once though get_filename and once through get_code).
There's a comment in get_filename about needing to get the code for the filename, so this seems intentional, but I'm not sure whether it is intentional to do the entire dance twice instead of some caching.
@serhiy-storchaka let me know if this should be a separate issue (or isn't an issue at all).- added a commit that references this issue
on Jul 16, 2026 #153799 fixes this by not compiling the source in
get_filename.
When importing a not precompiled module from a ZIP archive, syntax warnings are emitted twice.
Discovered during adding tests for #139652.
Linked PRs