Skip to content

_pydatetime rejects ZoneInfo as tzinfo yet C datetime accepts #137754

Description

@StanFromIreland

Bug report

Bug description:

When using _datetimemodule.c implementation:

>>> from datetime import datetime
... from zoneinfo import ZoneInfo
... datetime(2025, 10, 26, 2, 0, tzinfo=ZoneInfo("Europe/Paris"))
... 
datetime.datetime(2025, 10, 26, 2, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Paris'))

However, with _pydatetime.py implementation:

>>> from _pydatetime import datetime
... from zoneinfo import ZoneInfo
... datetime(2025, 10, 26, 2, 0, tzinfo=ZoneInfo("Europe/Paris"))
... 
Traceback (most recent call last):
  File "<python-input-8>", line 3, in <module>
    datetime(2025, 10, 26, 2, 0, tzinfo=ZoneInfo("Europe/Paris"))
    ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.15/_pydatetime.py", line 1807, in __new__
    _check_tzinfo_arg(tzinfo)
    ~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/usr/local/lib/python3.15/_pydatetime.py", line 610, in _check_tzinfo_arg
    raise TypeError(
    ...<2 lines>...
    )
TypeError: tzinfo argument must be None or of a tzinfo subclass, not 'ZoneInfo'

CPython versions tested on:

CPython main branch, 3.14, 3.13

Operating systems tested on:

No response

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions