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

未关闭
#141,431 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib topic-importlib type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

_get_mtime_and_size_of_source 开始,追踪 zipapp 源代码的 mtime 如何通过 time.mktime 转换,以及它与 pyc 时间戳的差异。在 Linux 或 macOS 上复现 Python 3.11 或 3.13 中所描述的时区差异,然后验证在时区之间传输的 pyc 不会再被错误地标记为过期。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
backend
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。