summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2022-05-22 16:21:10 +0100
committerDavid Robertson <davidr@element.io>2022-05-22 16:26:02 +0100
commit4c66f552795ec67d853ddd904a7898b389f42880 (patch)
treeed7f243fd27049517ad3847813932570f8198a5f
parentUse pydantic plugin first (diff)
downloadsynapse-4c66f552795ec67d853ddd904a7898b389f42880.tar.xz
A batch of linting
-rw-r--r--synapse/config/oidc2.py19
-rw-r--r--tests/config/test_oidc2.py13
2 files changed, 16 insertions, 16 deletions
diff --git a/synapse/config/oidc2.py b/synapse/config/oidc2.py
index e48b635e09..4772e23183 100644
--- a/synapse/config/oidc2.py
+++ b/synapse/config/oidc2.py
@@ -1,15 +1,13 @@
 from enum import Enum
-
-from typing import TYPE_CHECKING, Any, Optional, Tuple, Type
+from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple
 
 from pydantic import BaseModel, StrictBool, StrictStr, constr, validator
-
-# Ugly workaround for https://github.com/samuelcolvin/pydantic/issues/156. Mypy doesn't
-# consider expressions like `constr(...)` to be valid types.
 from pydantic.fields import ModelField
 
 from synapse.util.stringutils import parse_and_validate_mxc_uri
 
+# Ugly workaround for https://github.com/samuelcolvin/pydantic/issues/156. Mypy doesn't
+# consider expressions like `constr(...)` to be valid types.
 if TYPE_CHECKING:
     IDP_ID_TYPE = str
     IDP_BRAND_TYPE = str
@@ -27,6 +25,7 @@ else:
         regex="^[a-z][a-z0-9_.-]*$",  # noqa: F722
     )
 
+
 # the following list of enum members is the same as the keys of
 # authlib.oauth2.auth.ClientAuth.DEFAULT_AUTH_METHODS. We inline it
 # to avoid importing authlib here.
@@ -60,7 +59,7 @@ class OIDCProviderModel(BaseModel):
     idp_id: IDP_ID_TYPE
 
     @validator("idp_id")
-    def ensure_idp_id_prefix(cls: Type[BaseModel], idp_id: str) -> str:
+    def ensure_idp_id_prefix(cls, idp_id: str) -> str:
         """Prefix the given IDP with a prefix specific to the SSO mechanism, to avoid
         clashes with other mechs (such as SAML, CAS).
 
@@ -80,9 +79,9 @@ class OIDCProviderModel(BaseModel):
     idp_icon: Optional[StrictStr]
 
     @validator("idp_icon")
-    def idp_icon_is_an_mxc_url(cls: Type["OIDCProviderModel"], value: str) -> str:
-        parse_and_validate_mxc_uri(value)
-        return value
+    def idp_icon_is_an_mxc_url(cls, idp_icon: str) -> str:
+        parse_and_validate_mxc_uri(idp_icon)
+        return idp_icon
 
     # Optional brand identifier for this IdP.
     idp_brand: Optional[StrictStr]
@@ -124,7 +123,7 @@ class OIDCProviderModel(BaseModel):
     # Using validate=True ensures we run the validator even in that situation.
     @validator("authorization_endpoint", "token_endpoint", always=True)
     def endpoints_required_if_discovery_disabled(
-        cls: Type["OIDCProviderModel"],
+        cls,
         endpoint_url: Optional[str],
         values: Mapping[str, Any],
         field: ModelField,
diff --git a/tests/config/test_oidc2.py b/tests/config/test_oidc2.py
index f12e7a5b2b..e7927bbed9 100644
--- a/tests/config/test_oidc2.py
+++ b/tests/config/test_oidc2.py
@@ -3,13 +3,13 @@ from typing import Any, Dict
 from unittest import TestCase
 
 import yaml
-from pydantic import ValidationError
 from parameterized import parameterized
+from pydantic import ValidationError
 
 from synapse.config.oidc2 import (
-    OIDCProviderModel,
     ClientAuthMethods,
     LegacyOIDCProviderModel,
+    OIDCProviderModel,
 )
 
 SAMPLE_CONFIG = yaml.safe_load(
@@ -62,9 +62,9 @@ class PydanticOIDCTestCase(TestCase):
             OIDCProviderModel.parse_obj(self.config)
 
         # Enforce that idp_id is a string.
-        for bad_vlaue in 123, None, ["a"], {"a": "b"}:
-            with self.assertRaises(ValidationError) as e:
-                self.config["idp_id"] = bad_vlaue
+        for bad_value in 123, None, ["a"], {"a": "b"}:
+            with self.assertRaises(ValidationError):
+                self.config["idp_id"] = bad_value
                 OIDCProviderModel.parse_obj(self.config)
 
         # Enforce a length between 1 and 250.
@@ -81,7 +81,7 @@ class PydanticOIDCTestCase(TestCase):
             OIDCProviderModel.parse_obj(self.config)
 
         # What happens with a really long string of prohibited characters?
-        with self.assertRaises(ValidationError) as e:
+        with self.assertRaises(ValidationError):
             self.config["idp_id"] = "$" * 500
             OIDCProviderModel.parse_obj(self.config)
 
@@ -153,6 +153,7 @@ class PydanticOIDCTestCase(TestCase):
 
     def test_idp_icon(self) -> None:
         # Test that bad types are rejected, even with our validator in place
+        bad_value: object
         for bad_value in None, {}, [], 123, 45.6:
             with self.assertRaises(ValidationError):
                 self.config["idp_icon"] = bad_value