Added type hints to most classes using mokeytype#306
Added type hints to most classes using mokeytype#306HitLuca wants to merge 1 commit intocorydolphin:masterfrom
Conversation
|
Hey Luca! Thank you very much for the contribution! I am a big fan of MyPy but don't have experience using it in packaged libraries. Are you familiar with the best practices in terms of maintaining Python version compatibility? If so, I'd love some help with that side of things and then we can merge this and release! |
|
The way I do it is to simply add a type checking step in the CI build step, below is an example of what I used to do with travis: language: python
python:
- "3.something"
install:
- install_your_packages_etc
script:
- your black, pylint, pytest, and other build step tests
- mypy --strict my_project tests # make mypy strictly check type hintsIf your CI pipeline runs against multiple python versions and mypy becomes unsupported in the future you just won't pass the build step and can react accordingly. All the missing steps to make this project fully compliant with mypy:
If we want to be extra fancy, we can run mypy in strict mode with the Standard mypy likes this, as it's typed def test(a: str) -> list:
return a.split(",")Strict mypy needs the type hints to be fully defined, so no from typing import List
def test(a: str) -> List[str]:
return a.split(",")Let me know if something is unclear! Happy to contribute more, I just can't ensure consistency as I have a ton of other stuff to do |
Resolves #275
Pretty straightforward process, I installed
monkeytypeand ranmonkeytype run -m unittestin order to run all tests and generate a database of call stacks.With a small bash loop I applied type hints to all files:
just to be sure, I installed
mypyand checked both theflask_corsand thetestspackages for typing issues (mypy flask_cors tests): out of a total of 35 errors, 12 were regarding the use ofunittest.main()in each test file, the others seem to not be of concern and could be fixed by ensuring stricter type hints. Below is a list of all the errors foundThere are a number of vague type hints (
Any,Callable) which could be made more specific, but for now even having vague hints is better than nothing