DeprecationWarning on Python 3.12+: bundled well_known_types.py uses deprecated datetime.datetime.utcfromtimestamp
まだ誰も着手していません。
評価
調査の方向性
lark_oapi/ws/pb/google/protobuf/internal/well_known_types.py:91 から始め、naive なエポック値とその直下にある timezone-aware 値を比較します。非推奨の呼び出しを削除しつつ、naive な UTC のセマンティクスを維持してください。python -W error::DeprecationWarning -c "import lark_oapi.ws.pb.google.protobuf.internal.well_known_types" を実行します。警告なしでインポートが成功すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
lark_oapi bundles a vendored copy of protobuf's well_known_types.py under lark_oapi/ws/pb/google/protobuf/internal/. That vendored file still calls datetime.datetime.utcfromtimestamp(0), which is deprecated in Python 3.12+ and emits a DeprecationWarning on Python 3.13/3.14:
.../lark_oapi/ws/pb/google/protobuf/internal/well_known_types.py:91: DeprecationWarning:
datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version.
Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
_EPOCH_DATETIME_NAIVE = datetime.datetime.utcfromtimestamp(0)
Upstream google.protobuf already replaced this call (it now uses datetime.fromtimestamp(0, datetime.timezone.utc)), but the copy pinned inside lark_oapi has not been regenerated, so users on Python 3.12+ still hit the warning whenever the WebSocket (lark_oapi.ws) protobuf code is imported.
Reproduction
Environment:
- Python: 3.14.6
- lark-oapi: 1.7.1 (installed from PyPI; also reproducible against
v2_mainat the path below) - OS: macOS
Steps:
python -W error::DeprecationWarning -c "import lark_oapi.ws.pb.google.protobuf.internal.well_known_types"
Expected: import succeeds with no warning.
Actual:
.../lark_oapi/ws/pb/google/protobuf/internal/well_known_types.py:91: DeprecationWarning:
datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version.
Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
Location
lark_oapi/ws/pb/google/protobuf/internal/well_known_types.py:91 (still present on v2_main):
_EPOCH_DATETIME_NAIVE = datetime.datetime.utcfromtimestamp(0)
_EPOCH_DATETIME_AWARE = datetime.datetime.fromtimestamp(
0, tz=datetime.timezone.utc)
The _AWARE variant right below already uses the timezone-aware form; only the _NAIVE line needs to change.
Suggested fix
utcfromtimestamp cannot be made timezone-aware directly; replace it with the equivalent naive UTC datetime constructed from the already-correct aware value, e.g.:
_EPOCH_DATETIME_NAIVE = datetime.datetime.fromtimestamp(
0, tz=datetime.timezone.utc).replace(tzinfo=None)
This preserves the original "naive UTC" semantics that callers of _EPOCH_DATETIME_NAIVE rely on (used at line 251: return _EPOCH_DATETIME_NAIVE + delta) while removing the deprecated API call.
Alternatively, regenerate the vendored protobuf stubs from a current googleapis/python-protobuf release so the whole bundled copy tracks upstream fixes.
Impact
- Functional impact: none (warning only; behavior is unchanged).
- DX impact: noisy logs, fails test runs that elevate
DeprecationWarningto errors, and will turn into a hardAttributeErroronce Python removes the API (currently scheduled for a future 3.x release).
Workaround
Users can suppress the warning locally, e.g.:
import warnings
warnings.filterwarnings(
"ignore",
message="datetime.datetime.utcfromtimestamp.*",
category=DeprecationWarning,
)
—but the bundled protobuf code should be updated at the source.
- 主要言語
- Python
- スター
- 559
- フォーク
- 102
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
larksuite/oapi-sdk-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
larksuite/oapi-sdk-python#163 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
larksuite/oapi-sdk-python#162 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 94/100
larksuite/oapi-sdk-python#161 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
larksuite/oapi-sdk-python#160 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
larksuite/oapi-sdk-python#159 ·
larksuite/oapi-sdk-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100