@@ -85,29 +85,30 @@ def get_all_addresses_v6() -> list[tuple[tuple[str, int, int], int]]:
85
85
)
86
86
87
87
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 ]:
89
89
if "%" in ip :
90
90
ip = ip [: ip .index ("%" )] # Strip scope_id.
91
91
ipaddr = ipaddress .ip_address (ip )
92
92
for adapter in adapters :
93
93
for adapter_ip in adapter .ips :
94
94
# 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 )
100
101
101
102
raise RuntimeError (f"No adapter found for IP address { ip } " )
102
103
103
104
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 ]:
105
106
for adapter in adapters :
106
107
if adapter .index == index :
107
108
for adapter_ip in adapter .ips :
108
109
# IPv6 addresses are represented as tuples
109
110
if isinstance (adapter_ip .ip , tuple ):
110
- return cast ( tuple [ str , int , int ], adapter_ip .ip )
111
+ return adapter_ip .ip
111
112
112
113
raise RuntimeError (f"No adapter found for index { index } " )
113
114
@@ -414,8 +415,7 @@ def create_sockets(
414
415
return listen_socket , respond_sockets
415
416
416
417
417
- def get_errno (e : Exception ) -> int :
418
- assert isinstance (e , socket .error )
418
+ def get_errno (e : OSError ) -> int :
419
419
return cast (int , e .args [0 ])
420
420
421
421
0 commit comments