Skip to content

fix(ws): drop deprecated datetime.utcfromtimestamp/utcnow in vendored well_known_types - #154

Open
Xuxchloris wants to merge 1 commit into
larksuite:v2_mainfrom
Xuxchloris:fix/timestamp-deprecation-warnings
Open

fix(ws): drop deprecated datetime.utcfromtimestamp/utcnow in vendored well_known_types#154
Xuxchloris wants to merge 1 commit into
larksuite:v2_mainfrom
Xuxchloris:fix/timestamp-deprecation-warnings

Conversation

@Xuxchloris

Copy link
Copy Markdown

Fixes #145.

Problem

The vendored lark_oapi/ws/pb/google/protobuf/internal/well_known_types.py still calls datetime.datetime.utcfromtimestamp(0) and datetime.datetime.utcnow(), both deprecated since Python 3.12 and scheduled for removal — every import of the ws protobuf runtime on Python 3.13/3.14 emits a DeprecationWarning.

Change

Mirrors the upstream google.protobuf fix:

  • _EPOCH_DATETIME_NAIVE = datetime.datetime(1970, 1, 1) — identical value, no deprecated call.
  • Timestamp.GetCurrentTime() uses datetime.datetime.now(tz=datetime.timezone.utc).

Tests

New lark_oapi/ws/tests/test_well_known_types_timestamp.py:

  • GetCurrentTime() under warnings.simplefilter("error", DeprecationWarning) and sanity-checked against time.time().
  • FromDatetime/ToDatetime roundtrips for naive and timezone-aware datetimes.

Verification

  • python -m pytest lark_oapi/ws/tests/test_well_known_types_timestamp.py — 3/3 pass.
  • python -m pytest (default suite) — 666 pass; the single failing test_upload_error_propagation case is the pre-existing Windows-only path-escape issue (CI runs Linux).

… well_known_types

Python 3.12+ emits DeprecationWarning for datetime.utcfromtimestamp() /
datetime.utcnow(); the vendored google.protobuf well_known_types.py still
used both. Mirrors the upstream protobuf fix:

- _EPOCH_DATETIME_NAIVE = datetime.datetime(1970, 1, 1) (identical value)
- GetCurrentTime uses datetime.datetime.now(tz=datetime.timezone.utc)

Fixes larksuite#145. Adds timestamp tests (GetCurrentTime under
DeprecationWarning-as-error, naive/aware FromDatetime/ToDatetime
roundtrips) under lark_oapi/ws/tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeprecationWarning on Python 3.12+: bundled well_known_types.py uses deprecated datetime.datetime.utcfromtimestamp

1 participant