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

PEP484 type hints / mypy #1456

Open
5 of 11 tasks
The-Compiler opened this issue Apr 26, 2016 · 11 comments
Open
5 of 11 tasks

PEP484 type hints / mypy #1456

The-Compiler opened this issue Apr 26, 2016 · 11 comments
Labels
component: style / refactoring Issues related to coding styles or code that should be refactored. priority: 1 - middle Issues which should be done at some point, but aren't that important.
Projects

Comments

@The-Compiler
Copy link
Member

The-Compiler commented Apr 26, 2016

As mypy seems a lot more usable than when I last looked at it, maybe qutebrowser should start using PEP484 type hints.

PyQt 5.6 also comes with .pyi files for the whole PyQt, so that might already be beneficial before starting to annotate qutebrowser source.


@The-Compiler The-Compiler added the priority: 1 - middle Issues which should be done at some point, but aren't that important. label Apr 26, 2016
@rcorre

This comment has been minimized.

@The-Compiler

This comment has been minimized.

@The-Compiler
Copy link
Member Author

The-Compiler commented May 10, 2016

This is was blocked by #637.

@The-Compiler
Copy link
Member Author

python/typing#310 (comment) looks useful too

@The-Compiler
Copy link
Member Author

PyAnnotate sounds interesting - though someone™ would need to add Python 3 style annotation support to it.

@The-Compiler
Copy link
Member Author

MonkeyType seems awesome!

@The-Compiler The-Compiler added the component: style / refactoring Issues related to coding styles or code that should be refactored. label Mar 22, 2018
@The-Compiler The-Compiler added this to Refactoring in Extensions Mar 22, 2018
@The-Compiler
Copy link
Member Author

mypy now supports PEP 571, which means it'd be possible to release type hints for PyQt rewritten so they actually work with MyPy.

@The-Compiler The-Compiler moved this from Refactoring to Backlog in Extensions Oct 15, 2018
@The-Compiler The-Compiler added component: style / refactoring Issues related to coding styles or code that should be refactored. and removed component: style / refactoring Issues related to coding styles or code that should be refactored. labels Nov 30, 2018
@The-Compiler
Copy link
Member Author

mypy is now running on Travis CI! There's still a long way to go as not much code is annotated right now, but it's a good start.

@The-Compiler
Copy link
Member Author

qutebrowser is now using mypy's check_untyped_defs, which means it checks the entire codebase, even where there aren't any type annotations yet.

This requires quite some # type: ignore comments (~140 at the time of writing), mainly due to issues with PyQt5-stubs. I expect those to go down again in the future, as those issues can be fixed there (or even upstream in PyQt5).

I'll update the original post with some more TODO items about things I've learned along the way.

@The-Compiler
Copy link
Member Author

The-Compiler commented Jan 17, 2020

Might be interesting to use diff-cover to enforce any new code to have type annotations.

See pytest-dev/pytest#6486 for an example.

edit: I added tox -e mypy-diff now - not using it on CI by default since there are a lot of WIP PRs still, but I'll probably turn it on at some point.

@The-Compiler
Copy link
Member Author

Also note that mypy has a pretty nice HTML report feature nowadays - if you run tox -e mypy -- --html-report mypy-html and look at mypy-html/index.html, you will get a list of files needing work:

image

The ones marked in red are places which likely will need more work (and probably don't have type annotations at all yet).

The-Compiler added a commit that referenced this issue Jun 24, 2020
Not done by default with "tox -e mypy" because it disables mypy's caching,
causing its runtime to go from <1s to ~15s:
python/mypy#9041

See #1456
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: style / refactoring Issues related to coding styles or code that should be refactored. priority: 1 - middle Issues which should be done at some point, but aren't that important.
Projects
Extensions
  
Done
Development

No branches or pull requests

2 participants