diff --git a/build-support/githooks/pre-commit b/build-support/githooks/pre-commit index a8c0a5781dd..0ff35481549 100755 --- a/build-support/githooks/pre-commit +++ b/build-support/githooks/pre-commit @@ -58,6 +58,12 @@ if git rev-parse --verify "${MERGE_BASE}" &>/dev/null; then # quite often with a pexrc available. echo "* Checking lint" && ./pants --exclude-target-regexp='testprojects/.*' --changed-parent="${MERGE_BASE}" lint || exit 1 + echo "* Checking types (for build-support)" + # NB: This task requires Python 3, so we must temporarily override any intepreter constraints + # set by ci.sh, specifically it setting constraints to Python 2, because those constraints may + # cause a select-interpreter failure. + PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS="['CPython>=3.6']" ./pants mypy 'build-support::' || exit 1 + if git diff "${MERGE_BASE}" --name-only | grep '\.rs$' > /dev/null; then echo "* Checking formatting of rust files" && ./build-support/bin/check_rust_formatting.sh || exit 1 # Clippy happens on a different Travis CI shard because of separate caching concerns. diff --git a/build-support/mypy/mypy.ini b/build-support/mypy/mypy.ini new file mode 100644 index 00000000000..676a6b88f06 --- /dev/null +++ b/build-support/mypy/mypy.ini @@ -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 diff --git a/pants.ini b/pants.ini index 323f268c40f..b281d6a1f24 100644 --- a/pants.ini +++ b/pants.ini @@ -299,6 +299,10 @@ skip: True [pycheck-context-manager] skip: True +[mypy] +mypy_version: 0.701 +config_file: build-support/mypy/mypy.ini + [scala] version: 2.12