Open
Description
Brief description
When using mypy to type-check code involving the PcapReader class, mypy incorrectly infers the return type of the __next__
method. Specifically, it interprets PcapReader.__next__
as returning the type defined in RawPcapReader.__next__
(i.e., Tuple[bytes, RawPcapReader.PacketMetadata]
), even though PcapReader overrides this method to return a Packet.
Scapy version
2.6.1
Python version
3.10.12
Operating system
Ubuntu 22.04.4 LTS
Additional environment information
No response
How to reproduce
- Define the PcapReader class.
- Run mypy on a script that uses PcapReader in an iteration context, such as:
for packet in PcapReader(path):
print(packet.time)
- Observe that mypy reports the type of packet as Tuple[bytes, RawPcapReader.PacketMetadata] instead of Packet.
Actual result
error: "tuple[bytes, PacketMetadata]" has no attribute "time" [attr-defined]
Expected result
Mypy interprets packet
, as returned by PcapReader's __next__
, as of type Packet.
Related resources
No response