From ac661379501e46a5436208037dcfa174b3c1486c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Taha=20Say=C4=B1n?= Date: Sat, 19 Sep 2026 12:52:50 +0300 Subject: [PATCH] Fix Packet.fields_desc type annotation to match runtime behavior (#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: https://github.com/secdev/scapy/issues/5018 AI-Assisted: no --- scapy/packet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scapy/packet.py b/scapy/packet.py index 8afb483c94b..e8dfe29447a 100644 --- a/scapy/packet.py +++ b/scapy/packet.py @@ -105,7 +105,7 @@ class Packet( "process_information" ] name = None - fields_desc = [] # type: ClassVar[List[AnyField]] + fields_desc = [] # type: ClassVar[List[Union[AnyField, Packet_metaclass]]] deprecated_fields = {} # type: Dict[str, Tuple[str, str]] overload_fields = {} # type: Dict[Type[Packet], Dict[str, Any]] payload_guess = [] # type: List[Tuple[Dict[str, Any], Type[Packet]]]