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

Datetime fromisoformat does not parse expected string #128686

Closed
ryan-intrepid opened this issue Jan 9, 2025 · 3 comments
Closed

Datetime fromisoformat does not parse expected string #128686

ryan-intrepid opened this issue Jan 9, 2025 · 3 comments
Labels
3.10 only security fixes type-bug An unexpected behavior, bug, or error

Comments

@ryan-intrepid
Copy link

ryan-intrepid commented Jan 9, 2025

Bug report

Bug description:

Datetime fromisoformat() not parsing string with trailing 'Z'

>>> import datetime
>>> datetime.datetime.fromisoformat('2011-11-04T00:05:23Z')
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ValueError: Invalid isoformat string: '2011-11-04T00:05:23Z'
>>> datetime.fromisoformat('2011-11-04T00:05:23')
datetime.datetime(2011, 11, 4, 0, 5, 23)

Environment information

user@Dell-XPS-15-9530:~$ python3
Python 3.10.14 (main, Apr  6 2024, 18:45:05) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

Documentation page example and expected result:

>>>datetime.fromisoformat('2011-11-04T00:05:23')
datetime.datetime(2011, 11, 4, 0, 5, 23)
>>>datetime.fromisoformat('2011-11-04T00:05:23Z')
datetime.datetime(2011, 11, 4, 0, 5, 23, tzinfo=datetime.timezone.utc)

Testing on 3.12.8 [GCC 11.4.0] worked as expected

CPython versions tested on:

3.10

Operating systems tested on:

Linux

@ryan-intrepid ryan-intrepid added the type-bug An unexpected behavior, bug, or error label Jan 9, 2025
@brettcannon brettcannon added the 3.10 only security fixes label Jan 9, 2025
@brettcannon
Copy link
Member

The docs you linked to are for the latest Python 3 release (currently 3.13). The 3.10 docs for datetime.datetime.fromisoformat() doesn't have that example because Z is not supported in that version.

@brettcannon brettcannon closed this as not planned Won't fix, can't repro, duplicate, stale Jan 9, 2025
@brettcannon
Copy link
Member

3.10 is also only receiving security updates at this point, so we wouldn't be able to fix it even if there was a bug unfortunately.

@ryan-intrepid
Copy link
Author

Welp, I feel a bit silly for the wrong docs.
I know there is no bug fixing, but would it be possible to update the documentation at datetime.isoformat() from
'Return a string representing the date and time in ISO 8601 format' to
'Return a string representing the date and time in an ISO 8601 compliant format' ?
I read that first line and assumed it could output anything ISO 8601 [definitely my bad], but a bit of clarity might help prevent similar reports in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants