scapy icon indicating copy to clipboard operation
scapy copied to clipboard

Type hints for layers/all.py and layers/clns.py (NOTE: impossible types)

Open LemmaEOF opened this issue 4 years ago • 1 comments

This PR adds type hints for the scapy/layers/all.py and scapy/layers/clns.py files. These are pretty common-sense, except for one issue:

The type of _create_cln_pdu is pretty definitively Callable[[bytes, Any], Packet], being a method that takes in bytes and kwargs and constructs a Packet from them. In most cases, you could feasibly pass this around and pretend it's a Type[Packet], which bind_bottom_up requires. However, bind_bottom_up accesses a payload_guess property that isn't possible to put on the _create_cln_pdu function. I attempted to work around this by writing a subclass of Packet that would supply the proper Type[Packet] needed, but this proved to be infeasible. I don't know what the best solution for this would be, so I added a TODO about it. I may come back to experiment with alternate solutions in a separate PR.

LemmaEOF avatar Oct 16 '21 22:10 LemmaEOF

Codecov Report

Merging #3410 (688e356) into master (1de61c7) will decrease coverage by 0.00%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #3410      +/-   ##
==========================================
- Coverage   85.95%   85.95%   -0.01%     
==========================================
  Files         275      275              
  Lines       56834    56836       +2     
==========================================
- Hits        48854    48851       -3     
- Misses       7980     7985       +5     
Impacted Files Coverage Δ
scapy/layers/all.py 80.95% <100.00%> (+0.95%) :arrow_up:
scapy/layers/clns.py 92.59% <100.00%> (+0.28%) :arrow_up:
scapy/arch/windows/__init__.py 67.73% <0.00%> (-0.57%) :arrow_down:
scapy/layers/ntp.py 84.59% <0.00%> (-0.28%) :arrow_down:
scapy/layers/inet.py 65.92% <0.00%> (-0.08%) :arrow_down:
scapy/fields.py 91.47% <0.00%> (-0.06%) :arrow_down:
scapy/sendrecv.py 85.16% <0.00%> (+0.15%) :arrow_up:

codecov[bot] avatar Oct 16 '21 22:10 codecov[bot]