Skip to content

Datetime fromisoformat does not parse expected string #128686

@ryan-intrepid

Description

@ryan-intrepid

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10only security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions