Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AbhishekPandey1998
Copy link

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

Copy link

codecov bot commented Jul 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.08%. Comparing base (b54fdb7) to head (43ba816).

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.

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
1 participant