Content-Length: 345043 | pFad | https://github.com/python/cpython/issues/137754

B0 `_pydatetime` rejects `ZoneInfo` as tzinfo yet C datetime accepts · Issue #137754 · python/cpython · GitHub
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

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

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/137754

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy