diff --git a/.github/workflows/autodeps.yml b/.github/workflows/autodeps.yml index adc407dda5..fb73ad31a7 100644 --- a/.github/workflows/autodeps.yml +++ b/.github/workflows/autodeps.yml @@ -26,13 +26,13 @@ jobs: - name: Setup python uses: actions/setup-python@v6 with: - python-version: "3.10" + python-version: "3.11" - name: Bump dependencies run: | python -m pip install -U pip pre-commit python -m pip install -r test-requirements.txt - uv pip compile --universal --python-version=3.10 --upgrade test-requirements.in -o test-requirements.txt + uv pip compile --universal --python-version=3.11 --upgrade test-requirements.in -o test-requirements.txt uv pip compile --universal --python-version=3.11 --upgrade docs-requirements.in -o docs-requirements.txt pre-commit autoupdate --jobs 0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad39592c88..679fde7ae0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -168,18 +168,18 @@ jobs: strategy: fail-fast: false matrix: - python: ['3.10', '3.11', '3.12', '3.13', '3.14', '3.14t', '3.15', '3.15t'] + python: ['3.11', '3.12', '3.13', '3.14', '3.14t', '3.15', '3.15t'] arch: ['x86', 'x64'] lsp: [''] lsp_extract_file: [''] extra_name: [''] include: - - python: '3.10' + - python: '3.11' arch: 'x64' lsp: 'https://raw.githubusercontent.com/python-trio/trio-ci-assets/master/komodia-based-vpn-setup.zip' lsp_extract_file: 'komodia-based-vpn-setup.exe' extra_name: ', with Komodia LSP' - - python: '3.10' + - python: '3.11' arch: 'x64' lsp: 'https://www.proxifier.com/download/legacy/ProxifierSetup342.exe' lsp_extract_file: '' @@ -243,7 +243,7 @@ jobs: strategy: fail-fast: false matrix: - python: ['pypy-3.11', '3.10', '3.11', '3.12', '3.13', '3.14', '3.14t', '3.15', '3.15t'] + python: ['pypy-3.11', '3.11', '3.12', '3.13', '3.14', '3.14t', '3.15', '3.15t'] check_formatting: ['0'] no_test_requirements: ['0'] extra_name: [''] @@ -252,7 +252,7 @@ jobs: check_formatting: '1' extra_name: ', check formatting' # separate test run that doesn't install test-requirements.txt - - python: '3.10' + - python: '3.11' no_test_requirements: '1' extra_name: ', no test-requirements' continue-on-error: >- @@ -288,7 +288,7 @@ jobs: if: matrix.check_formatting == '1' uses: actions/setup-python@v6 with: - python-version: '3.10' + python-version: '3.11' cache: pip cache-dependency-path: test-requirements.txt allow-prereleases: true @@ -321,7 +321,7 @@ jobs: strategy: fail-fast: false matrix: - python: ['pypy-3.11', '3.10', '3.11', '3.12', '3.13', '3.14', '3.14t', '3.15', '3.15t'] + python: ['pypy-3.11', '3.11', '3.12', '3.13', '3.14', '3.14t', '3.15', '3.15t'] continue-on-error: >- ${{ ( @@ -412,12 +412,10 @@ jobs: include: # Cython 2 supports 3.10 and 3.11 and Cython 3 supports all versions we do, # so test both the lowest and higher version for both - - python: '3.10' - cython: '<3' - python: '3.11' cython: '<3' # TODO: technically we should pin cython versions - - python: '3.10' + - python: '3.11' cython: '>=3' - python: '3.15' cython: '>=3' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 63b2f1c292..8d097dea9a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -76,7 +76,7 @@ repos: name: uv pip-compile test-requirements.in args: [ "--universal", - "--python-version=3.10", + "--python-version=3.11", "test-requirements.in", "-o", "test-requirements.txt"] diff --git a/README.rst b/README.rst index e29f9035f7..041b7e91a7 100644 --- a/README.rst +++ b/README.rst @@ -92,7 +92,7 @@ demonstration of implementing the "Happy Eyeballs" algorithm in an older library versus Trio. **Cool, but will it work on my system?** Probably! As long as you have -some kind of Python 3.10-or-better (CPython or `currently maintained versions of +some kind of Python 3.11-or-better (CPython or `currently maintained versions of PyPy3 `__ are both fine), and are using Linux, macOS, Windows, or FreeBSD, then Trio will work. Other environments might work too, but those diff --git a/docs/source/conf.py b/docs/source/conf.py index eb278bf65f..10a651a494 100755 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -25,9 +25,7 @@ from pathlib import Path from typing import TYPE_CHECKING, cast -if sys.version_info >= (3, 11): - from sphinx.util.inventory import _InventoryItem - +from sphinx.util.inventory import _InventoryItem from sphinx.util.logging import getLogger if TYPE_CHECKING: @@ -274,20 +272,12 @@ def add_mapping( assert isinstance(inventory, dict) inventory = cast("Inventory", inventory) - if sys.version_info >= (3, 11): - inventory[f"py:{reftype}"][f"{target}"] = _InventoryItem( - project_name="Python", - project_version=version, - uri=f"https://docs.python.org/{url_version}/library/{library}.html/{obj}", - display_name="-", - ) - else: - inventory[f"py:{reftype}"][f"{target}"] = ( - "Python", - version, - f"https://docs.python.org/{url_version}/library/{library}.html/{obj}", - "-", - ) + inventory[f"py:{reftype}"][f"{target}"] = _InventoryItem( + project_name="Python", + project_version=version, + uri=f"https://docs.python.org/{url_version}/library/{library}.html/{obj}", + display_name="-", + ) # This has been removed in Py3.12, so add a link to the 3.11 version with deprecation warnings. add_mapping("method", "pathlib", "Path.link_to", "3.11") diff --git a/docs/source/index.rst b/docs/source/index.rst index 1744f91bdd..5f901ad268 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -45,7 +45,7 @@ Vital statistics: * Supported environments: We test on - - Python: 3.10+ (CPython and PyPy) + - Python: 3.11+ (CPython and PyPy) - Windows, macOS, Linux (glibc and musl), FreeBSD Other environments might also work; give it a try and see. diff --git a/docs/source/reference-core.rst b/docs/source/reference-core.rst index ee4468ce6d..8c4b07b5c6 100644 --- a/docs/source/reference-core.rst +++ b/docs/source/reference-core.rst @@ -773,45 +773,6 @@ If you want to reraise exceptions, or raise new ones, you can do so, but be awar exceptions raised in ``except*`` sections will be raised together in a new exception group. -But what if you can't use Python 3.11, and therefore ``except*``, just yet? -The same exceptiongroup_ library which backports `ExceptionGroup` also lets -you approximate this behavior with exception handler callbacks: - -.. code-block:: python - - from exceptiongroup import catch - - def handle_keyerrors(excgroup): - for exc in excgroup.exceptions: - ... # handle each KeyError - - def handle_indexerrors(excgroup): - for exc in excgroup.exceptions: - ... # handle each IndexError - - with catch({ - KeyError: handle_keyerrors, - IndexError: handle_indexerrors - }): - async with trio.open_nursery() as nursery: - nursery.start_soon(broken1) - nursery.start_soon(broken2) - -The semantics for the handler functions are equal to ``except*`` blocks, except for -setting local variables. If you need to set local variables, you need to declare them -inside the handler function(s) with the ``nonlocal`` keyword: - -.. code-block:: python - - def handle_keyerrors(excgroup): - nonlocal myflag - myflag = True - - myflag = False - with catch({KeyError: handle_keyerrors}): - async with trio.open_nursery() as nursery: - nursery.start_soon(broken1) - .. _handling_exception_groups: Designing for multiple errors diff --git a/newsfragments/3594.removal.rst b/newsfragments/3594.removal.rst new file mode 100644 index 0000000000..c943b718d8 --- /dev/null +++ b/newsfragments/3594.removal.rst @@ -0,0 +1 @@ +Drop support for Python 3.10. diff --git a/pyproject.toml b/pyproject.toml index 8ebfa12ee6..a7ca069fcd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,6 @@ classifiers = [ "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", @@ -35,7 +34,7 @@ classifiers = [ "Topic :: System :: Networking", "Typing :: Typed", ] -requires-python = ">=3.10" +requires-python = ">=3.11" dependencies = [ # attrs 19.2.0 adds `eq` option to decorators # attrs 20.1.0 adds @frozen @@ -50,7 +49,6 @@ dependencies = [ # cffi 1.14 fixes memory leak inside ffi.getwinerror() # cffi is required on Windows, except on PyPy where it is built-in "cffi>=1.14; os_name == 'nt' and implementation_name != 'pypy'", - "exceptiongroup; python_version < '3.11'", ] dynamic = ["version"] @@ -161,6 +159,7 @@ extend-ignore = [ # conflicts with formatter (ruff recommends these be disabled) "missing-trailing-comma", # COM812 + "non-pep646-unpack" # (UP044) ignoring it for now(See: https://github.com/python-trio/trio/pull/3594#issuecomment-6898086470) ] [tool.ruff.lint.per-file-ignores] @@ -195,7 +194,7 @@ combine-as-imports = true fixture-parentheses = false [tool.mypy] -python_version = "3.10" +python_version = "3.11" files = ["src/trio/", "docs/source/*.py"] # Be flexible about dependencies that don't have stubs yet (like pytest) @@ -222,7 +221,7 @@ disallow_untyped_defs = true check_untyped_defs = true [tool.pyright] -pythonVersion = "3.10" +pythonVersion = "3.11" reportUnnecessaryTypeIgnoreComment = true typeCheckingMode = "strict" diff --git a/src/trio/_abc.py b/src/trio/_abc.py index 2036f297f9..f737b1148c 100644 --- a/src/trio/_abc.py +++ b/src/trio/_abc.py @@ -2,15 +2,13 @@ import socket from abc import ABC, abstractmethod -from typing import TYPE_CHECKING, Generic, Literal, TypeVar +from typing import TYPE_CHECKING, Generic, Literal, Self, TypeVar import trio if TYPE_CHECKING: from types import TracebackType - from typing_extensions import Self - # both of these introduce circular imports if outside a TYPE_CHECKING guard from ._socket import SocketType from .lowlevel import Task diff --git a/src/trio/_channel.py b/src/trio/_channel.py index c785434e7a..3e609249da 100644 --- a/src/trio/_channel.py +++ b/src/trio/_channel.py @@ -6,10 +6,7 @@ from contextlib import AbstractAsyncContextManager, asynccontextmanager from functools import wraps from math import inf -from typing import ( - TYPE_CHECKING, - Generic, -) +from typing import TYPE_CHECKING, Generic, ParamSpec, Self import attrs from outcome import Error, Value @@ -25,14 +22,9 @@ raise_single_exception_from_group, ) -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup - if TYPE_CHECKING: from types import TracebackType - from typing_extensions import ParamSpec, Self - P = ParamSpec("P") elif "sphinx.ext.autodoc" in sys.modules: # P needs to exist for Sphinx to parse the type hints successfully. @@ -583,11 +575,10 @@ async def context_manager( except MultipleExceptionError: # In case user has except* we make it possible for them to handle the # exceptions. - if sys.version_info >= (3, 11): - eg.add_note( - "Encountered exception during cleanup of generator object, as " - "well as exception in the contextmanager body - unable to unwrap." - ) + eg.add_note( + "Encountered exception during cleanup of generator object, as " + "well as exception in the contextmanager body - unable to unwrap." + ) raise eg from None diff --git a/src/trio/_core/_asyncgens.py b/src/trio/_core/_asyncgens.py index fea41e0e4d..5cdca35f64 100644 --- a/src/trio/_core/_asyncgens.py +++ b/src/trio/_core/_asyncgens.py @@ -4,7 +4,7 @@ import sys import warnings import weakref -from typing import TYPE_CHECKING, NoReturn, TypeVar +from typing import TYPE_CHECKING, Never, TypeVar import attrs @@ -23,8 +23,8 @@ _P = ParamSpec("_P") - _WEAK_ASYNC_GEN_SET = weakref.WeakSet[AsyncGeneratorType[object, NoReturn]] - _ASYNC_GEN_SET = set[AsyncGeneratorType[object, NoReturn]] + _WEAK_ASYNC_GEN_SET = weakref.WeakSet[AsyncGeneratorType[object, Never]] + _ASYNC_GEN_SET = set[AsyncGeneratorType[object, Never]] else: _WEAK_ASYNC_GEN_SET = weakref.WeakSet _ASYNC_GEN_SET = set @@ -66,7 +66,7 @@ class AsyncGenerators: prev_hooks: sys._asyncgen_hooks = attrs.field(init=False) def install_hooks(self, runner: _run.Runner) -> None: - def firstiter(agen: AsyncGeneratorType[object, NoReturn]) -> None: + def firstiter(agen: AsyncGeneratorType[object, Never]) -> None: if hasattr(_run.GLOBAL_RUN_CONTEXT, "task"): self.alive.add(agen) else: @@ -81,7 +81,7 @@ def firstiter(agen: AsyncGeneratorType[object, NoReturn]) -> None: self.prev_hooks.firstiter(agen) def finalize_in_trio_context( - agen: AsyncGeneratorType[object, NoReturn], + agen: AsyncGeneratorType[object, Never], agen_name: str, ) -> None: try: @@ -99,7 +99,7 @@ def finalize_in_trio_context( self.trailing_needs_finalize.add(agen) @_core.enable_ki_protection - def finalizer(agen: AsyncGeneratorType[object, NoReturn]) -> None: + def finalizer(agen: AsyncGeneratorType[object, Never]) -> None: try: self.foreign.remove(id(agen)) except KeyError: @@ -222,7 +222,7 @@ def close(self) -> None: async def _finalize_one( self, - agen: AsyncGeneratorType[object, NoReturn], + agen: AsyncGeneratorType[object, Never], name: object, ) -> None: try: diff --git a/src/trio/_core/_entry_queue.py b/src/trio/_core/_entry_queue.py index 988b45ca00..9f5435c048 100644 --- a/src/trio/_core/_entry_queue.py +++ b/src/trio/_core/_entry_queue.py @@ -3,7 +3,7 @@ import threading from collections import deque from collections.abc import Callable -from typing import TYPE_CHECKING, NoReturn +from typing import TYPE_CHECKING, NoReturn, TypeVarTuple, Unpack import attrs @@ -12,7 +12,6 @@ from ._wakeup_socketpair import WakeupSocketpair if TYPE_CHECKING: - from typing_extensions import TypeVarTuple, Unpack PosArgsT = TypeVarTuple("PosArgsT") diff --git a/src/trio/_core/_exceptions.py b/src/trio/_core/_exceptions.py index f24e56b5e6..e0961b6893 100644 --- a/src/trio/_core/_exceptions.py +++ b/src/trio/_core/_exceptions.py @@ -1,7 +1,7 @@ from __future__ import annotations from functools import partial -from typing import TYPE_CHECKING, Literal, TypeAlias +from typing import TYPE_CHECKING, Literal, Self, TypeAlias import attrs @@ -10,7 +10,6 @@ if TYPE_CHECKING: from collections.abc import Callable - from typing_extensions import Self CancelReasonLiteral: TypeAlias = Literal[ "KeyboardInterrupt", diff --git a/src/trio/_core/_ki.py b/src/trio/_core/_ki.py index fa3369d56d..00895ed1ca 100644 --- a/src/trio/_core/_ki.py +++ b/src/trio/_core/_ki.py @@ -3,7 +3,7 @@ import signal import sys import weakref -from typing import TYPE_CHECKING, Generic, Protocol, TypeGuard, TypeVar +from typing import TYPE_CHECKING, Generic, Protocol, Self, TypeGuard, TypeVar import attrs @@ -14,7 +14,6 @@ import types from collections.abc import Callable - from typing_extensions import Self # In ordinary single-threaded Python code, when you hit control-C, it raises # an exception and automatically does all the regular unwinding stuff. # diff --git a/src/trio/_core/_run.py b/src/trio/_core/_run.py index 61f670cab6..18cfb193a6 100644 --- a/src/trio/_core/_run.py +++ b/src/trio/_core/_run.py @@ -20,6 +20,9 @@ Final, NoReturn, Protocol, + Self, + TypeVarTuple, + Unpack, cast, overload, ) @@ -57,10 +60,6 @@ wait_task_rescheduled, ) -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup - - if TYPE_CHECKING: import contextvars import types @@ -75,7 +74,7 @@ # for some strange reason Sphinx works with outcome.Outcome, but not Outcome, in # start_guest_run. Same with types.FrameType in iter_await_frames - from typing_extensions import Self, TypeVar, TypeVarTuple, Unpack + from typing_extensions import TypeVar PosArgT = TypeVarTuple("PosArgT") StatusT = TypeVar("StatusT", default=None) diff --git a/src/trio/_core/_tests/test_asyncgen.py b/src/trio/_core/_tests/test_asyncgen.py index a5c27ed5fb..8705707c44 100644 --- a/src/trio/_core/_tests/test_asyncgen.py +++ b/src/trio/_core/_tests/test_asyncgen.py @@ -5,7 +5,7 @@ import weakref from math import inf from types import AsyncGeneratorType -from typing import TYPE_CHECKING, NoReturn +from typing import TYPE_CHECKING, Never import pytest @@ -306,12 +306,12 @@ async def awaits_after_yield() -> AsyncGenerator[int, None]: def test_delegation_to_existing_hooks() -> None: record = [] - def my_firstiter(agen: AsyncGenerator[object, NoReturn]) -> None: + def my_firstiter(agen: AsyncGenerator[object, Never]) -> None: assert isinstance(agen, AsyncGeneratorType) assert agen.ag_frame is not None record.append("firstiter " + agen.ag_frame.f_locals["arg"]) - def my_finalizer(agen: AsyncGenerator[object, NoReturn]) -> None: + def my_finalizer(agen: AsyncGenerator[object, Never]) -> None: assert isinstance(agen, AsyncGeneratorType) assert agen.ag_frame is not None record.append("finalizer " + agen.ag_frame.f_locals["arg"]) diff --git a/src/trio/_core/_tests/test_exceptiongroup_gc.py b/src/trio/_core/_tests/test_exceptiongroup_gc.py index e8ffa62945..799040a614 100644 --- a/src/trio/_core/_tests/test_exceptiongroup_gc.py +++ b/src/trio/_core/_tests/test_exceptiongroup_gc.py @@ -13,9 +13,6 @@ from collections.abc import Callable from types import TracebackType -if sys.version_info < (3, 11): - from exceptiongroup import ExceptionGroup - def raiser1() -> NoReturn: raiser1_2() diff --git a/src/trio/_core/_tests/test_ki.py b/src/trio/_core/_tests/test_ki.py index 1ce4af9aaf..9b72cfb273 100644 --- a/src/trio/_core/_tests/test_ki.py +++ b/src/trio/_core/_tests/test_ki.py @@ -6,7 +6,7 @@ import sys import threading import weakref -from typing import TYPE_CHECKING, TypeVar +from typing import TYPE_CHECKING, Never, TypeVar import outcome import pytest @@ -34,8 +34,6 @@ ) from types import AsyncGeneratorType - from typing_extensions import Never - from ..._core import Abort, RaiseCancelT diff --git a/src/trio/_core/_tests/test_run.py b/src/trio/_core/_tests/test_run.py index e49e2e6ed2..d518ce913b 100644 --- a/src/trio/_core/_tests/test_run.py +++ b/src/trio/_core/_tests/test_run.py @@ -50,9 +50,6 @@ Generator, ) -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup, ExceptionGroup - T = TypeVar("T") @@ -2951,15 +2948,8 @@ async def spawn_tasks_in_old_nursery(task_status: _core.TaskStatus[None]) -> Non assert pytest.RaisesGroup(ValueError, ValueError).matches(excinfo.value.__cause__) -if sys.version_info >= (3, 11): - - def no_other_refs() -> list[object]: - return [] - -else: - - def no_other_refs() -> list[object]: - return [sys._getframe(1)] +def no_other_refs() -> list[object]: + return [] @pytest.mark.skipif( diff --git a/src/trio/_core/_tests/type_tests/run.py b/src/trio/_core/_tests/type_tests/run.py index 5c51b91496..46f62b70e8 100644 --- a/src/trio/_core/_tests/type_tests/run.py +++ b/src/trio/_core/_tests/type_tests/run.py @@ -1,9 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, overload +from typing import TYPE_CHECKING, assert_type, overload import trio -from typing_extensions import assert_type if TYPE_CHECKING: from collections.abc import Sequence diff --git a/src/trio/_core/_traps.py b/src/trio/_core/_traps.py index 14f66af927..dba074d81e 100644 --- a/src/trio/_core/_traps.py +++ b/src/trio/_core/_traps.py @@ -11,7 +11,7 @@ TYPE_CHECKING, Any, Callable, - NoReturn, + Never, TypeAlias, cast, ) @@ -26,7 +26,7 @@ from ._run import Task -RaiseCancelT: TypeAlias = Callable[[], NoReturn] +RaiseCancelT: TypeAlias = Callable[[], Never] # This class object is used as a singleton. diff --git a/src/trio/_core/_unbounded_queue.py b/src/trio/_core/_unbounded_queue.py index b9e7974841..75e8491208 100644 --- a/src/trio/_core/_unbounded_queue.py +++ b/src/trio/_core/_unbounded_queue.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Generic, TypeVar +from typing import Generic, Self, TypeVar import attrs @@ -10,9 +10,6 @@ T = TypeVar("T") -if TYPE_CHECKING: - from typing_extensions import Self - @attrs.frozen class UnboundedQueueStatistics: diff --git a/src/trio/_dtls.py b/src/trio/_dtls.py index ab27f9cec7..e63f735078 100644 --- a/src/trio/_dtls.py +++ b/src/trio/_dtls.py @@ -18,7 +18,15 @@ import weakref from itertools import count from math import isnan -from typing import TYPE_CHECKING, Generic, TypeAlias, TypeVar +from typing import ( + TYPE_CHECKING, + Generic, + Self, + TypeAlias, + TypeVar, + TypeVarTuple, + Unpack, +) from weakref import ReferenceType, WeakValueDictionary import attrs @@ -33,7 +41,6 @@ # See DTLSEndpoint.__init__ for why this is imported here from OpenSSL import SSL # noqa: TC004 - from typing_extensions import Self, TypeVarTuple, Unpack from trio._socket import AddressFormat from trio.socket import SocketType diff --git a/src/trio/_highlevel_open_tcp_listeners.py b/src/trio/_highlevel_open_tcp_listeners.py index 023b2b240f..2c7b6179d2 100644 --- a/src/trio/_highlevel_open_tcp_listeners.py +++ b/src/trio/_highlevel_open_tcp_listeners.py @@ -12,9 +12,6 @@ if TYPE_CHECKING: from collections.abc import Awaitable, Callable -if sys.version_info < (3, 11): - from exceptiongroup import ExceptionGroup - # Default backlog size: # diff --git a/src/trio/_highlevel_open_tcp_stream.py b/src/trio/_highlevel_open_tcp_stream.py index de4dc5acdd..e74fb24176 100644 --- a/src/trio/_highlevel_open_tcp_stream.py +++ b/src/trio/_highlevel_open_tcp_stream.py @@ -1,6 +1,5 @@ from __future__ import annotations -import sys from contextlib import contextmanager, suppress from math import isnan from typing import TYPE_CHECKING @@ -16,9 +15,6 @@ from trio._socket import AddressFormat, _GetAddrInfoEntry -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup, ExceptionGroup - # Implementation of RFC 6555 "Happy eyeballs" # https://tools.ietf.org/html/rfc6555 diff --git a/src/trio/_path.py b/src/trio/_path.py index ea571c9c01..60b9148806 100644 --- a/src/trio/_path.py +++ b/src/trio/_path.py @@ -13,6 +13,8 @@ ClassVar, Concatenate, Literal, + ParamSpec, + Self, TypeVar, overload, ) @@ -32,7 +34,6 @@ OpenBinaryModeWriting, OpenTextMode, ) - from typing_extensions import ParamSpec, Self P = ParamSpec("P") diff --git a/src/trio/_signals.py b/src/trio/_signals.py index 729c48ad4e..686a75ce46 100644 --- a/src/trio/_signals.py +++ b/src/trio/_signals.py @@ -3,7 +3,7 @@ import signal from collections import OrderedDict from contextlib import contextmanager -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Self import trio @@ -13,7 +13,6 @@ from collections.abc import AsyncIterator, Callable, Generator, Iterable from types import FrameType - from typing_extensions import Self # Discussion of signal handling strategies: # diff --git a/src/trio/_socket.py b/src/trio/_socket.py index 5202e295ad..11f615b9b2 100644 --- a/src/trio/_socket.py +++ b/src/trio/_socket.py @@ -11,6 +11,8 @@ Any, Concatenate, Literal, + ParamSpec, + Self, SupportsIndex, TypeAlias, TypeVar, @@ -28,7 +30,7 @@ from collections.abc import Awaitable, Callable, Iterable from types import TracebackType - from typing_extensions import Buffer, ParamSpec, Self + from typing_extensions import Buffer from ._abc import HostnameResolver, SocketFactory diff --git a/src/trio/_ssl.py b/src/trio/_ssl.py index 7579f3445e..c86ee816ed 100644 --- a/src/trio/_ssl.py +++ b/src/trio/_ssl.py @@ -4,7 +4,16 @@ import operator as _operator import ssl as _stdlib_ssl from enum import Enum as _Enum -from typing import TYPE_CHECKING, Any, ClassVar, Final as TFinal, Generic, TypeVar +from typing import ( + TYPE_CHECKING, + Any, + ClassVar, + Final as TFinal, + Generic, + TypeVar, + TypeVarTuple, + Unpack, +) import trio @@ -17,8 +26,6 @@ if TYPE_CHECKING: from collections.abc import Awaitable, Callable - from typing_extensions import TypeVarTuple, Unpack - Ts = TypeVarTuple("Ts") # General theory of operation: @@ -228,7 +235,7 @@ class _Once: def __init__( self, - afn: Callable[[*Ts], Awaitable[object]], + afn: Callable[[Unpack[Ts]], Awaitable[object]], *args: Unpack[Ts], ) -> None: self._afn = afn @@ -467,7 +474,7 @@ def _check_status(self) -> None: # too. async def _retry( self, - fn: Callable[[*Ts], T], + fn: Callable[[Unpack[Ts]], T], *args: Unpack[Ts], ignore_want_read: bool = False, is_handshake: bool = False, diff --git a/src/trio/_subprocess.py b/src/trio/_subprocess.py index b384d18ffa..a3295d0a2b 100644 --- a/src/trio/_subprocess.py +++ b/src/trio/_subprocess.py @@ -15,6 +15,7 @@ Protocol, TypeAlias, TypedDict, + Unpack, overload, ) @@ -34,8 +35,6 @@ import signal from collections.abc import Awaitable, Callable, Iterable, Mapping, Sequence - from typing_extensions import Unpack - from ._abc import ReceiveStream, SendStream @@ -1120,17 +1119,11 @@ class UnixRunProcessMixin(TypedDict, total=False): # TODO: once https://github.com/python/mypy/issues/18692 is # fixed, move the `UnixRunProcessArgs` definition down. - if sys.version_info >= (3, 11): - UnixProcessArgs = UnixProcessArgs3_11 - - class UnixRunProcessArgs(UnixProcessArgs3_11, UnixRunProcessMixin): - """Arguments for run_process on Unix with 3.11+""" - else: - UnixProcessArgs = UnixProcessArgs3_10 + UnixProcessArgs = UnixProcessArgs3_11 - class UnixRunProcessArgs(UnixProcessArgs3_10, UnixRunProcessMixin): - """Arguments for run_process on Unix with 3.10+""" + class UnixRunProcessArgs(UnixProcessArgs3_11, UnixRunProcessMixin): + """Arguments for run_process on Unix with 3.11+""" @overload # type: ignore[no-overload-impl] async def open_process( diff --git a/src/trio/_tests/test_channel.py b/src/trio/_tests/test_channel.py index 831f8eb483..4ed1471371 100644 --- a/src/trio/_tests/test_channel.py +++ b/src/trio/_tests/test_channel.py @@ -1,6 +1,5 @@ from __future__ import annotations -import sys from typing import TYPE_CHECKING import pytest @@ -10,9 +9,6 @@ from ..testing import assert_checkpoints, wait_all_tasks_blocked -if sys.version_info < (3, 11): - from exceptiongroup import ExceptionGroup - if TYPE_CHECKING: from collections.abc import AsyncGenerator @@ -534,7 +530,6 @@ async def agen(events: list[str]) -> AsyncGenerator[int]: assert i == 1 raise TypeError("iterator") - if sys.version_info >= (3, 11): assert g.value.__notes__ == [ "Encountered exception during cleanup of generator object, as " "well as exception in the contextmanager body - unable to unwrap." diff --git a/src/trio/_tests/test_exports.py b/src/trio/_tests/test_exports.py index d1c254a285..62b675e6fe 100644 --- a/src/trio/_tests/test_exports.py +++ b/src/trio/_tests/test_exports.py @@ -416,7 +416,7 @@ def lookup_symbol(symbol: str) -> dict[str, Any]: # type: ignore[misc, explicit # using .remove() instead of .delete() to get an error in case they start not # being missing - if BaseException in class_.__mro__ and sys.version_info >= (3, 11): + if BaseException in class_.__mro__: extra.remove("__notes__") if tool == "mypy" and attrs.has(class_): @@ -480,7 +480,7 @@ def lookup_symbol(symbol: str) -> dict[str, Any]: # type: ignore[misc, explicit # I have not researched why these are missing, should maybe create an issue # upstream with jedi - if tool == "jedi" and sys.version_info >= (3, 11): + if tool == "jedi": if class_ in ( trio.DTLSChannel, trio.MemoryReceiveChannel, diff --git a/src/trio/_tests/test_highlevel_open_tcp_listeners.py b/src/trio/_tests/test_highlevel_open_tcp_listeners.py index 5c5a50c6cd..5967d86c39 100644 --- a/src/trio/_tests/test_highlevel_open_tcp_listeners.py +++ b/src/trio/_tests/test_highlevel_open_tcp_listeners.py @@ -2,7 +2,6 @@ import errno import socket as stdlib_socket -import sys from socket import AddressFamily, SocketKind from typing import TYPE_CHECKING, Literal, cast, overload @@ -22,9 +21,6 @@ from .. import socket as tsocket from .._core._tests.tutil import binds_ipv6, slow -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup - if TYPE_CHECKING: from collections.abc import Sequence diff --git a/src/trio/_tests/test_highlevel_open_tcp_stream.py b/src/trio/_tests/test_highlevel_open_tcp_stream.py index a7da7016a4..29a34a615c 100644 --- a/src/trio/_tests/test_highlevel_open_tcp_stream.py +++ b/src/trio/_tests/test_highlevel_open_tcp_stream.py @@ -1,7 +1,6 @@ from __future__ import annotations import socket -import sys from socket import AddressFamily, SocketKind from typing import TYPE_CHECKING, Literal @@ -23,9 +22,6 @@ from trio._socket import _GetAddrInfoEntry from trio.testing import MockClock -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup - def test_close_all() -> None: class CloseMe(SocketType): diff --git a/src/trio/_tests/test_repl.py b/src/trio/_tests/test_repl.py index 28075d551c..f6cbfbfa1e 100644 --- a/src/trio/_tests/test_repl.py +++ b/src/trio/_tests/test_repl.py @@ -129,8 +129,6 @@ async def test_system_exits_in_exc_group( raw_input = build_raw_input( [ "import sys", - "if sys.version_info < (3, 11):", - " from exceptiongroup import BaseExceptionGroup", "", "raise BaseExceptionGroup('', [RuntimeError(), SystemExit()])", "print('AFTER BaseExceptionGroup')", @@ -152,8 +150,6 @@ async def test_system_exits_in_nested_exc_group( raw_input = build_raw_input( [ "import sys", - "if sys.version_info < (3, 11):", - " from exceptiongroup import BaseExceptionGroup", "", "raise BaseExceptionGroup(", " '', [BaseExceptionGroup('', [RuntimeError(), SystemExit()])])", diff --git a/src/trio/_tests/test_testing_raisesgroup.py b/src/trio/_tests/test_testing_raisesgroup.py index ba453edbe8..a95c0ff22c 100644 --- a/src/trio/_tests/test_testing_raisesgroup.py +++ b/src/trio/_tests/test_testing_raisesgroup.py @@ -10,9 +10,6 @@ from trio.testing import _Matcher as Matcher, _RaisesGroup as RaisesGroup from trio.testing._raises_group import repr_callable -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup, ExceptionGroup - def wrap_escape(s: str) -> str: return "^" + re.escape(s) + "$" diff --git a/src/trio/_tests/test_util.py b/src/trio/_tests/test_util.py index c8beefa1ca..69eca4785e 100644 --- a/src/trio/_tests/test_util.py +++ b/src/trio/_tests/test_util.py @@ -1,11 +1,10 @@ from __future__ import annotations -import sys import types from typing import TYPE_CHECKING, TypeVar if TYPE_CHECKING: - from collections.abc import AsyncGenerator, Coroutine, Generator + from collections.abc import AsyncGenerator import pytest import trio @@ -28,9 +27,6 @@ ) from ..testing import wait_all_tasks_blocked -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup, ExceptionGroup - if TYPE_CHECKING: from collections.abc import AsyncGenerator @@ -108,20 +104,6 @@ async def f() -> None: # pragma: no cover coroutine_or_error(f()) # type: ignore[arg-type, unused-coroutine] assert "expecting an async function" in str(excinfo.value) - import asyncio - - if sys.version_info < (3, 11): - - @asyncio.coroutine - def generator_based_coro() -> ( - Generator[Coroutine[None, None, None], None, None] - ): # pragma: no cover - yield from asyncio.sleep(1) - - with pytest.raises(TypeError) as excinfo: - coroutine_or_error(generator_based_coro()) # type: ignore[arg-type, unused-coroutine] - assert "asyncio" in str(excinfo.value) - with pytest.raises(TypeError) as excinfo: coroutine_or_error(create_asyncio_future_in_new_loop()) # type: ignore[arg-type, unused-coroutine] assert "asyncio" in str(excinfo.value) diff --git a/src/trio/_tests/type_tests/check_wraps.py b/src/trio/_tests/type_tests/check_wraps.py index 058e9d0609..36af56cc17 100644 --- a/src/trio/_tests/type_tests/check_wraps.py +++ b/src/trio/_tests/type_tests/check_wraps.py @@ -1,7 +1,8 @@ # https://github.com/python-trio/trio/issues/2775#issuecomment-1702267589 # (except platform independent...) +from typing import assert_type + import trio -from typing_extensions import assert_type async def fn(s: trio.SocketStream) -> None: diff --git a/src/trio/_tests/type_tests/path.py b/src/trio/_tests/type_tests/path.py index 2b956c9315..8cbe026f69 100644 --- a/src/trio/_tests/type_tests/path.py +++ b/src/trio/_tests/type_tests/path.py @@ -4,11 +4,10 @@ import os import pathlib import sys -from typing import IO, Any, BinaryIO +from typing import IO, Any, BinaryIO, assert_type import trio from trio._file_io import AsyncIOWrapper -from typing_extensions import assert_type def operator_checks(text: str, tpath: trio.Path, ppath: pathlib.Path) -> None: diff --git a/src/trio/_tests/type_tests/subprocesses.py b/src/trio/_tests/type_tests/subprocesses.py index 689ffd7d95..12ce31d36a 100644 --- a/src/trio/_tests/type_tests/subprocesses.py +++ b/src/trio/_tests/type_tests/subprocesses.py @@ -1,10 +1,9 @@ import os import sys from collections.abc import Sequence -from typing import TypeAlias +from typing import TypeAlias, assert_type import trio -from typing_extensions import assert_type StrOrBytesPath: TypeAlias = str | bytes | os.PathLike[str] | os.PathLike[bytes] diff --git a/src/trio/_tests/type_tests/task_status.py b/src/trio/_tests/type_tests/task_status.py index 6d2e3922bb..1f37bc9d85 100644 --- a/src/trio/_tests/type_tests/task_status.py +++ b/src/trio/_tests/type_tests/task_status.py @@ -1,7 +1,8 @@ """Check that started() can only be called for TaskStatus[None].""" +from typing import assert_type + from trio import TaskStatus -from typing_extensions import assert_type def check_status( diff --git a/src/trio/_threads.py b/src/trio/_threads.py index 46de93563d..9d33b5ff89 100644 --- a/src/trio/_threads.py +++ b/src/trio/_threads.py @@ -6,7 +6,7 @@ import queue as stdlib_queue import threading from itertools import count -from typing import TYPE_CHECKING, Generic, TypeVar +from typing import TYPE_CHECKING, Generic, TypeVar, TypeVarTuple, Unpack import attrs import outcome @@ -29,8 +29,6 @@ if TYPE_CHECKING: from collections.abc import Awaitable, Callable, Generator - from typing_extensions import TypeVarTuple, Unpack - from trio._core._traps import RaiseCancelT Ts = TypeVarTuple("Ts") diff --git a/src/trio/_util.py b/src/trio/_util.py index bae6608d88..b95b13b928 100644 --- a/src/trio/_util.py +++ b/src/trio/_util.py @@ -9,8 +9,11 @@ from typing import ( TYPE_CHECKING, Any, + Never, NoReturn, TypeVar, + TypeVarTuple, + Unpack, final as std_final, ) @@ -24,14 +27,8 @@ RetT = TypeVar("RetT") if TYPE_CHECKING: - import sys from types import AsyncGeneratorType, TracebackType - from typing_extensions import TypeVarTuple, Unpack - - if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup - PosArgsT = TypeVarTuple("PosArgsT") @@ -291,7 +288,7 @@ def _create(cls: type[T], *args: object, **kwargs: object) -> T: return super().__call__(*args, **kwargs) # type: ignore -def name_asyncgen(agen: AsyncGeneratorType[object, NoReturn]) -> str: +def name_asyncgen(agen: AsyncGeneratorType[object, Never]) -> str: """Return the fully-qualified name of the async generator function that produced the async generator iterator *agen*. """ diff --git a/src/trio/testing/_check_streams.py b/src/trio/testing/_check_streams.py index a53a45416a..7d39bf33dc 100644 --- a/src/trio/testing/_check_streams.py +++ b/src/trio/testing/_check_streams.py @@ -2,7 +2,6 @@ from __future__ import annotations import random -import sys from collections.abc import Awaitable, Callable, Generator from contextlib import contextmanager, suppress from typing import ( @@ -24,8 +23,6 @@ ArgsT = ParamSpec("ArgsT") -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup Res1 = TypeVar("Res1", bound=AsyncResource) Res2 = TypeVar("Res2", bound=AsyncResource) diff --git a/src/trio/testing/_fake_net.py b/src/trio/testing/_fake_net.py index 82d14f590d..b0bef1cd05 100644 --- a/src/trio/testing/_fake_net.py +++ b/src/trio/testing/_fake_net.py @@ -14,7 +14,7 @@ import os import socket import sys -from typing import TYPE_CHECKING, Any, NoReturn, TypeAlias, overload +from typing import TYPE_CHECKING, Any, NoReturn, Self, TypeAlias, overload import attrs @@ -27,7 +27,7 @@ from socket import AddressFamily, SocketKind from types import TracebackType - from typing_extensions import Buffer, Self + from typing_extensions import Buffer from trio._socket import AddressFormat, _GetAddrInfoEntry diff --git a/src/trio/testing/_raises_group.py b/src/trio/testing/_raises_group.py index 2c483a0f29..9874cfc5fb 100644 --- a/src/trio/testing/_raises_group.py +++ b/src/trio/testing/_raises_group.py @@ -1,7 +1,6 @@ from __future__ import annotations import re -import sys from abc import ABC, abstractmethod from re import Pattern from textwrap import indent @@ -39,9 +38,6 @@ ExcT_1 = TypeVar("ExcT_1", bound=Exception) ExcT_2 = TypeVar("ExcT_2", bound=Exception) -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup, ExceptionGroup - @final class _ExceptionInfo(Generic[MatchE]): diff --git a/tox.ini b/tox.ini index e09c1d97ca..8b0319f504 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{39,310,311,312,313,314,315,py310,py311} +envlist = py{39,311,312,313,314,315,py310,py311} labels = check = typing, gen_exports, type_completeness, pip_compile cython = py39-cython2,py39-cython,py311-cython2,py313-cython @@ -101,7 +101,7 @@ description = "Run type checks: mypy on all platforms, and pyright on `src/trio[ deps = -r test-requirements.txt exceptiongroup -base_python = 3.10 +base_python = 3.11 set_env = PYRIGHT_PYTHON_IGNORE_WARNINGS=1 commands =