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

Setup MyPy config and enforce types for build-support scripts #7704

Merged
merged 11 commits into from May 14, 2019
6 changes: 6 additions & 0 deletions build-support/githooks/pre-commit
Expand Up @@ -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.
Expand Down
50 changes: 50 additions & 0 deletions 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
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved
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
4 changes: 4 additions & 0 deletions pants.ini
Expand Up @@ -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

Expand Down