python / python/cpython

`.pyc` file in zipapp can be marked as stale if opened in a different timezone than the one it was created in

Open
#141,431 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-importlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

_get_mtime_and_size_of_source uses localtime rather than UTC --- in a zipapp, if the pyc was created in a timezone that is different than the timezone of the computer that it is being run on, it can be marked as 'stale', even though it shouldn't be --- for example, if the source file was last modified at 3:30 EST, that 3:30 EST will be stored in the pyc file as a Unix timestamp. However, if the zipapp is then transferred to a computer running PST, the modification time of the source file will be read from the zip file as 3:30 PST in unix time (through time.mktime), which will obviously be different than the 3:30 EST read from the pyc file directly (since it is never passed through time.mktime).

This seems to be because zip files do not store timezones with mtime, so Python is forced to interpret it as local time.

CPython versions tested on:

3.11, 3.13

Operating systems tested on:

Linux, macOS

Linked PRs
  • gh-143868
  • gh-143953

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at _get_mtime_and_size_of_source and trace how zipapp source mtimes are converted with time.mktime versus pyc timestamps. Reproduce the timezone difference described for Python 3.11 or 3.13 on Linux or macOS, then verify that a pyc transferred between timezones is no longer incorrectly marked stale.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.