Add rudimentary mypy type checking#5575
Conversation
asottile
left a comment
There was a problem hiding this comment.
please also add additional_dependencies: [flake8-typing-imports] to the flake8 hook configuration in .pre-commit-config.yaml
Codecov Report
@@ Coverage Diff @@
## features #5575 +/- ##
============================================
+ Coverage 96.08% 96.09% +<.01%
============================================
Files 117 117
Lines 25716 25728 +12
Branches 2494 2494
============================================
+ Hits 24709 24723 +14
+ Misses 702 701 -1
+ Partials 305 304 -1
Continue to review full report at Codecov.
|
|
Thanks @bluetech for working on this! I've changed the title to "WIP" to explicitly state this is not yet prime for merging. 👍 |
|
I updated the PR to address some of @asottile's comments. |
|
Updated again. I've switched to use pre-commit and addresses some of the other comments. Currently some of the tests are failing, but I can't check what causes them exactly ATM - will check later, but I pushed anyway. |
Add a very lax mypy configuration, add it to tox -e linting, and fix/ignore the few errors that come up. The idea is to get it running before diving in too much. This enables: - Progressively adding type annotations and enabling more strict options, which will improve the codebase (IMO). - Annotating the public API in-line, and eventually exposing it to library users who use type checkers (with a py.typed file). Though, none of this is done yet. Refs pytest-dev#3342.
|
Updated - CI looks happy now. I added I also changed the mypy pre-commit to use |
|
@nicoddemus ok with cherry-picking this to master? I'd like to be able to iterate on this there (and not have it regress) |
|
@asottile it doesn't add any extra dependencies to users of the library or changes any public API, so feel free to go ahead! 👍 |
| return self.frame.code.path | ||
|
|
||
| def getlocals(self): | ||
| @property |
There was a problem hiding this comment.
that one is a breaking change of the api
There was a problem hiding this comment.
I don't think Code objects are exposed -- or at least I can't find any cases that they are (?)
| from _pytest.outcomes import TEST_OUTCOME | ||
|
|
||
| if False: # TYPE_CHECKING | ||
| from typing import Type |
There was a problem hiding this comment.
Why is this only imported conditionally, but not the others?
There was a problem hiding this comment.
it is not available in python 3.5.0 / 3.5.1

(This PR is currently an RFC, I will discuss it in issue #3342).
Add a very lax mypy configuration, add it to tox -e linting, and
fix/ignore the few errors that come up. The idea is to get it running
before diving in too much.
This enables:
Progressively adding type annotations and enabling more strict
options, which will improve the codebase (IMO).
Annotating the public API in-line, and eventually exposing it to
library users who use type checkers (with a py.typed file).
Though, none of this is done yet.
Refs #3342.