With exactly the semantics that I would expect. Now, I wanted to say that this would have been introduced when timezone support was added to the datetime module, but it wasn’t:
Python 3.11.0a1+ (heads/pep-671:2601ebc9cd, Dec 1 2021, 19:18:04) [GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.timezone.utc
datetime.timezone.utc
>>> datetime.datetime.fromisoformat("2024-01-01T02:32:21Z")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Invalid isoformat string: '2024-01-01T02:32:21Z'
So I’m not exactly sure when it was added, or whether it’s simply a matter of Python version or if you need something else. But the support is definitely there in the version I’m using (3.13, built a couple months ago).
Heh. I only have a very small number of release versions of Python - mostly, I just keep building from source, installing, and carrying on. So my “python3” command is forever updating, but every once in a while it changes its announced version number, and leaves one behind. I actually have a Python 3.11 from Debian, but it’s in /usr/bin/python3.11 and my personally-built one is in /usr/local/bin/python3.11 which takes precedence. Forgot that I have the Debian one though, or I would have tested it as well.
But the reason I didn’t go into too much detail was that I wasn’t sure whether it was a version matter or something else (like having pytz installed via pip).