Skip to content

Commit a3972a0

Browse files
authored
A bit more test_ssl.py type check cleanup (#1405)
We're basically down to a) a few hard things, b) typing a bunch of callbacks/utility functions in tests
1 parent 9baefba commit a3972a0

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

tests/test_ssl.py

+22-12
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
TYPE_RSA,
5353
X509,
5454
PKey,
55+
X509Name,
5556
X509Store,
5657
dump_certificate,
5758
dump_privatekey,
@@ -3144,15 +3145,15 @@ def test_wantReadError(self) -> None:
31443145
conn.bio_read(1024)
31453146

31463147
@pytest.mark.parametrize("bufsize", [1.0, None, object(), "bufsize"])
3147-
def test_bio_read_wrong_args(self, bufsize) -> None:
3148+
def test_bio_read_wrong_args(self, bufsize: object) -> None:
31483149
"""
31493150
`Connection.bio_read` raises `TypeError` if passed a non-integer
31503151
argument.
31513152
"""
31523153
ctx = Context(SSLv23_METHOD)
31533154
conn = Connection(ctx, None)
31543155
with pytest.raises(TypeError):
3155-
conn.bio_read(bufsize)
3156+
conn.bio_read(bufsize) # type: ignore[arg-type]
31563157

31573158
def test_buffer_size(self) -> None:
31583159
"""
@@ -3287,7 +3288,9 @@ class TestConnectionRecvInto:
32873288
Tests for `Connection.recv_into`.
32883289
"""
32893290

3290-
def _no_length_test(self, factory):
3291+
def _no_length_test(
3292+
self, factory: typing.Callable[[int], typing.Any]
3293+
) -> None:
32913294
"""
32923295
Assert that when the given buffer is passed to `Connection.recv_into`,
32933296
whatever bytes are available to be received that fit into that buffer
@@ -3308,7 +3311,9 @@ def test_bytearray_no_length(self) -> None:
33083311
"""
33093312
self._no_length_test(bytearray)
33103313

3311-
def _respects_length_test(self, factory):
3314+
def _respects_length_test(
3315+
self, factory: typing.Callable[[int], typing.Any]
3316+
) -> None:
33123317
"""
33133318
Assert that when the given buffer is passed to `Connection.recv_into`
33143319
along with a value for `nbytes` that is less than the size of that
@@ -3330,7 +3335,9 @@ def test_bytearray_respects_length(self) -> None:
33303335
"""
33313336
self._respects_length_test(bytearray)
33323337

3333-
def _doesnt_overfill_test(self, factory):
3338+
def _doesnt_overfill_test(
3339+
self, factory: typing.Callable[[int], typing.Any]
3340+
) -> None:
33343341
"""
33353342
Assert that if there are more bytes available to be read from the
33363343
receive buffer than would fit into the buffer passed to
@@ -3881,7 +3888,9 @@ def test_unexpected_EOF(self) -> None:
38813888
(54, "ECONNRESET"),
38823889
]
38833890

3884-
def _check_client_ca_list(self, func):
3891+
def _check_client_ca_list(
3892+
self, func: typing.Callable[[Context], list[X509Name]]
3893+
) -> None:
38853894
"""
38863895
Verify the return value of the `get_client_ca_list` method for
38873896
server and client connections.
@@ -3912,9 +3921,9 @@ def test_set_client_ca_list_errors(self) -> None:
39123921
"""
39133922
ctx = Context(SSLv23_METHOD)
39143923
with pytest.raises(TypeError):
3915-
ctx.set_client_ca_list("spam")
3924+
ctx.set_client_ca_list("spam") # type: ignore[arg-type]
39163925
with pytest.raises(TypeError):
3917-
ctx.set_client_ca_list(["spam"])
3926+
ctx.set_client_ca_list(["spam"]) # type: ignore[list-item]
39183927

39193928
def test_set_empty_ca_list(self) -> None:
39203929
"""
@@ -4016,7 +4025,7 @@ def test_add_client_ca_wrong_args(self) -> None:
40164025
"""
40174026
ctx = Context(SSLv23_METHOD)
40184027
with pytest.raises(TypeError):
4019-
ctx.add_client_ca("spam")
4028+
ctx.add_client_ca("spam") # type: ignore[arg-type]
40204029

40214030
def test_one_add_client_ca(self) -> None:
40224031
"""
@@ -4142,7 +4151,7 @@ def test_available(self) -> None:
41424151
results = []
41434152

41444153
@feature_guard
4145-
def inner():
4154+
def inner() -> bool:
41464155
results.append(True)
41474156
return True
41484157

@@ -4157,7 +4166,7 @@ def test_unavailable(self) -> None:
41574166
feature_guard = _make_requires(False, "Error text")
41584167

41594168
@feature_guard
4160-
def inner(): # pragma: nocover
4169+
def inner() -> None: # pragma: nocover
41614170
pytest.fail("Should not be called")
41624171

41634172
with pytest.raises(NotImplementedError) as e:
@@ -4180,7 +4189,7 @@ def _client_connection(
41804189
self,
41814190
callback: typing.Callable[[Connection, bytes, T | None], bool],
41824191
data: T | None,
4183-
request_ocsp=True,
4192+
request_ocsp: bool = True,
41844193
) -> Connection:
41854194
"""
41864195
Builds a client connection suitable for using OCSP.
@@ -4586,6 +4595,7 @@ def pump() -> None:
45864595
s_listening = False
45874596
s_handshaking = True
45884597
# Write the duplicate ClientHello. See giant comment above.
4598+
assert latest_client_hello is not None
45894599
s.bio_write(latest_client_hello)
45904600

45914601
if s_handshaking:

0 commit comments

Comments
 (0)