From 457420e3d091214d23c516f43a92fed3f1faefec Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Sun, 5 Jul 2026 21:01:52 +0800 Subject: [PATCH 1/2] Prefer to use standard typing Self --- asyncssh/agent.py | 5 ++++- asyncssh/connection.py | 5 ++++- asyncssh/forward.py | 6 +++++- asyncssh/listener.py | 6 +++++- asyncssh/process.py | 6 +++++- asyncssh/scp.py | 5 ++++- asyncssh/sftp.py | 5 ++++- 7 files changed, 31 insertions(+), 7 deletions(-) diff --git a/asyncssh/agent.py b/asyncssh/agent.py index d44a7e00..a71b1094 100644 --- a/asyncssh/agent.py +++ b/asyncssh/agent.py @@ -25,7 +25,10 @@ import sys from types import TracebackType from typing import TYPE_CHECKING, List, Optional, Sequence, Tuple, Type, Union -from typing_extensions import Protocol, Self +if sys.version_info >= (3, 11): + from typing import Protocol, Self +else: + from typing_extensions import Protocol, Self from .listener import SSHForwardListener from .misc import async_context_manager, maybe_wait_closed diff --git a/asyncssh/connection.py b/asyncssh/connection.py index 93427c42..730f426d 100644 --- a/asyncssh/connection.py +++ b/asyncssh/connection.py @@ -40,7 +40,10 @@ from typing import TYPE_CHECKING, Any, AnyStr, Awaitable, Callable, Dict from typing import Generic, List, Mapping, Optional, Sequence, Set, Tuple from typing import Type, TypeVar, Union, cast -from typing_extensions import Protocol, Self +if sys.version_info >= (3, 11): + from typing import Protocol, Self +else: + from typing_extensions import Protocol, Self from .agent import SSHAgentClient, SSHAgentListener diff --git a/asyncssh/forward.py b/asyncssh/forward.py index 8470c000..b691d05b 100644 --- a/asyncssh/forward.py +++ b/asyncssh/forward.py @@ -22,10 +22,14 @@ import asyncio import socket +import sys from types import TracebackType from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, Optional from typing import Type, cast -from typing_extensions import Self +if sys.version_info >= (3, 11): + from typing import Self +else: + from typing_extensions import Self from .misc import ChannelOpenError, SockAddr diff --git a/asyncssh/listener.py b/asyncssh/listener.py index e9cc475b..97e03fec 100644 --- a/asyncssh/listener.py +++ b/asyncssh/listener.py @@ -23,10 +23,14 @@ import asyncio import errno import socket +import sys from types import TracebackType from typing import TYPE_CHECKING, AnyStr, Callable, Generic, List, Optional from typing import Sequence, Set, Tuple, Type, Union -from typing_extensions import Self +if sys.version_info >= (3, 11): + from typing import Self +else: + from typing_extensions import Self from .forward import SSHForwarderCoro from .forward import SSHLocalPortForwarder, SSHLocalPathForwarder diff --git a/asyncssh/process.py b/asyncssh/process.py index 5e109989..23131452 100644 --- a/asyncssh/process.py +++ b/asyncssh/process.py @@ -29,11 +29,15 @@ from pathlib import PurePath import socket import stat +import sys from types import TracebackType from typing import Any, AnyStr, Awaitable, Callable, Dict, Generic, IO from typing import Iterable, List, Mapping, Optional, Set, TextIO from typing import Tuple, Type, TypeVar, Union, cast -from typing_extensions import Protocol, Self +if sys.version_info >= (3, 11): + from typing import Protocol, Self +else: + from typing_extensions import Protocol, Self from .channel import SSHChannel, SSHClientChannel, SSHServerChannel diff --git a/asyncssh/scp.py b/asyncssh/scp.py index f3b69c74..5dafe820 100644 --- a/asyncssh/scp.py +++ b/asyncssh/scp.py @@ -33,7 +33,10 @@ from types import TracebackType from typing import TYPE_CHECKING, AsyncIterator, List, NoReturn, Optional from typing import Sequence, Tuple, Type, Union, cast -from typing_extensions import Protocol, Self +if sys.version_info >= (3, 11): + from typing import Protocol, Self +else: + from typing_extensions import Protocol, Self from .constants import DEFAULT_LANG from .constants import FILEXFER_TYPE_REGULAR, FILEXFER_TYPE_DIRECTORY diff --git a/asyncssh/sftp.py b/asyncssh/sftp.py index 75d8df7a..7a7abc39 100644 --- a/asyncssh/sftp.py +++ b/asyncssh/sftp.py @@ -37,7 +37,10 @@ from typing import TYPE_CHECKING, AnyStr, AsyncIterator, Awaitable, Callable from typing import Dict, Generic, IO, Iterable, List, Mapping, Optional from typing import Sequence, Set, Tuple, Type, TypeVar, Union, cast, overload -from typing_extensions import Literal, Protocol, Self +if sys.version_info >= (3, 11): + from typing import Literal, Protocol, Self +else: + from typing_extensions import Literal, Protocol, Self from . import constants from .constants import DEFAULT_LANG From e8fce2b6648871f70f8f6f129bf1a05d45363c89 Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Mon, 6 Jul 2026 13:58:56 +0800 Subject: [PATCH 2/2] feat: only install typing-extensions for `python<3.11` --- asyncssh/agent.py | 7 ++++--- asyncssh/connection.py | 8 ++++---- asyncssh/kex_dh.py | 4 ++-- asyncssh/misc.py | 6 +++--- asyncssh/process.py | 6 +++--- asyncssh/public_key.py | 5 ++--- asyncssh/saslprep.py | 3 +-- asyncssh/scp.py | 6 +++--- asyncssh/sftp.py | 9 +++++---- pyproject.toml | 2 +- 10 files changed, 28 insertions(+), 28 deletions(-) diff --git a/asyncssh/agent.py b/asyncssh/agent.py index a71b1094..df65912e 100644 --- a/asyncssh/agent.py +++ b/asyncssh/agent.py @@ -24,11 +24,12 @@ import os import sys from types import TracebackType -from typing import TYPE_CHECKING, List, Optional, Sequence, Tuple, Type, Union +from typing import TYPE_CHECKING, List, Optional, Protocol, Sequence, Tuple +from typing import Type, Union if sys.version_info >= (3, 11): - from typing import Protocol, Self + from typing import Self else: - from typing_extensions import Protocol, Self + from typing_extensions import Self from .listener import SSHForwardListener from .misc import async_context_manager, maybe_wait_closed diff --git a/asyncssh/connection.py b/asyncssh/connection.py index 730f426d..477e69ab 100644 --- a/asyncssh/connection.py +++ b/asyncssh/connection.py @@ -38,12 +38,12 @@ from pathlib import Path from types import TracebackType from typing import TYPE_CHECKING, Any, AnyStr, Awaitable, Callable, Dict -from typing import Generic, List, Mapping, Optional, Sequence, Set, Tuple -from typing import Type, TypeVar, Union, cast +from typing import Generic, List, Mapping, Optional, Protocol, Sequence, Set +from typing import Tuple, Type, TypeVar, Union, cast if sys.version_info >= (3, 11): - from typing import Protocol, Self + from typing import Self else: - from typing_extensions import Protocol, Self + from typing_extensions import Self from .agent import SSHAgentClient, SSHAgentListener diff --git a/asyncssh/kex_dh.py b/asyncssh/kex_dh.py index ab0dc87f..25a09206 100644 --- a/asyncssh/kex_dh.py +++ b/asyncssh/kex_dh.py @@ -21,8 +21,8 @@ """SSH Diffie-Hellman, ECDH, and Edwards DH key exchange handlers""" from hashlib import sha1, sha224, sha256, sha384, sha512 -from typing import TYPE_CHECKING, Callable, Mapping, Optional, Type, cast -from typing_extensions import Protocol +from typing import TYPE_CHECKING, Callable, Mapping, Optional, Protocol, Type +from typing import cast from .constants import DEFAULT_LANG from .crypto import Curve25519DH, Curve448DH, DH, ECDH, PQClass, MLKEM, SNTRUP diff --git a/asyncssh/misc.py b/asyncssh/misc.py index e9f0d183..47badb9d 100644 --- a/asyncssh/misc.py +++ b/asyncssh/misc.py @@ -37,9 +37,9 @@ from random import SystemRandom from types import TracebackType from typing import Any, AsyncContextManager, Awaitable, Callable, Dict -from typing import Generator, Generic, IO, Iterator, List, Mapping, Optional -from typing import Sequence, Tuple, Type, TypeVar, Union, cast, overload -from typing_extensions import Literal, Protocol +from typing import Generator, Generic, IO, Iterator, List, Literal, Mapping +from typing import Optional, Protocol, Sequence, Tuple, Type, TypeVar, Union +from typing import cast, overload from .constants import DEFAULT_LANG from .constants import DISC_COMPRESSION_ERROR, DISC_CONNECTION_LOST diff --git a/asyncssh/process.py b/asyncssh/process.py index 23131452..c31c1ce8 100644 --- a/asyncssh/process.py +++ b/asyncssh/process.py @@ -32,12 +32,12 @@ import sys from types import TracebackType from typing import Any, AnyStr, Awaitable, Callable, Dict, Generic, IO -from typing import Iterable, List, Mapping, Optional, Set, TextIO +from typing import Iterable, List, Mapping, Optional, Protocol, Set, TextIO from typing import Tuple, Type, TypeVar, Union, cast if sys.version_info >= (3, 11): - from typing import Protocol, Self + from typing import Self else: - from typing_extensions import Protocol, Self + from typing_extensions import Self from .channel import SSHChannel, SSHClientChannel, SSHServerChannel diff --git a/asyncssh/public_key.py b/asyncssh/public_key.py index b4664983..5e8637c6 100644 --- a/asyncssh/public_key.py +++ b/asyncssh/public_key.py @@ -29,9 +29,8 @@ from hashlib import md5, sha1, sha256, sha384, sha512 from pathlib import Path, PurePath -from typing import Callable, Dict, List, Mapping, Optional, Sequence, Set -from typing import Tuple, Type, Union, cast -from typing_extensions import Protocol +from typing import Callable, Dict, List, Mapping, Optional, Protocol +from typing import Sequence, Set, Tuple, Type, Union, cast from .crypto import ed25519_available, ed448_available from .encryption import Encryption diff --git a/asyncssh/saslprep.py b/asyncssh/saslprep.py index 9b736617..4b2563b3 100644 --- a/asyncssh/saslprep.py +++ b/asyncssh/saslprep.py @@ -33,8 +33,7 @@ # pylint: enable=deprecated-module import unicodedata -from typing import Callable, Optional, Sequence -from typing_extensions import Literal +from typing import Callable, Literal, Optional, Sequence class SASLPrepError(ValueError): diff --git a/asyncssh/scp.py b/asyncssh/scp.py index 5dafe820..3ecafbd5 100644 --- a/asyncssh/scp.py +++ b/asyncssh/scp.py @@ -32,11 +32,11 @@ import sys from types import TracebackType from typing import TYPE_CHECKING, AsyncIterator, List, NoReturn, Optional -from typing import Sequence, Tuple, Type, Union, cast +from typing import Protocol, Sequence, Tuple, Type, Union, cast if sys.version_info >= (3, 11): - from typing import Protocol, Self + from typing import Self else: - from typing_extensions import Protocol, Self + from typing_extensions import Self from .constants import DEFAULT_LANG from .constants import FILEXFER_TYPE_REGULAR, FILEXFER_TYPE_DIRECTORY diff --git a/asyncssh/sftp.py b/asyncssh/sftp.py index 7a7abc39..e496f9ef 100644 --- a/asyncssh/sftp.py +++ b/asyncssh/sftp.py @@ -35,12 +35,13 @@ import time from types import TracebackType from typing import TYPE_CHECKING, AnyStr, AsyncIterator, Awaitable, Callable -from typing import Dict, Generic, IO, Iterable, List, Mapping, Optional -from typing import Sequence, Set, Tuple, Type, TypeVar, Union, cast, overload +from typing import Dict, Generic, IO, Iterable, List, Literal, Mapping +from typing import Optional, Protocol, Sequence, Set, Tuple, Type, TypeVar +from typing import Union, cast, overload if sys.version_info >= (3, 11): - from typing import Literal, Protocol, Self + from typing import Self else: - from typing_extensions import Literal, Protocol, Self + from typing_extensions import Self from . import constants from .constants import DEFAULT_LANG diff --git a/pyproject.toml b/pyproject.toml index dd2f82b8..7adcdd01 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ classifiers = [ requires-python = '>= 3.10' dependencies = [ 'cryptography >= 48.0.1', - 'typing_extensions >= 4.0.0', + "typing-extensions (>= 4.0.0); python_version < '3.11'", ] dynamic = ['version']