From 0ae94c6051d3513e44cbf3705f78cf926586fab6 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 5 Jul 2021 14:36:46 -0700 Subject: [PATCH] mypy: Move configuration to pyproject.toml. Signed-off-by: Anders Kaseorg --- docs/subsystems/dependencies.md | 2 +- docs/testing/mypy.md | 4 ++-- mypy.ini | 40 -------------------------------- pyproject.toml | 41 +++++++++++++++++++++++++++++++++ tools/lint | 2 +- 5 files changed, 45 insertions(+), 44 deletions(-) delete mode 100644 mypy.ini diff --git a/docs/subsystems/dependencies.md b/docs/subsystems/dependencies.md index 672d44f683..8e9da08e7a 100644 --- a/docs/subsystems/dependencies.md +++ b/docs/subsystems/dependencies.md @@ -192,7 +192,7 @@ highlighting. The system is largely managed by the code in * **Mypy type checker**. Because we're using mypy in a strict mode, when you add use of a new Python dependency, you usually need to either adds stubs to the `stubs/` directory for the library, or edit - `mypy.ini` in the root of the Zulip project to configure + `pyproject.toml` in the root of the Zulip project to configure `ignore_missing_imports` for the new library. See [our mypy docs][mypy-docs] for more details. diff --git a/docs/testing/mypy.md b/docs/testing/mypy.md index b056374f53..cf71e26e5f 100644 --- a/docs/testing/mypy.md +++ b/docs/testing/mypy.md @@ -98,14 +98,14 @@ basically the equivalent of C header files defining the types used in these Python APIs. For other third-party modules that we call from Zulip, one either -needs to add an `ignore_missing_imports` entry in `mypy.ini` in the +needs to add an `ignore_missing_imports` entry in `pyproject.toml` in the root of the project, letting `mypy` know that it's third-party code, or add type stubs to the `stubs/` directory, which has type stubs that mypy can use to type-check calls into that third-party module. It's easy to add new stubs! Just read the docs, look at some of existing examples to see how they work, and remember to remove the -`ignore_missing_imports` entry in `mypy.ini` when you add them. +`ignore_missing_imports` entry in `pyproject.toml` when you add them. For any third-party modules that don't have stubs, `mypy` treats everything in the third-party module as an `Any`, which is the right diff --git a/mypy.ini b/mypy.ini deleted file mode 100644 index 35e9144b14..0000000000 --- a/mypy.ini +++ /dev/null @@ -1,40 +0,0 @@ -[mypy] -# Logistics of what code to check and how to handle the data. -scripts_are_modules = True -show_traceback = True -# See https://zulip.readthedocs.io/en/latest/testing/mypy.html#mypy-stubs-for-third-party-modules -# for notes on how we manage mypy stubs. -mypy_path = $MYPY_CONFIG_FILE_DIR/stubs -cache_dir = $MYPY_CONFIG_FILE_DIR/var/mypy-cache - -# These are all the options that would be enabled by mypy --strict, in -# the order listed by the mypy --help documentation of --strict. We -# do not yet enable all of them. -warn_unused_configs = True -disallow_any_generics = True -disallow_subclassing_any = False -disallow_untyped_calls = False -disallow_untyped_defs = True -disallow_incomplete_defs = True -check_untyped_defs = True -disallow_untyped_decorators = False -no_implicit_optional = True -warn_redundant_casts = True -warn_unused_ignores = True -warn_return_any = False -no_implicit_reexport = False -strict_equality = True - -# Display the codes needed for # type: ignore[code] annotations. -show_error_codes = True - -# We use a lot of third-party libraries we don't have stubs for, as -# well as a handful of our own modules that we haven't told mypy how -# to find. Ignore them. (For some details, see: -# `git log -p -S ignore_missing_imports mypy.ini`.) -# -# This doesn't get in the way of using the stubs we *do* have. -ignore_missing_imports = True - -# Warn of unreachable or redundant code. -warn_unreachable = True diff --git a/pyproject.toml b/pyproject.toml index cfea661f79..bcc7729afb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,3 +7,44 @@ src_paths = [".", "tools", "tools/setup/emoji"] known_third_party = "zulip" profile = "black" line_length = 100 + +[tool.mypy] +# Logistics of what code to check and how to handle the data. +scripts_are_modules = true +show_traceback = true +# See https://zulip.readthedocs.io/en/latest/testing/mypy.html#mypy-stubs-for-third-party-modules +# for notes on how we manage mypy stubs. +mypy_path = "$MYPY_CONFIG_FILE_DIR/stubs" +cache_dir = "$MYPY_CONFIG_FILE_DIR/var/mypy-cache" + +# These are all the options that would be enabled by mypy --strict, in +# the order listed by the mypy --help documentation of --strict. We +# do not yet enable all of them. +warn_unused_configs = true +disallow_any_generics = true +disallow_subclassing_any = false +disallow_untyped_calls = false +disallow_untyped_defs = true +disallow_incomplete_defs = true +check_untyped_defs = true +disallow_untyped_decorators = false +no_implicit_optional = true +warn_redundant_casts = true +warn_unused_ignores = true +warn_return_any = false +no_implicit_reexport = false +strict_equality = true + +# Display the codes needed for # type: ignore[code] annotations. +show_error_codes = true + +# We use a lot of third-party libraries we don't have stubs for, as +# well as a handful of our own modules that we haven't told mypy how +# to find. Ignore them. (For some details, see: +# `git log -p -S ignore_missing_imports -- mypy.ini`.) +# +# This doesn't get in the way of using the stubs we *do* have. +ignore_missing_imports = true + +# Warn of unreachable or redundant code. +warn_unreachable = true diff --git a/tools/lint b/tools/lint index a67fb51a9b..bc33f568bf 100755 --- a/tools/lint +++ b/tools/lint @@ -134,7 +134,7 @@ def run() -> None: command, ["py"], pass_targets=False, - description="Static type checker for Python (config: mypy.ini)", + description="Static type checker for Python (config: pyproject.toml)", ) linter_config.external_linter( "tsc",