GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Syntax warnings are duplicated in zipimport · Issue #141276 · python/cpython

Syntax warnings are duplicated in zipimport #141276

New issue
Copy link
New issue
Copy link
Closed
Closed
Syntax warnings are duplicated in zipimport#141276
Copy link
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-importlib

Description

@serhiy-storchaka
serhiy-storchaka
opened on Nov 9, 2025
Issue body actions

When importing a not precompiled module from a ZIP archive, syntax warnings are emitted twice.

Discovered during adding tests for #139652.

Linked PRs

  • gh-141276: Avoid compiling zipimport source in get_filename #153799
  • [3.15] gh-141276: Avoid compiling zipimport source in get_filename (GH-153799) #159729
  • [3.14] gh-141276: Avoid compiling zipimport source in get_filename (GH-153799) #161504

Activity

  1. serhiy-storchaka
    added
    topic-importlib
    3.13only security fixesonly security fixes
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    on Nov 9, 2025
  2. StanFromIreland
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Nov 9, 2025
  3. typenoob commented on Nov 11, 2025

    @typenoob
    typenoob
    on Nov 11, 2025
    More actions

    The warnings are emitted both in _frozen_importlib._find_spec and _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_spec acquired the filename by get_filename

    cpython/Lib/zipimport.py

    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?

    cpython/Lib/zipimport.py

    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?

  4. typenoob commented on Nov 26, 2025

    @typenoob
    typenoob
    on Nov 26, 2025
    More actions

    @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?

  5. itamaro commented on Nov 27, 2025

    @itamaro
    itamaro
    on Nov 27, 2025
    Contributor
    More actions

    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).

  6. harjothkhara
    added a commit that references this issue on Jul 16, 2026

    pythongh-141276: Update zipimport warning expectations

    05f92d2
  7. harjothkhara commented on Aug 23, 2026

    @harjothkhara
    harjothkhara
    on Aug 23, 2026
    Contributor
    More actions

    #153799 fixes this by not compiling the source in get_filename.

  8. harjothkhara
    added 2 commits that reference this issue on Oct 8, 2026

    pythongh-141276: Return before reading source in _get_module_code

    d202f7f

    pythongh-141276: Address round-2 review feedback on zipimport

    8082336
  9. itamaro
    added 2 commits that reference this issue on Oct 10, 2026

    Merge branch 'main' into codex/pythongh-141276-zipimport

    cb21019

    gh-141276: Avoid compiling zipimport source in get_filename (#153799)

    230917f
  10. orsenthil
    added a commit that references this issue on Oct 11, 2026

    pythongh-141276: Avoid compiling zipimport source in get_filename (py…

    46f0541
  11. itamaro
    added 3 commits that reference this issue on Oct 19, 2026

    [3.15] gh-141276: Avoid compiling zipimport source in get_filename (G…

    47e4ba6

    pythongh-141276: Follow-ups to the zipimporter.get_filename() change

    4d56783

    pythongh-141276: Only validate the pyc header in zipimporter.get_file…

    cc58252
  12. itamaro
    added a commit that references this issue on Nov 6, 2026

    [3.14] gh-141276: Avoid compiling zipimport source in get_filename (G…

    310c85a
  13. itamaro
    closed this as completedon Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-importlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.