Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cf44289

Browse filesBrowse files
authored
chore: cleanup typing in net utils (#1521)
1 parent dba44e4 commit cf44289
Copy full SHA for cf44289

File tree

Expand file treeCollapse file tree

1 file changed

+10
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-10
lines changed
Open diff view settings
Collapse file

‎src/zeroconf/_utils/net.py‎

Copy file name to clipboardExpand all lines: src/zeroconf/_utils/net.py
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,30 @@ def get_all_addresses_v6() -> list[tuple[tuple[str, int, int], int]]:
8585
)
8686

8787

88-
def ip6_to_address_and_index(adapters: list[Any], ip: str) -> tuple[tuple[str, int, int], int]:
88+
def ip6_to_address_and_index(adapters: list[ifaddr.Adapter], ip: str) -> tuple[tuple[str, int, int], int]:
8989
if "%" in ip:
9090
ip = ip[: ip.index("%")] # Strip scope_id.
9191
ipaddr = ipaddress.ip_address(ip)
9292
for adapter in adapters:
9393
for adapter_ip in adapter.ips:
9494
# IPv6 addresses are represented as tuples
95-
if isinstance(adapter_ip.ip, tuple) and ipaddress.ip_address(adapter_ip.ip[0]) == ipaddr:
96-
return (
97-
cast(tuple[str, int, int], adapter_ip.ip),
98-
cast(int, adapter.index),
99-
)
95+
if (
96+
adapter.index is not None
97+
and isinstance(adapter_ip.ip, tuple)
98+
and ipaddress.ip_address(adapter_ip.ip[0]) == ipaddr
99+
):
100+
return (adapter_ip.ip, adapter.index)
100101

101102
raise RuntimeError(f"No adapter found for IP address {ip}")
102103

103104

104-
def interface_index_to_ip6_address(adapters: list[Any], index: int) -> tuple[str, int, int]:
105+
def interface_index_to_ip6_address(adapters: list[ifaddr.Adapter], index: int) -> tuple[str, int, int]:
105106
for adapter in adapters:
106107
if adapter.index == index:
107108
for adapter_ip in adapter.ips:
108109
# IPv6 addresses are represented as tuples
109110
if isinstance(adapter_ip.ip, tuple):
110-
return cast(tuple[str, int, int], adapter_ip.ip)
111+
return adapter_ip.ip
111112

112113
raise RuntimeError(f"No adapter found for index {index}")
113114

@@ -414,8 +415,7 @@ def create_sockets(
414415
return listen_socket, respond_sockets
415416

416417

417-
def get_errno(e: Exception) -> int:
418-
assert isinstance(e, socket.error)
418+
def get_errno(e: OSError) -> int:
419419
return cast(int, e.args[0])
420420

421421

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.