Fix import from stdlib module types
Marco Ricci

Marco Ricci commited on 2024-07-22 13:24:42
Zeige 1 geänderte Dateien mit 3 Einfügungen und 3 Löschungen.


Having both a `types` submodule and importing the stdlib `types`
directly as `types` was unproblematic at runtime, but very confusing to
`mypy`.

Since we only need one type, and since the stdlib `types` module has
a similar role to `collections.abc`, `typing` and `typing_extensions`,
I presume it is at least in the spirit of the Google Style Guide to
treat imports from `types` like imports from `typing`, i.e., to allow
direct import of symbols from that module.
... ...
@@ -14,11 +14,11 @@ from typing import TYPE_CHECKING
14 14
 
15 15
 from typing_extensions import Self
16 16
 
17
-from ssh_agent_client import types as ssh_types
17
+from ssh_agent_client import types
18 18
 
19 19
 if TYPE_CHECKING:
20
-    import types
21 20
     from collections.abc import Sequence
21
+    from types import TracebackType
22 22
 
23 23
 __all__ = ('SSHAgentClient',)
24 24
 __author__ = 'Marco Ricci <m@the13thletter.info>'
... ...
@@ -106,7 +106,7 @@ class SSHAgentClient:
106 106
         self,
107 107
         exc_type: type[BaseException] | None,
108 108
         exc_val: BaseException | None,
109
-        exc_tb: types.TracebackType | None,
109
+        exc_tb: TracebackType | None,
110 110
     ) -> bool:
111 111
         """Close socket connection upon context manager completion."""
112 112
         return bool(
113 113