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

Updates for Python 3.12 #3288

Merged
merged 3 commits into from Jun 22, 2023
Merged

Updates for Python 3.12 #3288

merged 3 commits into from Jun 22, 2023

Conversation

bdarnell
Copy link
Member

Now that the gzip bug (python/cpython#105808) is fixed in 3.12b3, we can bring that version back to CI. We also need to pick up a newer version of tox and make some changes to datetime handling to avoid deprecation warnings.

Fixes #3278
Closes #3277

Now that python/cpython#105808 is fixed in beta 3.
Python 3.12 deprecates the utcnow and utcfromtimestamp methods and
discourages the use of naive datetimes to represent UTC. This was
previously the main way that Tornado used datetimes (since it was
the only option available in Python 2 before the introduction
of datetime.timezone.utc in Python 3.2).

- httpclient_test: Test-only change to test that both kinds of datetimes
  are supported in If-Modified-Since (this just calls
  httputil.format_timestamp)
- httputil: No functional changes, but format_timestamp's
  support for both naive and aware datetimes is now tested.
- locale: format_timestamp now supports aware datetimes (in
  addition to the existing support for naive datetimes).
- web: Cookie expirations internally use aware datetimes.
  StaticFileHandler.get_modified_time now supports both and the
  standard implementation returns aware.

It feels fragile that "naive" and "aware" datetimes are not distinct
types but subject to data-dependent behavior. This change uses
"aware" datetimes throughout Tornado, but some operations (comparisons
and subtraction) fail with mixed datetime types and if I missed any
in this change may cause errors if naive datetimes were used (where
previously naive datetimes would have been required). But that's
apparently the API we have to work with.
@bdarnell bdarnell merged commit cb5db3b into tornadoweb:master Jun 22, 2023
11 checks passed
@bdarnell bdarnell deleted the enable-312 branch June 22, 2023 01:15
@opoplawski
Copy link

Thank you!

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.

Test failures with Python 3.12 b1 & b2
2 participants