python-libusb1 icon indicating copy to clipboard operation
python-libusb1 copied to clipboard

Add initial mypy support

Open ahawker opened this issue 5 years ago • 2 comments

Status: Ready for review Issue: Fixes #57

If merged, this PR adds initial support for mypy.

  • Type stubs, .pyi files have been added for the package interface __init__.py and libusb1.py module.
  • The _version.py module and tests are currently excluded from checks (see mypy.ini). They're skipped now since they're "internal" but can easily be added to type checks in the future.

I did the best I could with the type definitions for functions that I'm not using in https://github.com/adbpy/transports but there are potentially some mistakes/inconsistencies. These should be relatively easily to "whack-o-mole" as they come up (or during code review for someone that knows the codebase better).

Testing

The stubs should pass normal and strict checks.

hawker@mbp:~/src/github.com/ahawker/python-libusb1|master⚡
⇒  mypy usb1 && mypy --strict usb1
Success: no issues found in 4 source files
Success: no issues found in 4 source files

There is also a new Travis CI job for validating the mypy type hints on py36.

I also ran them against all the code in the examples/ directory. All types exported from the package appear correct in there, with the only strict errors being the fact that the examples themselves aren't typed.

ahawker avatar Sep 08 '20 22:09 ahawker

@vpelletier Thank you for taking the the time to do an in-depth review & feedback! Life's gotten a bit busy so it'll be a little slower to tidy this up but just letting you know I haven't forgotten.

ahawker avatar Sep 14 '20 23:09 ahawker

You're welcome. There is no hurry, on my side it's also getting pretty busy, and will probably remain so for about a month.

vpelletier avatar Sep 15 '20 12:09 vpelletier