Commit 036c3c1
build(lint): enable 8 more mypy error codes + fix violations
Add eight error codes to [tool.mypy] enable_error_code on top of
explicit-override: ignore-without-code, truthy-iterable, redundant-self,
unused-awaitable (free — zero violations), truthy-bool, redundant-expr,
possibly-undefined, mutable-override (cheap — fixed below). Deliberately
NOT warn_unreachable / disallow_any_decorated: they false-positive against
the ProtoEnum dynamic-_missing_ `case _:` pattern and stdlib decorator
machinery (Any-typed), respectively.
Categories fixed:
- truthy-bool + packet-handler redundant-expr (cast-away-None root cause):
the UDP/TCP/ICMPv4/ICMPv6 RX handlers cast stack.sockets.get(...) /
get_for_ingress(...) — both `socket | None` — to a bare TcpSocket /
UdpSocket, lying to mypy that the lookup never returns None. That single
dishonesty produced the truthy-bool walrus warnings and the
`is None or` / `is not None and` redundant-expr warnings. Made every
cast honest (`cast(UdpSocket | None, ...)` / `cast(TcpSocket | None,
...)`) and converted walrus-truthiness to explicit `is None` / `is not
None` checks. Runtime is identical — the handlers already coped with
None via truthiness; only the type is now honest and the guard explicit.
- possibly-undefined: enum __str__ `match self` blocks bound `name` only
on the known-member cases, leaving it unbound for a dynamically
materialised unknown ProtoEnum member. Added a `case _:` default that
binds the existing fallback form and dropped the now-redundant
`... if self.is_unknown else name` ternary, keeping identical output for
known and unknown members (net_proto lib/enums + dhcp4/dhcp6/dns/llc/
ip6_routing enums).
- redundant-expr (defensive isinstance guards): for net_addr Ip4/Ip6Network
tuple-form validation and the DHCPv4 classless-static-route __post_init__,
mypy proves the element-type isinstance operands statically true from the
declared types, but the runtime checks are load-bearing (a test pins the
DHCPv4 wrong-element rejection; the network guard prevents a bare-builtin
int(str) later). Kept the guards: extracted a `_is_well_formed_route`
helper typed `object` for DHCPv4 (no suppression needed), and a narrow
justified `# type: ignore[redundant-expr]` for the two network files.
The sendmsg ancdata 3-tuple check was genuinely redundant (item is
already a tuple) — simplified to `len(item) != 3`.
- mutable-override: TCP cubic/cwnd integration test classes set
`_DEFAULT_CC_MODE = CcMode.RENO`, narrowing the TcpTestCase base attr
typed `CcMode | None`. Annotated each override `: CcMode | None` to keep
the base type.
- examples_legacy / tests_runner (same gate): dropped a dead `if subsystem`
truthy filter in stack.py, added a `case _: assert_never(ip_version)`
exhaustiveness guard in client__icmp_echo.py, and annotated
TestslideStyleRunner.resultclass to the base's mutable
`Callable[..., TextTestResult]` type.
- Real latent bug: stack/__init__.py boot defaults IP4_ADDRESS / IP6_ADDRESS
/ IP4_GATEWAY / IP6_GATEWAY were unannotated `= None`, so mypy inferred
type `None`, making the operator-set boot-address path in lifecycle.init
(`Ip4IfAddr(_stack.IP4_ADDRESS)` etc.) dead to the type checker. Annotated
to the real intended types (`str | None` for the host addresses consumed by
Ip{4,6}IfAddr(...), `Ip{4,6}Address | None` for the gateways passed to
install_boot_default_routes). No cascade.
Doc: typing.md §2.1 documents the now-enabled extra codes and why
warn_unreachable / disallow_any_decorated stay off; §21 notes
ignore-without-code now mechanically forbids bare `# type: ignore`.
make lint clean, 12752 passing / 0 failing / 0 skipped, no leaked log lines.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent d0d1bc2 commit 036c3c1
22 files changed
Lines changed: 225 additions & 105 deletions
File tree
- .claude/rules
- examples_legacy
- packages
- net_addr/net_addr
- net_proto/net_proto
- lib
- protocols
- dhcp4
- options
- dhcp6
- dns
- ip6_routing
- llc
- pytcp/pytcp
- runtime
- packet_handler
- socket
- stack
- tests/integration/protocols/tcp
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
60 | 83 | | |
61 | 84 | | |
62 | 85 | | |
| |||
1028 | 1051 | | |
1029 | 1052 | | |
1030 | 1053 | | |
1031 | | - | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
1032 | 1058 | | |
1033 | 1059 | | |
1034 | 1060 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
| 125 | + | |
124 | 126 | | |
125 | 127 | | |
126 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
382 | 382 | | |
383 | 383 | | |
384 | 384 | | |
385 | | - | |
| 385 | + | |
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
96 | 104 | | |
97 | 105 | | |
98 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
96 | 104 | | |
97 | 105 | | |
98 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
64 | 66 | | |
65 | | - | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| |||
142 | 144 | | |
143 | 145 | | |
144 | 146 | | |
| 147 | + | |
| 148 | + | |
145 | 149 | | |
146 | | - | |
| 150 | + | |
147 | 151 | | |
148 | 152 | | |
149 | 153 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
95 | 97 | | |
96 | | - | |
| 98 | + | |
Lines changed: 26 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
78 | 97 | | |
79 | 98 | | |
80 | 99 | | |
| |||
101 | 120 | | |
102 | 121 | | |
103 | 122 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
111 | 130 | | |
112 | 131 | | |
113 | 132 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
90 | 92 | | |
91 | | - | |
| 93 | + | |
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
| |||
125 | 127 | | |
126 | 128 | | |
127 | 129 | | |
| 130 | + | |
| 131 | + | |
128 | 132 | | |
129 | | - | |
| 133 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
66 | 68 | | |
67 | | - | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| |||
98 | 100 | | |
99 | 101 | | |
100 | 102 | | |
| 103 | + | |
| 104 | + | |
101 | 105 | | |
102 | | - | |
| 106 | + | |
103 | 107 | | |
104 | 108 | | |
105 | 109 | | |
| |||
139 | 143 | | |
140 | 144 | | |
141 | 145 | | |
| 146 | + | |
| 147 | + | |
142 | 148 | | |
143 | | - | |
| 149 | + | |
144 | 150 | | |
145 | 151 | | |
146 | 152 | | |
| |||
165 | 171 | | |
166 | 172 | | |
167 | 173 | | |
| 174 | + | |
| 175 | + | |
168 | 176 | | |
169 | | - | |
| 177 | + | |
0 commit comments