qutebrowser / qutebrowser

A keyboard-driven, vim-like browser based on Python and Qt.
https://www.qutebrowser.org/
GNU General Public License v3.0
9.6k stars 1.01k forks source link

PEP484 type hints / mypy #1456

Open The-Compiler opened 8 years ago

The-Compiler commented 8 years ago

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.


rcorre commented 8 years ago

Is that PEP484 link really laggy for you when scrolling? Also, your text above is a pretty good repro of #1182 Issues within issues...

The-Compiler commented 8 years ago

It's a bit laggy, but not very bad - blame QtWebEngine for that one :wink:

The-Compiler commented 8 years ago

This is was blocked by #637.

The-Compiler commented 7 years ago

https://github.com/python/typing/issues/310#issuecomment-293340873 looks useful too

The-Compiler commented 6 years ago

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

The-Compiler commented 6 years ago

MonkeyType seems awesome!

The-Compiler commented 6 years ago

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 commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

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

See https://github.com/pytest-dev/pytest/pull/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 commented 4 years ago

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).