Browse Source

ref: limit the typing allowlist to specific codes (#51799)

rather than ignoring all errors we can also work on the specific _type_
of errors that are ignored
anthony sottile 1 year ago
parent
commit
6c1a91e023

+ 27 - 1
pyproject.toml

@@ -1577,5 +1577,31 @@ module = [
     "tests.symbolicator.test_payload_full",
     "tests.symbolicator.test_unreal_full",
 ]
-ignore_errors = true
+disable_error_code = [
+    "abstract",
+    "arg-type",
+    "assignment",
+    "attr-defined",
+    "call-arg",
+    "call-overload",
+    "dict-item",
+    "func-returns-value",
+    "has-type",
+    "index",
+    "list-item",
+    "method-assign",
+    "misc",
+    "no-redef",
+    "operator",
+    "override",
+    "return",
+    "return-value",
+    "type-var",
+    "typeddict-item",
+    "typeddict-unknown-key",
+    "union-attr",
+    "unreachable",
+    "valid-type",
+    "var-annotated",
+]
 # end: sentry modules with typing issues

+ 2 - 2
src/sentry/integrations/github/webhook.py

@@ -450,7 +450,7 @@ class GitHubWebhookBase(Endpoint):
 
         return constant_time_compare(expected, signature)
 
-    @method_decorator(csrf_exempt)  # type: ignore
+    @method_decorator(csrf_exempt)
     def dispatch(self, request: Request, *args: Any, **kwargs: Any) -> HttpResponse:
         if request.method != "POST":
             return HttpResponse(status=405)
@@ -523,7 +523,7 @@ class GitHubIntegrationsWebhookEndpoint(GitHubWebhookBase):
         "installation": InstallationEventWebhook,
     }
 
-    @method_decorator(csrf_exempt)  # type: ignore
+    @method_decorator(csrf_exempt)
     def dispatch(self, request: Request, *args: Any, **kwargs: Any) -> HttpResponse:
         if request.method != "POST":
             return HttpResponse(status=405)

+ 1 - 3
src/sentry/search/snuba/executors.py

@@ -250,9 +250,7 @@ class AbstractQueryExecutor(metaclass=ABCMeta):
         for alias in required_aggregations:
             aggregation = self.aggregation_defs[alias]
             if replace_better_priority_aggregation and alias == "better_priority":
-                aggregation = self.aggregation_defs[
-                    "better_priority_issue_platform"  # type:ignore[call-overload]
-                ]
+                aggregation = self.aggregation_defs["better_priority_issue_platform"]
             if callable(aggregation):
                 if aggregate_kwargs:
                     aggregation = aggregation(start, end, aggregate_kwargs.get(alias, {}))

+ 9 - 1
tools/mypy_helpers/make_module_ignores.py

@@ -1,13 +1,17 @@
 from __future__ import annotations
 
+import re
 import shutil
 import subprocess
 import sys
 
+ERROR_RE = re.compile(r".*error:.*\[([^]]+)\]$")
+
 
 def main() -> int:
     shutil.rmtree(".mypy_cache", ignore_errors=True)
 
+    codes = set()
     filenames = set()
     out = subprocess.run(
         (sys.executable, "-m", "tools.mypy_helpers.mypy_without_ignores", *sys.argv[1:]),
@@ -17,6 +21,9 @@ def main() -> int:
         filename, _, _ = line.partition(":")
         if filename.endswith(".py"):
             filenames.add(filename)
+        match = ERROR_RE.match(line)
+        if match is not None:
+            codes.add(match[1])
 
     mods = []
     for filename in sorted(filenames):
@@ -29,12 +36,13 @@ def main() -> int:
             filename = filename[: -len("/__init__")]
         mods.append(filename.replace("/", "."))
     mods_s = "".join(f'    "{mod}",\n' for mod in mods)
+    codes_s = "".join(f'    "{code}",\n' for code in sorted(codes))
     generated = (
         f"# - remove the module from the list and fix the issues!\n"
         f"# - python3 -m tools.mypy_helpers.find_easiest_modules\n"
         f"[[tool.mypy.overrides]]\n"
         f"module = [\n{mods_s}]\n"
-        f"ignore_errors = true\n"
+        f"disable_error_code = [\n{codes_s}]\n"
     )
     with open("pyproject.toml") as f:
         src = f.read()