summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2022-05-19 11:29:49 +0100
committerDavid Robertson <davidr@element.io>2022-05-19 11:29:49 +0100
commit51d9e344124e175409b5c59185f167e0760c3708 (patch)
tree293bfbb964c37d0fa04e6fb5f66f70e336ff635b
parentIt seems what I want is `constr` (diff)
downloadsynapse-51d9e344124e175409b5c59185f167e0760c3708.tar.xz
move TYPE_CHECKING workaround outside
-rw-r--r--synapse/config/oidc2.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/synapse/config/oidc2.py b/synapse/config/oidc2.py

index e89879d1f4..12059f5bef 100644 --- a/synapse/config/oidc2.py +++ b/synapse/config/oidc2.py
@@ -2,6 +2,19 @@ from typing import TYPE_CHECKING, Any, Optional, Tuple from pydantic import BaseModel, StrictBool, StrictStr, constr +# 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 +else: + IDP_ID_TYPE = constr( + strict=True, + min_length=1, + max_length=250, + regex="^[A-Za-z0-9._~-]+$", # noqa: F722 + ) + class OIDCProviderModel(BaseModel): """ @@ -15,17 +28,7 @@ class OIDCProviderModel(BaseModel): # a unique identifier for this identity provider. Used in the 'user_external_ids' # table, as well as the query/path parameter used in the login protocol. # TODO: this is optional in the old-style config, defaulting to "oidc". - # Ugly workaround for https://github.com/samuelcolvin/pydantic/issues/156, see also - # https://github.com/samuelcolvin/pydantic/issues/156#issuecomment-1130883884 - if TYPE_CHECKING: - idp_id: str - else: - idp_id: constr( - strict=True, - min_length=1, - max_length=250, - regex="^[A-Za-z0-9._~-]+$", # noqa: F722 - ) + idp_id: IDP_ID_TYPE # user-facing name for this identity provider. # TODO: this is optional in the old-style config, defaulting to "OIDC".