From 6000a33a8ebd762b696164a7d472af5d23de8db2 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 16 Aug 2022 13:23:22 +0200 Subject: [PATCH] *: fix type annotations for serializer model Signed-off-by: Jens Langhammer --- authentik/core/models.py | 6 +++--- authentik/flows/models.py | 4 ++-- authentik/lib/models.py | 2 +- authentik/policies/dummy/models.py | 2 +- authentik/policies/event_matcher/models.py | 2 +- authentik/policies/expiry/models.py | 2 +- authentik/policies/expression/models.py | 2 +- authentik/policies/hibp/models.py | 2 +- authentik/policies/models.py | 2 +- authentik/policies/password/models.py | 2 +- authentik/policies/reputation/models.py | 4 ++-- authentik/sources/plex/models.py | 2 +- authentik/stages/authenticator_duo/models.py | 2 +- authentik/stages/authenticator_sms/models.py | 4 ++-- authentik/stages/authenticator_static/models.py | 2 +- authentik/stages/authenticator_totp/models.py | 2 +- authentik/stages/authenticator_validate/models.py | 2 +- authentik/stages/authenticator_webauthn/models.py | 2 +- authentik/stages/captcha/models.py | 2 +- authentik/stages/consent/models.py | 2 +- authentik/stages/deny/models.py | 2 +- authentik/stages/dummy/models.py | 2 +- authentik/stages/email/models.py | 2 +- authentik/stages/identification/models.py | 2 +- authentik/stages/invitation/models.py | 2 +- authentik/stages/password/models.py | 2 +- authentik/stages/prompt/models.py | 6 +++--- authentik/stages/user_delete/models.py | 2 +- authentik/stages/user_login/models.py | 2 +- authentik/stages/user_logout/models.py | 2 +- authentik/stages/user_write/models.py | 2 +- 31 files changed, 38 insertions(+), 38 deletions(-) diff --git a/authentik/core/models.py b/authentik/core/models.py index 485090cbd..b2a178b76 100644 --- a/authentik/core/models.py +++ b/authentik/core/models.py @@ -20,7 +20,7 @@ from django.utils.timezone import now from django.utils.translation import gettext_lazy as _ from guardian.mixins import GuardianUserMixin from model_utils.managers import InheritanceManager -from rest_framework.serializers import BaseSerializer, Serializer +from rest_framework.serializers import Serializer from structlog.stdlib import get_logger from authentik.blueprints.models import ManagedModel @@ -482,7 +482,7 @@ class UserSourceConnection(SerializerModel, CreatedUpdatedModel): objects = InheritanceManager() @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[Serializer]: """Get serializer for this model""" raise NotImplementedError @@ -553,7 +553,7 @@ class Token(SerializerModel, ManagedModel, ExpiringModel): description = models.TextField(default="", blank=True) @property - def serializer(self) -> Serializer: + def serializer(self) -> type[Serializer]: from authentik.core.api.tokens import TokenSerializer return TokenSerializer diff --git a/authentik/flows/models.py b/authentik/flows/models.py index d7e5ba39d..6c7edc37b 100644 --- a/authentik/flows/models.py +++ b/authentik/flows/models.py @@ -165,7 +165,7 @@ class Flow(SerializerModel, PolicyBindingModel): stages = models.ManyToManyField(Stage, through="FlowStageBinding", blank=True) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.flows.api.flows import FlowSerializer return FlowSerializer @@ -225,7 +225,7 @@ class FlowStageBinding(SerializerModel, PolicyBindingModel): objects = InheritanceManager() @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.flows.api.bindings import FlowStageBindingSerializer return FlowStageBindingSerializer diff --git a/authentik/lib/models.py b/authentik/lib/models.py index 3c7ba9c65..3d9e67442 100644 --- a/authentik/lib/models.py +++ b/authentik/lib/models.py @@ -12,7 +12,7 @@ class SerializerModel(models.Model): """Base Abstract Model which has a serializer""" @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: """Get serializer for this model""" raise NotImplementedError diff --git a/authentik/policies/dummy/models.py b/authentik/policies/dummy/models.py index 4302c9c8d..a91c86453 100644 --- a/authentik/policies/dummy/models.py +++ b/authentik/policies/dummy/models.py @@ -24,7 +24,7 @@ class DummyPolicy(Policy): wait_max = models.IntegerField(default=30) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.policies.dummy.api import DummyPolicySerializer return DummyPolicySerializer diff --git a/authentik/policies/event_matcher/models.py b/authentik/policies/event_matcher/models.py index e1aeefb73..57f437da7 100644 --- a/authentik/policies/event_matcher/models.py +++ b/authentik/policies/event_matcher/models.py @@ -54,7 +54,7 @@ class EventMatcherPolicy(Policy): ) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.policies.event_matcher.api import EventMatcherPolicySerializer return EventMatcherPolicySerializer diff --git a/authentik/policies/expiry/models.py b/authentik/policies/expiry/models.py index 47b7de56b..595cdf594 100644 --- a/authentik/policies/expiry/models.py +++ b/authentik/policies/expiry/models.py @@ -21,7 +21,7 @@ class PasswordExpiryPolicy(Policy): days = models.IntegerField() @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.policies.expiry.api import PasswordExpiryPolicySerializer return PasswordExpiryPolicySerializer diff --git a/authentik/policies/expression/models.py b/authentik/policies/expression/models.py index 7bef23cab..d79efb372 100644 --- a/authentik/policies/expression/models.py +++ b/authentik/policies/expression/models.py @@ -14,7 +14,7 @@ class ExpressionPolicy(Policy): expression = models.TextField() @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.policies.expression.api import ExpressionPolicySerializer return ExpressionPolicySerializer diff --git a/authentik/policies/hibp/models.py b/authentik/policies/hibp/models.py index d9884f3bf..971318e92 100644 --- a/authentik/policies/hibp/models.py +++ b/authentik/policies/hibp/models.py @@ -26,7 +26,7 @@ class HaveIBeenPwendPolicy(Policy): allowed_count = models.IntegerField(default=0) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.policies.hibp.api import HaveIBeenPwendPolicySerializer return HaveIBeenPwendPolicySerializer diff --git a/authentik/policies/models.py b/authentik/policies/models.py index fa4a77e61..43b5ab577 100644 --- a/authentik/policies/models.py +++ b/authentik/policies/models.py @@ -102,7 +102,7 @@ class PolicyBinding(SerializerModel): return PolicyResult(False) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.policies.api.bindings import PolicyBindingSerializer return PolicyBindingSerializer diff --git a/authentik/policies/password/models.py b/authentik/policies/password/models.py index 77c37ffb8..ca757bc64 100644 --- a/authentik/policies/password/models.py +++ b/authentik/policies/password/models.py @@ -33,7 +33,7 @@ class PasswordPolicy(Policy): error_message = models.TextField() @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.policies.password.api import PasswordPolicySerializer return PasswordPolicySerializer diff --git a/authentik/policies/reputation/models.py b/authentik/policies/reputation/models.py index 37c745165..a75498c86 100644 --- a/authentik/policies/reputation/models.py +++ b/authentik/policies/reputation/models.py @@ -25,7 +25,7 @@ class ReputationPolicy(Policy): threshold = models.IntegerField(default=-5) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.policies.reputation.api import ReputationPolicySerializer return ReputationPolicySerializer @@ -73,7 +73,7 @@ class Reputation(SerializerModel): updated = models.DateTimeField(auto_now_add=True) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.policies.reputation.api import ReputationSerializer return ReputationSerializer diff --git a/authentik/sources/plex/models.py b/authentik/sources/plex/models.py index 40018bad5..4c902cf88 100644 --- a/authentik/sources/plex/models.py +++ b/authentik/sources/plex/models.py @@ -58,7 +58,7 @@ class PlexSource(Source): return "ak-source-plex-form" @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.sources.plex.api.source import PlexSourceSerializer return PlexSourceSerializer diff --git a/authentik/stages/authenticator_duo/models.py b/authentik/stages/authenticator_duo/models.py index 663906474..f24580787 100644 --- a/authentik/stages/authenticator_duo/models.py +++ b/authentik/stages/authenticator_duo/models.py @@ -23,7 +23,7 @@ class AuthenticatorDuoStage(ConfigurableStage, Stage): api_hostname = models.TextField() @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.authenticator_duo.api import AuthenticatorDuoStageSerializer return AuthenticatorDuoStageSerializer diff --git a/authentik/stages/authenticator_sms/models.py b/authentik/stages/authenticator_sms/models.py index d28445bd9..4ad2e2a5f 100644 --- a/authentik/stages/authenticator_sms/models.py +++ b/authentik/stages/authenticator_sms/models.py @@ -127,7 +127,7 @@ class AuthenticatorSMSStage(ConfigurableStage, Stage): raise @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.authenticator_sms.api import AuthenticatorSMSStageSerializer return AuthenticatorSMSStageSerializer @@ -186,7 +186,7 @@ class SMSDevice(SerializerModel, SideChannelDevice): return self.phone_number.startswith("hash:") @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.authenticator_sms.api import SMSDeviceSerializer return SMSDeviceSerializer diff --git a/authentik/stages/authenticator_static/models.py b/authentik/stages/authenticator_static/models.py index dfd97cd40..a34993b21 100644 --- a/authentik/stages/authenticator_static/models.py +++ b/authentik/stages/authenticator_static/models.py @@ -16,7 +16,7 @@ class AuthenticatorStaticStage(ConfigurableStage, Stage): token_count = models.IntegerField(default=6) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.authenticator_static.api import AuthenticatorStaticStageSerializer return AuthenticatorStaticStageSerializer diff --git a/authentik/stages/authenticator_totp/models.py b/authentik/stages/authenticator_totp/models.py index 5018c7a6f..1494159f0 100644 --- a/authentik/stages/authenticator_totp/models.py +++ b/authentik/stages/authenticator_totp/models.py @@ -23,7 +23,7 @@ class AuthenticatorTOTPStage(ConfigurableStage, Stage): digits = models.IntegerField(choices=TOTPDigits.choices) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.authenticator_totp.api import AuthenticatorTOTPStageSerializer return AuthenticatorTOTPStageSerializer diff --git a/authentik/stages/authenticator_validate/models.py b/authentik/stages/authenticator_validate/models.py index 77495c274..2d943cfd1 100644 --- a/authentik/stages/authenticator_validate/models.py +++ b/authentik/stages/authenticator_validate/models.py @@ -70,7 +70,7 @@ class AuthenticatorValidateStage(Stage): ) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.authenticator_validate.api import AuthenticatorValidateStageSerializer return AuthenticatorValidateStageSerializer diff --git a/authentik/stages/authenticator_webauthn/models.py b/authentik/stages/authenticator_webauthn/models.py index 06f9d1a7b..24ce7caaa 100644 --- a/authentik/stages/authenticator_webauthn/models.py +++ b/authentik/stages/authenticator_webauthn/models.py @@ -82,7 +82,7 @@ class AuthenticateWebAuthnStage(ConfigurableStage, Stage): ) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.authenticator_webauthn.api import AuthenticateWebAuthnStageSerializer return AuthenticateWebAuthnStageSerializer diff --git a/authentik/stages/captcha/models.py b/authentik/stages/captcha/models.py index 8ca556a88..434f1f6a8 100644 --- a/authentik/stages/captcha/models.py +++ b/authentik/stages/captcha/models.py @@ -19,7 +19,7 @@ class CaptchaStage(Stage): ) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.captcha.api import CaptchaStageSerializer return CaptchaStageSerializer diff --git a/authentik/stages/consent/models.py b/authentik/stages/consent/models.py index 086db4c3d..17c032cc5 100644 --- a/authentik/stages/consent/models.py +++ b/authentik/stages/consent/models.py @@ -31,7 +31,7 @@ class ConsentStage(Stage): ) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.consent.api import ConsentStageSerializer return ConsentStageSerializer diff --git a/authentik/stages/deny/models.py b/authentik/stages/deny/models.py index e1d3240ef..6f1692563 100644 --- a/authentik/stages/deny/models.py +++ b/authentik/stages/deny/models.py @@ -11,7 +11,7 @@ class DenyStage(Stage): """Cancells the current flow.""" @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.deny.api import DenyStageSerializer return DenyStageSerializer diff --git a/authentik/stages/dummy/models.py b/authentik/stages/dummy/models.py index b2e68ea69..88489899a 100644 --- a/authentik/stages/dummy/models.py +++ b/authentik/stages/dummy/models.py @@ -13,7 +13,7 @@ class DummyStage(Stage): __debug_only__ = True @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.dummy.api import DummyStageSerializer return DummyStageSerializer diff --git a/authentik/stages/email/models.py b/authentik/stages/email/models.py index e4c17a7b2..402144762 100644 --- a/authentik/stages/email/models.py +++ b/authentik/stages/email/models.py @@ -82,7 +82,7 @@ class EmailStage(Stage): template = models.TextField(default=EmailTemplates.PASSWORD_RESET) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.email.api import EmailStageSerializer return EmailStageSerializer diff --git a/authentik/stages/identification/models.py b/authentik/stages/identification/models.py index 04e251662..9ca742d96 100644 --- a/authentik/stages/identification/models.py +++ b/authentik/stages/identification/models.py @@ -92,7 +92,7 @@ class IdentificationStage(Stage): show_source_labels = models.BooleanField(default=False) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.identification.api import IdentificationStageSerializer return IdentificationStageSerializer diff --git a/authentik/stages/invitation/models.py b/authentik/stages/invitation/models.py index f9dbef49e..6c69cbd36 100644 --- a/authentik/stages/invitation/models.py +++ b/authentik/stages/invitation/models.py @@ -27,7 +27,7 @@ class InvitationStage(Stage): ) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.invitation.api import InvitationStageSerializer return InvitationStageSerializer diff --git a/authentik/stages/password/models.py b/authentik/stages/password/models.py index 6f72e5aff..1e1dd2b05 100644 --- a/authentik/stages/password/models.py +++ b/authentik/stages/password/models.py @@ -48,7 +48,7 @@ class PasswordStage(ConfigurableStage, Stage): ) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.password.api import PasswordStageSerializer return PasswordStageSerializer diff --git a/authentik/stages/prompt/models.py b/authentik/stages/prompt/models.py index 36872f866..658055408 100644 --- a/authentik/stages/prompt/models.py +++ b/authentik/stages/prompt/models.py @@ -1,5 +1,5 @@ """prompt models""" -from typing import Any, Optional +from typing import Any, Optional, Type from urllib.parse import urlparse, urlunparse from uuid import uuid4 @@ -111,7 +111,7 @@ class Prompt(SerializerModel): placeholder_expression = models.BooleanField(default=False) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> Type[BaseSerializer]: from authentik.stages.prompt.api import PromptSerializer return PromptSerializer @@ -207,7 +207,7 @@ class PromptStage(Stage): validation_policies = models.ManyToManyField(Policy, blank=True) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.prompt.api import PromptStageSerializer return PromptStageSerializer diff --git a/authentik/stages/user_delete/models.py b/authentik/stages/user_delete/models.py index 0fa414f9c..801cec5a5 100644 --- a/authentik/stages/user_delete/models.py +++ b/authentik/stages/user_delete/models.py @@ -12,7 +12,7 @@ class UserDeleteStage(Stage): Use with caution.""" @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.user_delete.api import UserDeleteStageSerializer return UserDeleteStageSerializer diff --git a/authentik/stages/user_login/models.py b/authentik/stages/user_login/models.py index cdd895d58..c75e1bb3b 100644 --- a/authentik/stages/user_login/models.py +++ b/authentik/stages/user_login/models.py @@ -23,7 +23,7 @@ class UserLoginStage(Stage): ) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.user_login.api import UserLoginStageSerializer return UserLoginStageSerializer diff --git a/authentik/stages/user_logout/models.py b/authentik/stages/user_logout/models.py index f04f2b02c..6d024077a 100644 --- a/authentik/stages/user_logout/models.py +++ b/authentik/stages/user_logout/models.py @@ -11,7 +11,7 @@ class UserLogoutStage(Stage): """Resets the users current session.""" @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.user_logout.api import UserLogoutStageSerializer return UserLogoutStageSerializer diff --git a/authentik/stages/user_write/models.py b/authentik/stages/user_write/models.py index b967a82a4..c77efed49 100644 --- a/authentik/stages/user_write/models.py +++ b/authentik/stages/user_write/models.py @@ -32,7 +32,7 @@ class UserWriteStage(Stage): ) @property - def serializer(self) -> BaseSerializer: + def serializer(self) -> type[BaseSerializer]: from authentik.stages.user_write.api import UserWriteStageSerializer return UserWriteStageSerializer