Skip to content

date.fromtimestamp(None) behaves differently between _pydatetime and _datetime #120268

Closed
@Eclips4

Description

@Eclips4

Bug report

Bug description:

./python
Python 3.14.0a0 (heads/main-dirty:55402d3232, Jun  8 2024, 11:03:56) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import _datetime
>>> _datetime.date.fromtimestamp(None)
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    _datetime.date.fromtimestamp(None)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
TypeError: 'NoneType' object cannot be interpreted as an integer
>>> import _pydatetime
>>> _pydatetime.date.fromtimestamp(None)
datetime.date(2024, 6, 8)
>>> 

This happens because the _pydatetime.date.fromtimestamp is using time.localtime which is accepts None as a valid argument while _datetime.date.fromtimestamp is trying to convert None to an integer.
I would prefer to change the Python implementation, as the documentaion for datetime.date.fromtimestamp doesn't mention that it can accept None as a valid argument.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions