Skip to content

Commit 3b7ef13

Browse files
committed
Fixing typing errors.
1 parent 07daee9 commit 3b7ef13

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

.flake8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ max-line-length = 120
33
ignore = E203, E266, E701, E704, W503, E731, E741
44
per-file-ignores =
55
pytcp/**/__init__.py:F401
6-
net_addr/__init__.py:F401
6+
net_addr/__init__.py:F401
7+
pytcp/stack/__init__.py:F821

pytcp/lib/ip_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def pick_local_port() -> int:
156156
"""
157157

158158
available_ephemeral_ports = set(EPHEMERAL_PORT_RANGE) - {
159-
int(_.split("/")[3]) for _ in stack.sockets.values()
159+
socket.local_port for socket in stack.sockets.values()
160160
}
161161

162162
if len(available_ephemeral_ports):

pytcp/socket/__init__.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
"""
3636

3737

38+
from pytcp.socket.socket import (
39+
ReceiveTimeout, # pyright: ignore[reportUnusedImport]
40+
)
41+
from pytcp.socket.socket import gaierror # pyright: ignore[reportUnusedImport]
3842
from pytcp.socket.socket import ( # noqa: F401
3943
AddressFamily,
4044
IpProto,
41-
ReceiveTimeout,
4245
Socket,
4346
SocketType,
44-
gaierror,
4547
)
4648

4749
AF_INET = AddressFamily.INET4
@@ -78,17 +80,23 @@ def socket(
7880
from pytcp.socket.tcp__socket import TcpSocket
7981
from pytcp.socket.udp__socket import UdpSocket
8082

81-
match type, protocol:
82-
case SocketType.STREAM, None | IpProto.TCP:
83+
match family, type, protocol:
84+
case _, SocketType.STREAM, None | IpProto.TCP:
8385
return TcpSocket(address_family=family)
8486

85-
case SocketType.DGRAM, None | IpProto.UDP:
87+
case _, SocketType.DGRAM, None | IpProto.UDP:
8688
return UdpSocket(address_family=family)
8789

88-
case SocketType.DGRAM, IpProto.ICMP4 | IpProto.ICMP6:
90+
case _, SocketType.DGRAM, IpProto.ICMP4 | IpProto.ICMP6:
8991
raise NotImplementedError
9092

91-
case SocketType.RAW, _:
93+
case AddressFamily.INET4, SocketType.RAW, None:
94+
return RawSocket(address_family=family, ip_proto=IpProto.IP4)
95+
96+
case AddressFamily.INET6, SocketType.RAW, None:
97+
return RawSocket(address_family=family, ip_proto=IpProto.IP6)
98+
99+
case _, SocketType.RAW, _ if protocol is not None:
92100
return RawSocket(address_family=family, ip_proto=protocol)
93101

94102
case _:

pytcp/stack/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ def init(
232232
ip4_host: Ip4Host | None = (
233233
None
234234
if IP4_ADDRESS is None
235-
else Ip4Host(IP4_ADDRESS, gateway=IP4_GATEWAY) # type: ignore
235+
else Ip4Host(IP4_ADDRESS, gateway=IP4_GATEWAY)
236236
),
237237
ip4_dhcp: bool = True if IP4_ADDRESS is None else False,
238238
ip6_support: bool = True,
239239
ip6_host: Ip6Host | None = (
240240
None
241241
if IP6_ADDRESS is None
242-
else Ip4Host(IP6_ADDRESS, gateway=IP6_GATEWAY) # type: ignore
242+
else Ip6Host(IP6_ADDRESS, gateway=IP6_GATEWAY)
243243
),
244244
ip6_gua_autoconfig: bool = True if IP6_ADDRESS is None else False,
245245
ip6_lla_autoconfig: bool = True,

0 commit comments

Comments
 (0)