scapy icon indicating copy to clipboard operation
scapy copied to clipboard

Use Sequence[Packet] in _PacketIterable instead of List

Open cdleonard opened this issue 1 year ago • 1 comments

The Sequence type only requires a read-only list of Packet and is covariant. With List[Packet] the following simple code fails on mypy:

pl = [Ether() / IP() / UDP() for _ in range(10)]
wrpcap("tmp.pcap", pl)

This happens because Packet.__div__ cleverly returns Self so pl is a List[Ether] which is incompatible with List[Packet].

We can't actually turn _PacketIterable into Iterable[Packet] because __len__ is used.

cdleonard avatar May 27 '24 17:05 cdleonard

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 82.19%. Comparing base (b0506a1) to head (1cee94d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4401      +/-   ##
==========================================
- Coverage   82.19%   82.19%   -0.01%     
==========================================
  Files         352      352              
  Lines       83994    83994              
==========================================
- Hits        69038    69036       -2     
- Misses      14956    14958       +2     
Files Coverage Δ
scapy/plist.py 85.63% <100.00%> (ø)

... and 4 files with indirect coverage changes

codecov[bot] avatar May 27 '24 17:05 codecov[bot]