Skip to content

Reject main when copying an existing zipapp archive #159354

Description

@esadomer

zipapp.create_archive() documents that main can only be specified for a directory source without __main__.py. Existing archive sources enter the copy path before this argument is checked, silently ignoring it and modifying the target. The same problem occurs when main is explicitly set to an empty string.

Reproducer, run with the interpreter built from the CPython checkout:

import io
import zipapp
import zipfile

source = io.BytesIO()
with zipfile.ZipFile(source, 'w') as archive:
    archive.writestr('__main__.py', '')
for main in ('pkg.mod:fn', ''):
    source.seek(0)
    target = io.BytesIO(b'original content')
    try:
        zipapp.create_archive(source, target, main=main)
    except zipapp.ZipAppError as exc:
        print(main, exc)
    else:
        print(main, 'accepted')

Expected: Raise ZipAppError for either explicitly supplied value before reading/copying the archive or changing the target. Omitting main or passing None should continue to allow copying.

Observed: Both calls succeed and copy the existing archive, ignoring main.

Environment: CPython main, Windows debug build.

Linked PRs

Activity

  1. added a commit that references this issue on Oct 13, 2026
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Oct 14, 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

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions