Skip to content

Commit 7771186

Browse files
committed
Keep socket narrowing on covered paths
1 parent 94a35b5 commit 7771186

4 files changed

Lines changed: 17 additions & 24 deletions

File tree

tests/mock_vws/test_docker.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,11 @@ def _free_port() -> int:
185185
type=socket.SOCK_STREAM,
186186
) as sock:
187187
sock.bind(("127.0.0.1", 0))
188-
match sock.getsockname():
189-
case (str(), int() as port):
190-
return port
191-
case address:
192-
msg = f"Expected an IPv4 socket address, got {address!r}"
193-
raise TypeError(msg)
188+
address = sock.getsockname()
189+
assert isinstance(address, tuple)
190+
assert isinstance(address[1], int)
191+
port: int = address[1]
192+
return port
194193

195194

196195
@beartype

tests/mock_vws/test_healthcheck.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ def _unused_port() -> int:
4545
type=socket.SOCK_STREAM,
4646
) as sock:
4747
sock.bind(("localhost", 0))
48-
match sock.getsockname():
49-
case (str(), int() as port):
50-
pass
51-
case address:
52-
msg = f"Expected an IPv4 socket address, got {address!r}"
53-
raise TypeError(msg)
48+
address = sock.getsockname()
49+
assert isinstance(address, tuple)
50+
assert isinstance(address[1], int)
51+
port: int = address[1]
5452
return port
5553

5654

tests/mock_vws/test_httpx2_mock_usage.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,10 @@ def _unused_local_url() -> str:
8080
"""
8181
with socket.socket() as sock:
8282
sock.bind(("", 0))
83-
match sock.getsockname():
84-
case (str(), int() as port):
85-
pass
86-
case address:
87-
msg = f"Expected an IPv4 socket address, got {address!r}"
88-
raise TypeError(msg)
83+
address = sock.getsockname()
84+
assert isinstance(address, tuple)
85+
assert isinstance(address[1], int)
86+
port: int = address[1]
8987
return f"http://localhost:{port}"
9088

9189

tests/mock_vws/test_requests_mock_usage.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,10 @@ def _unused_local_url() -> str:
126126
"""Return a URL for a local address with nothing listening on it."""
127127
with socket.socket() as sock:
128128
sock.bind(("", 0))
129-
match sock.getsockname():
130-
case (str(), int() as port):
131-
pass
132-
case address:
133-
msg = f"Expected an IPv4 socket address, got {address!r}"
134-
raise TypeError(msg)
129+
address = sock.getsockname()
130+
assert isinstance(address, tuple)
131+
assert isinstance(address[1], int)
132+
port: int = address[1]
135133
return f"http://localhost:{port}"
136134

137135

0 commit comments

Comments
 (0)