Browse Source

ref: add `superuser: Any` to request (#57357)

<!-- Describe your PR here. -->
anthony sottile 1 year ago
parent
commit
9fa48b52c1
3 changed files with 4 additions and 1 deletions
  1. 0 1
      pyproject.toml
  2. 1 0
      tests/tools/mypy_helpers/test_plugin.py
  3. 3 0
      tools/mypy_helpers/plugin.py

+ 0 - 1
pyproject.toml

@@ -809,7 +809,6 @@ module = [
     "tests.sentry.api.endpoints.test_organization_metrics",
     "tests.sentry.api.helpers.test_group_index",
     "tests.sentry.api.serializers.test_project",
-    "tests.sentry.api.serializers.test_team",
     "tests.sentry.api.test_authentication",
     "tests.sentry.api.test_base",
     "tests.sentry.api.test_event_search",

+ 1 - 0
tests/tools/mypy_helpers/test_plugin.py

@@ -232,6 +232,7 @@ Found 4 errors in 1 file (checked 1 source file)
         pytest.param("csp_nonce", id="csp_nonce from csp.middleware"),
         pytest.param("is_sudo", id="is_sudo from sudo.middleware"),
         pytest.param("subdomain", id="subdomain from sentry.middleware.subdomain"),
+        pytest.param("superuser", id="superuser from sentry.middleware.superuser"),
     ),
 )
 def test_added_http_request_attribute(attr: str) -> None:

+ 3 - 0
tools/mypy_helpers/plugin.py

@@ -94,6 +94,9 @@ def _adjust_http_request_members(ctx: ClassDefContext) -> None:
         # added by sentry.middleware.subdomain
         subdomain_tp = UnionType([NoneType(), ctx.api.named_type("builtins.str")])
         add_attribute_to_class(ctx.api, ctx.cls, "subdomain", subdomain_tp)
+        # added by sentry.middleware.superuser
+        # TODO: figure out how to get the real types here
+        add_attribute_to_class(ctx.api, ctx.cls, "superuser", AnyType(TypeOfAny.explicit))
 
 
 class SentryMypyPlugin(Plugin):