Skip to content

Fix: Add type annotation and override PcapReader's __iter__ for mypy static type checking#4803

Merged
gpotter2 merged 1 commit into
secdev:masterfrom
AbhishekPandey1998:pcapreader-type-annotation-fix-mypy
Jul 30, 2025
Merged

Fix: Add type annotation and override PcapReader's __iter__ for mypy static type checking#4803
gpotter2 merged 1 commit into
secdev:masterfrom
AbhishekPandey1998:pcapreader-type-annotation-fix-mypy

Conversation

@AbhishekPandey1998

Copy link
Copy Markdown
Contributor

Summary

Fixes a mypy type-checking issue where PcapReader's __next__ method was inferred to return a tuple[bytes, PacketMetadata] instead of a Packet due to inheriting __iter__ declaration of RawPcapReader.

Changes

Overridden __iter__() method explicitly in PcapReader, with a type hint to indicate that PcapReader is an iterator over Packet objects.

Note: No test was added as no runtime behavior was changed.

fixes #4728

@codecov

codecov Bot commented Jul 27, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.08%. Comparing base (b54fdb7) to head (43ba816).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4803      +/-   ##
==========================================
- Coverage   80.08%   80.08%   -0.01%     
==========================================
  Files         365      365              
  Lines       89027    89029       +2     
==========================================
  Hits        71296    71296              
- Misses      17731    17733       +2     
Files with missing lines Coverage Δ
scapy/utils.py 73.90% <100.00%> (+0.02%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gpotter2

Copy link
Copy Markdown
Member

Thanks for the PR !

@gpotter2 gpotter2 merged commit 723441d into secdev:master Jul 30, 2025
22 of 24 checks passed
@gpotter2 gpotter2 added this to the 2.7.0 milestone Nov 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mypy Misinterprets __next__ Return Type in PcapReader Subclass

2 participants