Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Eclips4 opened this issue Jun 8, 2024 · 0 comments
Closed
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@Eclips4
Copy link
Member

Eclips4 commented Jun 8, 2024

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

@Eclips4 Eclips4 added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Jun 8, 2024
@Eclips4 Eclips4 changed the title date.fromtimestamp(None) behaves differently between `_pydatetime and _datetime date.fromtimestamp(None) behaves differently between _pydatetime and _datetime Jun 8, 2024
pganssle pushed a commit that referenced this issue Jun 8, 2024
…amp`` (#120269)

This makes the pure Python implementation consistent with the C implementation.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 8, 2024
…timestamp`` (pythonGH-120269)

This makes the pure Python implementation consistent with the C implementation.
(cherry picked from commit 34f5ae6)

Co-authored-by: Kirill Podoprigora <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 8, 2024
…timestamp`` (pythonGH-120269)

This makes the pure Python implementation consistent with the C implementation.
(cherry picked from commit 34f5ae6)

Co-authored-by: Kirill Podoprigora <[email protected]>
serhiy-storchaka pushed a commit that referenced this issue Jun 11, 2024
…mtimestamp`` (GH-120269) (GH-120282)

This makes the pure Python implementation consistent with the C implementation.
(cherry picked from commit 34f5ae6)

Co-authored-by: Kirill Podoprigora <[email protected]>
serhiy-storchaka pushed a commit that referenced this issue Jun 11, 2024
…mtimestamp`` (GH-120269) (GH-120283)

This makes the pure Python implementation consistent with the C implementation.
(cherry picked from commit 34f5ae6)

Co-authored-by: Kirill Podoprigora <[email protected]>
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
…timestamp`` (python#120269)

This makes the pure Python implementation consistent with the C implementation.
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
…timestamp`` (python#120269)

This makes the pure Python implementation consistent with the C implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
Archived in project
Development

No branches or pull requests

2 participants