Skip to content

Commit 1f052cc

Browse files
authored
Fixes for recent mypy (#1391)
Including ALPN typing which was totally broken
1 parent d3489af commit 1f052cc

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

src/OpenSSL/SSL.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ class _NoOverlappingProtocols:
289289
_ALPNSelectCallback = Callable[
290290
[
291291
"Connection",
292-
typing.Union[typing.List[bytes], _NoOverlappingProtocols],
292+
typing.List[bytes],
293293
],
294-
None,
294+
typing.Union[bytes, _NoOverlappingProtocols],
295295
]
296296
_CookieGenerateCallback = Callable[["Connection"], bytes]
297297
_CookieVerifyCallback = Callable[["Connection", bytes], bool]
@@ -1889,7 +1889,7 @@ def __init__(
18891889
# Negotiation. These strings get copied at some point but it's well
18901890
# after the callback returns, so we have to hang them somewhere to
18911891
# avoid them getting freed.
1892-
self._alpn_select_callback_args = None
1892+
self._alpn_select_callback_args: Any = None
18931893

18941894
# Reference the verify_callback of the Context. This ensures that if
18951895
# set_verify is called again after the SSL object has been created we

src/OpenSSL/_util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
from cryptography.hazmat.bindings.openssl.binding import Binding
99

10-
StrOrBytesPath = Union[str, bytes, os.PathLike]
10+
if sys.version_info >= (3, 9):
11+
StrOrBytesPath = Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]
12+
else:
13+
StrOrBytesPath = Union[str, bytes, os.PathLike]
1114

1215
binding = Binding()
1316
ffi = binding.ffi

src/OpenSSL/crypto.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from base64 import b16encode
99
from collections.abc import Iterable, Sequence
1010
from functools import partial
11-
from os import PathLike
1211
from typing import (
1312
Any,
1413
Callable,
@@ -24,6 +23,7 @@
2423
rsa,
2524
)
2625

26+
from OpenSSL._util import StrOrBytesPath
2727
from OpenSSL._util import (
2828
byte_string as _byte_string,
2929
)
@@ -87,7 +87,6 @@
8787
rsa.RSAPublicKey,
8888
]
8989
_Key = Union[_PrivateKey, _PublicKey]
90-
StrOrBytesPath = Union[str, bytes, PathLike]
9190
PassphraseCallableT = Union[bytes, Callable[..., bytes]]
9291

9392

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ commands =
4343

4444
[testenv:py311-mypy]
4545
deps =
46-
mypy==1.1.1
46+
mypy
4747
skip_install = true
4848
commands =
4949
mypy src

0 commit comments

Comments
 (0)