From 09efc06e2f89f9acf1c8b4503ab62a6b520c9e0b Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Fri, 7 Jun 2024 16:20:54 -0400 Subject: [PATCH 1/3] Add python 3.13 betas to test configs Belatedly promote 3.12 to non-beta status --- .github/workflows/test.yml | 5 ++++- setup.py | 1 + tornado/test/process_test.py | 11 +++++++++++ tox.ini | 9 +++++---- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 93b87d5ef1..53d4b4c6f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,8 +51,11 @@ jobs: tox_env: py311-full - python: '3.11.0' tox_env: py311-full - - python: '3.12.0-beta.3 - 3.12' + - python: '3.12.0' tox_env: py312-full + - python: '3.13.0-beta.1 - 3.13' + # Some optional dependencies don't seem to work on 3.13 yet + tox_env: py313 - python: 'pypy-3.8' # Pypy is a lot slower due to jit warmup costs, so don't run the # "full" test config there. diff --git a/setup.py b/setup.py index 8025ad972b..d524bd3f84 100644 --- a/setup.py +++ b/setup.py @@ -116,6 +116,7 @@ def get_tag(self): "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ], diff --git a/tornado/test/process_test.py b/tornado/test/process_test.py index ab290085b3..1e5b391b63 100644 --- a/tornado/test/process_test.py +++ b/tornado/test/process_test.py @@ -150,11 +150,19 @@ def test_subprocess(self): raise unittest.SkipTest( "Subprocess tests not compatible with " "LayeredTwistedIOLoop" ) + # In Python 3.13.0b1, the new repl logs an error on exit if terminfo + # doesn't exist, the -i flag is used, and stdin is not a tty. This bug may + # have been fixed in beta 2, so for now we disable the new repl in this test + # and the next. Once we've tested with beta 2 we can either remove this env var + # or file a bug upstream if it still exists. + env = dict(os.environ) + env["PYTHON_BASIC_REPL"] = "1" subproc = Subprocess( [sys.executable, "-u", "-i"], stdin=Subprocess.STREAM, stdout=Subprocess.STREAM, stderr=subprocess.STDOUT, + env=env, ) self.addCleanup(lambda: self.term_and_wait(subproc)) self.addCleanup(subproc.stdout.close) @@ -172,11 +180,14 @@ def test_subprocess(self): @gen_test def test_close_stdin(self): # Close the parent's stdin handle and see that the child recognizes it. + env = dict(os.environ) + env["PYTHON_BASIC_REPL"] = "1" subproc = Subprocess( [sys.executable, "-u", "-i"], stdin=Subprocess.STREAM, stdout=Subprocess.STREAM, stderr=subprocess.STDOUT, + env=env, ) self.addCleanup(lambda: self.term_and_wait(subproc)) yield subproc.stdout.read_until(b">>> ") diff --git a/tox.ini b/tox.ini index 7eaa5bd838..78ab162b02 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,7 @@ [tox] envlist = # Basic configurations: Run the tests for each python version. - py38-full,py39-full,py310-full,py311-full,pypy3-full + py38-full,py39-full,py310-full,py311-full,py312-full,pypy3-full # Build and test the docs with sphinx. docs @@ -29,6 +29,7 @@ basepython = py310: python3.10 py311: python3.11 py312: python3.12 + py313: python3.13 pypy3: pypy3 # In theory, it doesn't matter which python version is used here. # In practice, things like changes to the ast module can alter @@ -48,7 +49,7 @@ deps = setenv = # Treat the extension as mandatory in testing (but not on pypy) - {py3,py38,py39,py310,py311,py312}: TORNADO_EXTENSION=1 + {py3,py38,py39,py310,py311,py312,py313}: TORNADO_EXTENSION=1 # CI workers are often overloaded and can cause our tests to exceed # the default timeout of 5s. ASYNC_TEST_TIMEOUT=25 @@ -60,7 +61,7 @@ setenv = # during sdist installation (and it doesn't seem to be # possible to set environment variables during that phase of # tox). - {py3,py38,py39,py310,py311,pypy3}: PYTHONWARNINGS=error:::tornado + {py3,py38,py39,py310,py311,py312,py313,pypy3}: PYTHONWARNINGS=error:::tornado # Warn if we try to open a file with an unspecified encoding. # (New in python 3.10, becomes obsolete when utf8 becomes the # default in 3.15) @@ -117,5 +118,5 @@ commands = # something new than of depending on something old and deprecated. # But sometimes something we depend on gets removed so we should also # test the newest version. - mypy --platform linux --python-version 3.12 {posargs:tornado} + mypy --platform linux --python-version 3.13 {posargs:tornado} changedir = {toxinidir} From 12243ab3fd96469253f8ad5917901ba23528fdef Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Fri, 7 Jun 2024 16:36:52 -0400 Subject: [PATCH 2/3] util: Remove pre-py35 is_finalizing compatibility This code appears to be unused and in any case is unnecessary since is_finalizing has been in the standard library since 3.5. --- tornado/test/util_test.py | 6 ------ tornado/util.py | 17 ----------------- 2 files changed, 23 deletions(-) diff --git a/tornado/test/util_test.py b/tornado/test/util_test.py index 02cf0c19bd..7a6e817fd2 100644 --- a/tornado/test/util_test.py +++ b/tornado/test/util_test.py @@ -14,7 +14,6 @@ timedelta_to_seconds, import_object, re_unescape, - is_finalizing, ) import typing @@ -301,8 +300,3 @@ def test_re_unescape_raises_error_on_invalid_input(self): re_unescape("\\b") with self.assertRaises(ValueError): re_unescape("\\Z") - - -class IsFinalizingTest(unittest.TestCase): - def test_basic(self): - self.assertFalse(is_finalizing()) diff --git a/tornado/util.py b/tornado/util.py index 3a3a52f1f2..1fc2c69a52 100644 --- a/tornado/util.py +++ b/tornado/util.py @@ -12,7 +12,6 @@ import array import asyncio -import atexit from inspect import getfullargspec import os import re @@ -47,22 +46,6 @@ unicode_type = str basestring_type = str -try: - from sys import is_finalizing -except ImportError: - # Emulate it - def _get_emulated_is_finalizing() -> Callable[[], bool]: - L = [] # type: List[None] - atexit.register(lambda: L.append(None)) - - def is_finalizing() -> bool: - # Not referencing any globals here - return L != [] - - return is_finalizing - - is_finalizing = _get_emulated_is_finalizing() - # versionchanged:: 6.2 # no longer our own TimeoutError, use standard asyncio class From 6d1f091d8b2a3ffba5786ad93cf8c73af4122924 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Fri, 7 Jun 2024 21:25:29 -0400 Subject: [PATCH 3/3] process_test: Remove reference to deleted LayeredTwistedIOLoop --- tornado/test/process_test.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tornado/test/process_test.py b/tornado/test/process_test.py index 1e5b391b63..1f55f4d935 100644 --- a/tornado/test/process_test.py +++ b/tornado/test/process_test.py @@ -9,7 +9,6 @@ from tornado.httpclient import HTTPClient, HTTPError from tornado.httpserver import HTTPServer -from tornado.ioloop import IOLoop from tornado.log import gen_log from tornado.process import fork_processes, task_id, Subprocess from tornado.simple_httpclient import SimpleAsyncHTTPClient @@ -141,15 +140,6 @@ def term_and_wait(self, subproc): @gen_test def test_subprocess(self): - if IOLoop.configured_class().__name__.endswith("LayeredTwistedIOLoop"): - # This test fails non-deterministically with LayeredTwistedIOLoop. - # (the read_until('\n') returns '\n' instead of 'hello\n') - # This probably indicates a problem with either TornadoReactor - # or TwistedIOLoop, but I haven't been able to track it down - # and for now this is just causing spurious travis-ci failures. - raise unittest.SkipTest( - "Subprocess tests not compatible with " "LayeredTwistedIOLoop" - ) # In Python 3.13.0b1, the new repl logs an error on exit if terminfo # doesn't exist, the -i flag is used, and stdin is not a tty. This bug may # have been fixed in beta 2, so for now we disable the new repl in this test