forked from pantsbuild/pants
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup MyPy config and enforce types for build-support scripts (pantsb…
…uild#7704) ### Problem We would like to use type hints throughout our code base, per pantsbuild#6742. However, we must configure it with sensible defaults to make it easier to use and to provide a consistent interface for developers. We should also enforce as much type safety as we can via our `pre-commit` check. ### Solution * Add new `mypy.ini` file with fairly loose defaults that are good for first time codebases. Eventually, we will want to do things like require all functions to be typed, but for now we loosen our expectations. * Link to the config file in `pants.ini`, along with using the most modern MyPy release which gives us the `strict_equality` check. * Run `mypy.py` over the build-support scripts, which are fully typed. * Acts as a proof of concept for how this will be integrated into CI. ### Result `./pants mypy` is now a bit more useful on our codebase, even though it will still fail because of pre-existing issues. Further, the build-support folder will not have any typing regressions now.
- Loading branch information
1 parent
cebcb32
commit ad20e58
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[mypy] | ||
# Refer to https://mypy.readthedocs.io/en/latest/command_line.html for the definition of each | ||
# of these options. MyPy is frequently updated, so this file should be periodically reviewed | ||
# for any new behavior that we can opt-in to. | ||
# | ||
# In general, we would like to be as strict as possible, but currently keep most checks turned off | ||
# because our codebase has so little type coverage. As we add more types, these options should be | ||
# re-evaluated and made more strict where possible. | ||
|
||
# Optionals | ||
no_implicit_optional = True | ||
|
||
# Untyped. Eventually we should turn on as many of these as possible, but for now we turn them | ||
# off to allow an incremental migration. | ||
check_untyped_defs = False | ||
disallow_untyped_calls = False | ||
disallow_untyped_defs = False | ||
disallow_untyped_decorators = False | ||
disallow_incomplete_defs = False | ||
|
||
# Dynamic typing | ||
disallow_any_unimported = False | ||
disallow_any_expr = False | ||
disallow_any_decorated = False | ||
disallow_any_explicit = False | ||
disallow_any_generics = False | ||
disallow_subclassing_any = False | ||
|
||
# Strictness | ||
strict_equality = False | ||
|
||
# Warnings | ||
warn_unused_ignores = True | ||
warn_no_return = True | ||
warn_return_any = True | ||
warn_redundant_casts = True | ||
|
||
# Error output | ||
show_column_numbers = True | ||
show_traceback = True | ||
|
||
# Imports. See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports. | ||
ignore_missing_imports = True | ||
follow_imports = normal | ||
follow_imports_for_stubs = False | ||
|
||
# Ignore complaints about our dynamic programming | ||
# TODO: write a plugin that teaches MyPy how these work! | ||
# See https://mypy-lang.blogspot.com/2019/03/extending-mypy-with-plugins.html. | ||
always_true = enum,datatype |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters