From ce695129c9de82968038c773861f0dfa809a6105 Mon Sep 17 00:00:00 2001 From: Ashley Whetter Date: Thu, 25 Jul 2024 19:40:09 -0700 Subject: [PATCH] Enable stricter type checks that require little to no code change Contributes to #425 --- autoapi/extension.py | 2 +- docs/changes/425.misc.1 | 1 + pyproject.toml | 35 ++++++++++++++++++----------------- 3 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 docs/changes/425.misc.1 diff --git a/autoapi/extension.py b/autoapi/extension.py index 609c09b0..34ef2f16 100644 --- a/autoapi/extension.py +++ b/autoapi/extension.py @@ -40,7 +40,7 @@ "method", "attribute", ] -_VIEWCODE_CACHE: Dict[str, Tuple[str, Dict]] = {} +_VIEWCODE_CACHE: Dict[str, tuple[str, dict[str, tuple[str, int, int]]]] = {} """Caches a module's parse results for use in viewcode.""" diff --git a/docs/changes/425.misc.1 b/docs/changes/425.misc.1 new file mode 100644 index 00000000..792c9be8 --- /dev/null +++ b/docs/changes/425.misc.1 @@ -0,0 +1 @@ +Enable stricter type checks that require little to no code changes \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 9884737b..1b5842da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,24 @@ requires = ["setuptools>=46.4.0"] build-backend = "setuptools.build_meta" +[tool.mypy] +# Start off with these +warn_unused_configs = true +warn_redundant_casts = true +warn_unused_ignores = true + +# Getting these passing should be easy +strict_equality = true + +# These shouldn't be too much additional work, but may be tricky to +# get passing if you use a lot of untyped libraries +disallow_subclassing_any = true +disallow_untyped_decorators = true +disallow_any_generics = true + +# This one isn't too hard to get passing, but return on investment is lower +no_implicit_reexport = true + [[tool.mypy.overrides]] module = "astroid.*" ignore_missing_imports = true @@ -12,32 +30,15 @@ ignore_errors = true [[tool.mypy.overrides]] module = "autoapi._astroid_utils" -# Start off with these -# warn_unused_configs = true <-- can only be set globally -# warn_redundant_casts = true <-- can only be set globally -warn_unused_ignores = true - -# Getting these passing should be easy -strict_equality = true -strict_concatenate = true # Strongly recommend enabling this one as soon as you can check_untyped_defs = true -# These shouldn't be too much additional work, but may be tricky to -# get passing if you use a lot of untyped libraries -disallow_subclassing_any = true -disallow_untyped_decorators = true -disallow_any_generics = true - # These next few are various gradations of forcing use of type annotations disallow_untyped_calls = true disallow_incomplete_defs = true disallow_untyped_defs = true -# This one isn't too hard to get passing, but return on investment is lower -no_implicit_reexport = true - # This one can be tricky to get passing if you use a lot of untyped libraries # Ignore until astroid is typed (https://github.com/pylint-dev/astroid/issues/2060) warn_return_any = false