Skip to content

gh-70647: Add detail to error message when parsing a bad day of month. #116184

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

Closed
wants to merge 1 commit into from

Conversation

gpshead
Copy link
Member

@gpshead gpshead commented Mar 1, 2024

The presence of the values in the error message gives a stronger hint as to what went wrong.

>>> datetime.strptime("2.29", "%m.%d")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    datetime.strptime("2.29", "%m.%d")
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File ".../Lib/_strptime.py", line 565, in _strptime_datetime
    return cls(*args)
           ~~~^^^^^^^
ValueError: day 29 is out of range for month 2 in year 1900

… month.

The presence of the values in the error message gives a stronger hint as
to what went wrong.

```
>>> datetime.strptime("2.29", "%m.%d")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    datetime.strptime("2.29", "%m.%d")
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File ".../Lib/_strptime.py", line 565, in _strptime_datetime
    return cls(*args)
           ~~~^^^^^^^
ValueError: day 29 is out of range for month 2 in year 1900
```
@pitrou
Copy link
Member

pitrou commented Mar 1, 2024

+1 on the principle, but ideally there would be a test for this.

@gpshead
Copy link
Member Author

gpshead commented Mar 21, 2025

closing in favor of #131335

@gpshead gpshead closed this Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants