Skip to content
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

[Hinty] Type hinting automaton.py #3391

Merged
merged 2 commits into from
Nov 4, 2021
Merged

[Hinty] Type hinting automaton.py #3391

merged 2 commits into from
Nov 4, 2021

Conversation

Davidy22
Copy link
Contributor

@Davidy22 Davidy22 commented Oct 6, 2021

Used ansmachine.py as initial reference, Looked at some other files that I grepped into along the way.

Some notes taken while adding the hints:
add_breakpoints() returns None
Unsure of object type that could have fileno() on 609
645 assumed from rd and wr from the above class

Part of the long series of commits to work towards completion of #2158

Tests fail on my branch, but the error message seems unrelated to the file I changed, and I tried committing just a copy of master and that fails too so I guess it's just some teething issue in master

@codecov
Copy link

codecov bot commented Oct 6, 2021

Codecov Report

Merging #3391 (5e0cf48) into master (d1d2ff1) will decrease coverage by 0.00%.
The diff coverage is 83.64%.

@@            Coverage Diff             @@
##           master    #3391      +/-   ##
==========================================
- Coverage   85.28%   85.27%   -0.01%     
==========================================
  Files         277      277              
  Lines       57135    57192      +57     
==========================================
+ Hits        48728    48771      +43     
- Misses       8407     8421      +14     
Impacted Files Coverage Δ
scapy/automaton.py 75.43% <82.43%> (+0.33%) ⬆️
scapy/compat.py 95.73% <100.00%> (+0.02%) ⬆️
scapy/contrib/isotp/isotp_soft_socket.py 32.08% <100.00%> (ø)
scapy/pipetool.py 86.12% <100.00%> (+0.03%) ⬆️
scapy/sendrecv.py 80.92% <100.00%> (ø)
scapy/supersocket.py 58.78% <100.00%> (ø)
scapy/utils.py 77.36% <100.00%> (ø)
scapy/arch/windows/__init__.py 67.73% <0.00%> (-0.57%) ⬇️

@Davidy22
Copy link
Contributor Author

Davidy22 commented Oct 6, 2021

How did the % on files that I didn't change get affected?

@polybassa
Copy link
Contributor

Don't care about it. Codecov has some instability.

@gpotter2
Copy link
Member

gpotter2 commented Oct 9, 2021

You need to add automaton.py to .config/mypy/mypy_enabled.txt

@Davidy22
Copy link
Contributor Author

Added, noticed flake had some things to say about my hints too.

@Davidy22
Copy link
Contributor Author

Davidy22 commented Oct 13, 2021

Cleared out a couple hundred errors that mypy threw out, was nice to learn that there was a thing that would help with checking the type annotations. Made some notes along the way because there's some particularly hairy ones that I haven't gotten to resolving yet, some of which might involve changing other files. Pasting below:

  • WINDOWS and sys.platform == "win32" duplicate functionality, but sys.platform == "win32" is needed to make mypy stop whining about windows specific things.
  • mypy does not support using base class six.with_metaclass
  • state_wrapper being a function with attributes stapled to it throughout the program causes some issues in type checking. Followed a workaround here but there's some errors to work out still.
  • NewStateRequested being declared not in the top level causes some trouble for type checking.
  • Other files that reference things in this file are passing in some very unusual compound types.

@gpotter2
Copy link
Member

Thats some very solid work thanks a lot !

I have a trick for the WINDOWS vs sys.platform issue in the bags, because we're going to need it at some point to type arch/ anyways. I'mma try to commit it ASAP

@gpotter2 gpotter2 added the hacktoberfest-accepted When hacktoberfest PRs are good enough label Nov 1, 2021
Used ansmachine.py as initial reference, grepped into some other files along the way.

Some notes taken while adding the hints:
add_breakpoints returns None
Unsure of object type that could have fileno() on 609
645 assumed from rd and wr from the above class
@@ -21,7 +21,7 @@
open_test_sockets = list() # type: List[TestSocket]


class TestSocket(ObjectPipe, object):
class TestSocket(ObjectPipe[Packet], SuperSocket):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've tested this, but than decided to implement the Supersocket functions directly, since I had problems with the close function. Maybe that's fixed now, I just wanted to mention this, in case of strange bugs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was indeed super buggy but I think I figured it out, it needed an overwrite of the recv() function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the previous ping btw 😅

@gpotter2 gpotter2 added this to the 2.5.0 milestone Nov 1, 2021
@gpotter2 gpotter2 changed the title Type hinting automaton.py [Hinty] Type hinting automaton.py Nov 1, 2021
@polybassa
Copy link
Contributor

polybassa commented Nov 2, 2021 via email

@polybassa
Copy link
Contributor

polybassa commented Nov 2, 2021 via email

@gpotter2
Copy link
Member

gpotter2 commented Nov 2, 2021

@guedou This is ready for review.
I'd like to finish typing all of scapy's core soon-ish and proceed with 2.5.0.

There is mostly pipetools and arch left

guedou
guedou previously approved these changes Nov 2, 2021

def select_objects(inputs, remain):
# type: (List[Any], Union[float, int, None]) -> List[Any]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use a stricter type than Any here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too bad =/

@gpotter2 gpotter2 merged commit e28aa57 into secdev:master Nov 4, 2021
bzalkilani pushed a commit to bzalkilani/scapy that referenced this pull request Jun 12, 2022
* Type hinting automaton.py

Used ansmachine.py as initial reference, grepped into some other files along the way.

Some notes taken while adding the hints:
add_breakpoints returns None
Unsure of object type that could have fileno() on 609
645 assumed from rd and wr from the above class

* Various typing fixes

Co-authored-by: gpotter2 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted When hacktoberfest PRs are good enough Hinty
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants