Conversation
…dev#5018) At runtime, Packet_metaclass.__new__ explicitly handles the case where elements in fields_desc are Packet_metaclass instances (references to another Packet's fields_desc), not just Field instances: if isinstance(fld_or_pkt, Packet_metaclass): for pkt_fld in fld_or_pkt.fields_desc: ... # base_classes.py, line ~372 The class-level annotation declared fields_desc as List[AnyField], which does not include Packet_metaclass. This caused type checkers to flag valid usage such as: fields_desc = [MyOtherPacket, ByteField('x', 0)] Updated the annotation to List[Union[AnyField, Packet_metaclass]] to accurately reflect what the list can contain before Packet_metaclass resolution flattens the references into plain Field instances. Closes: secdev#5018 AI-Assisted: no
Ts-Boom
force-pushed
the
fix-fields-desc-type
branch
from
September 19, 2026 21:02
64c0471 to
ac66137
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5187 +/- ##
==========================================
- Coverage 80.37% 80.36% -0.01%
==========================================
Files 375 375
Lines 97675 97675
==========================================
- Hits 78506 78501 -5
- Misses 19169 19174 +5
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Packet.fields_descwas typed asClassVar[List[AnyField]], but atruntime
Packet_metaclass.__new__explicitly handles the case whereelements can be
Packet_metaclassinstances (references to anotherpacket's
fields_desc):This means the annotation was incorrect for the pre-resolution state of the list, causing type checkers to flag valid usage like:
Fix
Changed the annotation from
List[AnyField]toList[Union[AnyField, Packet_metaclass]].Packet_metaclassis already imported inpacket.py(line 44) andUnionis already in the typing imports — no new dependencies added.References
Packet.fields_desctype annotation is inconsistent with runtime behavior #5018AI Disclosure
No AI tools were used.