From 2ef1fd31a682f6d91c40958b7a95603fd9b71b92 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sat, 19 Nov 2022 15:59:31 -0500 Subject: [PATCH] setup: Add Python 3.11 final and 3.12 alpha to CI Adapts to the deprecation of multi-argument generator.throw(). --- .github/workflows/test.yml | 4 +++- pyproject.toml | 2 +- setup.py | 1 + tornado/gen.py | 24 ++++++++++++++---------- tornado/test/gen_test.py | 2 +- tornado/testing.py | 2 +- tox.ini | 7 ++++--- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 58ca611f..935c325e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,8 +44,10 @@ jobs: tox_env: py39-full - python: '3.10' tox_env: py310-full - - python: '3.11.0-alpha - 3.11' + - python: '3.11' tox_env: py311-full + - python: '3.12.0-alpha - 3.12' + tox_env: py312-full - 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/pyproject.toml b/pyproject.toml index b2095ed6..4c5d9b02 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" [tool.cibuildwheel] -build = "cp3[789]* cp310*" +build = "cp3[789]* cp310* cp311*" test-command = "python -m tornado.test" [tool.cibuildwheel.macos] diff --git a/setup.py b/setup.py index 3a157b54..6ebc0f6b 100644 --- a/setup.py +++ b/setup.py @@ -116,6 +116,7 @@ setuptools.setup( "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ], diff --git a/tornado/gen.py b/tornado/gen.py index f3e6e72f..4819b857 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -763,21 +763,25 @@ class Runner(object): return self.future = None try: - exc_info = None - try: value = future.result() - except Exception: - exc_info = sys.exc_info() - future = None + except Exception as e: + # Save the exception for later. It's important that + # gen.throw() not be called inside this try/except block + # because that makes sys.exc_info behave unexpectedly. + exc: Optional[Exception] = e + else: + exc = None + finally: + future = None - if exc_info is not None: + if exc is not None: try: - yielded = self.gen.throw(*exc_info) # type: ignore + yielded = self.gen.throw(exc) finally: - # Break up a reference to itself - # for faster GC on CPython. - exc_info = None + # Break up a circular reference for faster GC on + # CPython. + del exc else: yielded = self.gen.send(value) diff --git a/tornado/test/gen_test.py b/tornado/test/gen_test.py index 2b025386..c17bf65f 100644 --- a/tornado/test/gen_test.py +++ b/tornado/test/gen_test.py @@ -1119,7 +1119,7 @@ class ContextVarsTest(AsyncTestCase): x = 10 async def native_async_function(): - self.assertEquals(ctx_var.get(), x) + self.assertEqual(ctx_var.get(), x) ctx_var.set(x) yield native_async_function() diff --git a/tornado/testing.py b/tornado/testing.py index 688464f0..fcad60c1 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -672,7 +672,7 @@ def gen_test( # noqa: F811 if self._test_generator is not None and getattr( self._test_generator, "cr_running", True ): - self._test_generator.throw(type(e), e) + self._test_generator.throw(e) # In case the test contains an overly broad except # clause, we may get back here. # Coroutine was stopped or didn't raise a useful stack trace, diff --git a/tox.ini b/tox.ini index 6a7d4ce8..6ea03e46 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,7 @@ [tox] envlist = # Basic configurations: Run the tests for each python version. - py37-full,py38-full,py39-full,py310-full,pypy3-full + py37-full,py38-full,py39-full,py310-full,py311-full,pypy3-full # Build and test the docs with sphinx. docs @@ -32,6 +32,7 @@ basepython = py39: python3.9 py310: python3.10 py311: python3.11 + py312: python3.12 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 @@ -50,7 +51,7 @@ deps = setenv = # Treat the extension as mandatory in testing (but not on pypy) - {py3,py37,py38,py39,py310}: TORNADO_EXTENSION=1 + {py3,py37,py38,py39,py310,py311}: TORNADO_EXTENSION=1 # CI workers are often overloaded and can cause our tests to exceed # the default timeout of 5s. ASYNC_TEST_TIMEOUT=25 @@ -62,7 +63,7 @@ setenv = # during sdist installation (and it doesn't seem to be # possible to set environment variables during that phase of # tox). - {py3,py37,py38,py39,py310,pypy3}: PYTHONWARNINGS=error:::tornado + {py3,py37,py38,py39,py310,py311,pypy3}: PYTHONWARNINGS=error:::tornado # All non-comment lines but the last must end in a backslash.