Apply usability fixes to the SSH agent socket provider API
Marco Ricci

Marco Ricci commited on 2026-08-30 17:33:11
Zeige 2 geänderte Dateien mit 8 Einfügungen und 4 Löschungen.


The API definition actually requires the `typing-extensions` package,
but we forgot to declare that in `pyproject.toml`.

While it likely makes no typing difference, it is much better for
runtime checks to have `SSHAgentSocketProvider` be a runtime-checkable
protocol, instead of a string-valued type alias.  Among other things,
`isinstance(provider, SSHAgentSocketProvider)` fails if a string-valued
type alias is used.
... ...
@@ -30,7 +30,9 @@ classifiers = [
30 30
     "Topic :: Software Development :: Libraries",
31 31
     "Typing :: Typed",
32 32
 ]
33
-dependencies = []
33
+dependencies = [
34
+    "typing-extensions",
35
+]
34 36
 
35 37
 [project.urls]
36 38
 Documentation = "https://the13thletter.info/derivepassphrase/"
... ...
@@ -11,9 +11,8 @@ from typing import TYPE_CHECKING, Protocol
11 11
 from typing_extensions import NamedTuple, runtime_checkable
12 12
 
13 13
 if TYPE_CHECKING:
14
-    from collections.abc import Callable
15 14
 
16
-    from typing_extensions import Any, Buffer, TypeAlias
15
+    from typing_extensions import Any, Buffer
17 16
 
18 17
 # Semantic versioning.
19 18
 __version__ = "1.0a1"
... ...
@@ -51,8 +50,11 @@ class SSHAgentSocket(Protocol):
51 50
         """Like [socket.socket.recv][]."""
52 51
 
53 52
 
54
-SSHAgentSocketProvider: TypeAlias = "Callable[[], SSHAgentSocket]"
53
+@runtime_checkable
54
+class SSHAgentSocketProvider(Protocol):
55 55
     """A callable that provides an SSH agent socket."""
56
+    def __call__(self) -> SSHAgentSocket:
57
+        """Returns an SSH agent socket when called without arguments."""
56 58
 
57 59
 
58 60
 # For later major versions, we would define a new type.  For minor
59 61