Skip to content

_pydatetime rejects ZoneInfo as tzinfo yet C datetime accepts #137754

@StanFromIreland

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

Metadata

Metadata

Assignees

Labels

stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions