You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Packet.fields_desc supports Packet / Packet_metaclass but typed as List[AnyField]
Scapy version
2.7.0
Python version
3.14
Operating system
Windows11
Additional environment information
No response
How to reproduce
The type annotation for fields_desc on Packet classes is declared as List[AnyField]:
# scapy/packet.py, line 108fields_desc= [] # type: List[AnyField]
However, at runtime, the Packet_metaclass.__new__ method explicitly handles the case where elements in fields_desc are Packet metaclass instances (i.e., references to other Packet subclasses), not just Field instances:
# scapy/base_classes.py, lines 371-380if"fields_desc"indct: # perform resolution of references to other packets # noqa: E501current_fld=dct["fields_desc"] # type: List[Union[scapy.fields.Field[Any, Any], Packet_metaclass]] # noqa: E501resolved_fld= [] # type: List[scapy.fields.Field[Any, Any]]forfld_or_pktincurrent_fld:
ifisinstance(fld_or_pkt, Packet_metaclass):
# reference to another fields_descforpkt_fldinfld_or_pkt.fields_desc:
resolved_fld.append(pkt_fld)
else:
resolved_fld.append(fld_or_pkt)
This means fields_desc can contain:
Field instances — the documented/typed behavior
Packet classes (metaclass instances) — which get inlined/expanded by flattening their fields_desc
Brief description
Packet.fields_descsupportsPacket/Packet_metaclassbut typed asList[AnyField]Scapy version
2.7.0
Python version
3.14
Operating system
Windows11
Additional environment information
No response
How to reproduce
The type annotation for
fields_desconPacketclasses is declared asList[AnyField]:However, at runtime, the
Packet_metaclass.__new__method explicitly handles the case where elements infields_descarePacketmetaclass instances (i.e., references to otherPacketsubclasses), not justFieldinstances:This means
fields_desccan contain:Fieldinstances — the documented/typed behaviorPacketclasses (metaclass instances) — which get inlined/expanded by flattening theirfields_descActual result
No response
Expected result
The type should be updated to something like:
Related resources
No response