Skip to content

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

Closed

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    3.12only security fixes
    3.13only security fixes
    3.14bugs and security fixes
    on Jun 8, 2024
  2. changed the title [-]``date.fromtimestamp(None)`` behaves differently between ``_pydatetime` and ``_datetime``[/-] [+]``date.fromtimestamp(None)`` behaves differently between ``_pydatetime`` and ``_datetime``[/+] on Jun 8, 2024
  3. added a commit that references this issue on Jun 8, 2024
  4. added 2 commits that reference this issue on Jun 8, 2024
  5. added 2 commits that reference this issue on Jun 11, 2024
  6. added a commit that references this issue on Jul 11, 2024
  7. added a commit that references this issue on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13only security fixes3.14bugs and security fixesstdlibStandard 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