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

Inaccurate error message for datetime.datetime.fromtimestamp #111513

Open
ericli-splunk opened this issue Oct 30, 2023 · 1 comment
Open

Inaccurate error message for datetime.datetime.fromtimestamp #111513

ericli-splunk opened this issue Oct 30, 2023 · 1 comment
Labels
type-feature A feature request or enhancement

Comments

@ericli-splunk
Copy link

ericli-splunk commented Oct 30, 2023

Bug report

Bug description:

datetime.datetime.fromtimestamp recognizes floating point arguments, but when I mistakenly enter a string as an argument, I get the error message "TypeError: 'str' object cannot be interpreted as an integer". This error message implies that fromtimestamp only accepts integers, which is confusing.

Expected behavior: see error message "TypeError: 'str' object cannot be interpreted as a float" or similar.

The same problem happens for datetime.datetime.utcfromtimestamp.

>>> import datetime
>>> datetime.datetime.fromtimestamp('1.234')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object cannot be interpreted as an integer
>>> datetime.datetime.fromtimestamp(1.234)
datetime.datetime(1969, 12, 31, 16, 0, 1, 234000)
>>> datetime.datetime.utcfromtimestamp('1.234')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object cannot be interpreted as an integer
>>> datetime.datetime.utcfromtimestamp(1.234)
datetime.datetime(1970, 1, 1, 0, 0, 1, 234000)
>>> datetime.datetime.fromtimestamp(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object cannot be interpreted as an integer
>>> 

CPython versions tested on:

3.11

Operating systems tested on:

macOS

Linked PRs

@ericli-splunk ericli-splunk added the type-bug An unexpected behavior, bug, or error label Oct 30, 2023
@Eclips4
Copy link
Member

Eclips4 commented Oct 30, 2023

I don't see any bug in this code. It appears to be a request to enhance the error message, so I'm removing the "type-bug" label and adding the "type-feature" label.

@Eclips4 Eclips4 added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
Development

No branches or pull requests

2 participants