Skip to content

fix(ws): replace deprecated utcfromtimestamp in vendored well_known_types#147

Open
roson9527 wants to merge 1 commit into
larksuite:v2_mainfrom
roson9527:fix/ws-utcfromtimestamp-deprecation
Open

fix(ws): replace deprecated utcfromtimestamp in vendored well_known_types#147
roson9527 wants to merge 1 commit into
larksuite:v2_mainfrom
roson9527:fix/ws-utcfromtimestamp-deprecation

Conversation

@roson9527

Copy link
Copy Markdown

Summary

Fixes #145.

The bundled protobuf stub at lark_oapi/ws/pb/google/protobuf/internal/well_known_types.py still calls datetime.datetime.utcfromtimestamp(0), which is deprecated in Python 3.12+ and emits DeprecationWarning on Python 3.13/3.14. This breaks test runs that elevate DeprecationWarning to errors and will turn into a hard failure once Python removes the API.

Change

Align with current upstream protocolbuffers/protobuf (python/google/protobuf/internal/well_known_types.py) by constructing the epoch datetime directly instead of via the deprecated helper:

# before
_EPOCH_DATETIME_NAIVE = datetime.datetime.utcfromtimestamp(0)
_EPOCH_DATETIME_AWARE = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)

# after
_EPOCH_DATETIME_NAIVE = datetime.datetime(1970, 1, 1, tzinfo=None)
_EPOCH_DATETIME_AWARE = _EPOCH_DATETIME_NAIVE.replace(tzinfo=datetime.timezone.utc)

Semantics preserved: _EPOCH_DATETIME_NAIVE stays a naive UTC datetime, _EPOCH_DATETIME_AWARE stays timezone-aware UTC. Callers at lines 251/266 (_EPOCH_DATETIME_NAIVE + delta / _EPOCH_DATETIME_AWARE + delta) are unchanged.

Verification

  • Python 3.14.6: importing the module with warnings.simplefilter('error', DeprecationWarning) no longer raises.
  • Confirmed _EPOCH_DATETIME_NAIVE == datetime(1970, 1, 1) and _EPOCH_DATETIME_AWARE == datetime(1970, 1, 1, tzinfo=timezone.utc), matching pre-change values.
  • rg "utcfromtimestamp" lark_oapi/ returns no matches.

Scope

Single-file, 3-line change to vendored protobuf code. No API change, no dependency change.

@CLAassistant

CLAassistant commented Jul 27, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


roson seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

…ypes

The bundled protobuf well_known_types.py still constructed the epoch
datetime via datetime.datetime.utcfromtimestamp(0), which is deprecated
in Python 3.12+ and emits DeprecationWarning on 3.13/3.14. Align with
upstream protocolbuffers/protobuf, which constructs the naive epoch
datetime directly and derives the aware value from it.

Fixes larksuite#145
@roson9527
roson9527 force-pushed the fix/ws-utcfromtimestamp-deprecation branch from 50ae197 to 850887f Compare July 27, 2026 06:26
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

2 participants