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 485090cbdf..b2a178b76c 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 d7e5ba39d8..6c7edc37b8 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 3c7ba9c653..3d9e674426 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 4302c9c8d0..a91c86453b 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 e1aeefb731..57f437da76 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 47b7de56b4..595cdf5942 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 7bef23cabe..d79efb3729 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 d9884f3bfc..971318e92d 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 fa4a77e615..43b5ab577c 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 77c37ffb87..ca757bc640 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 37c745165f..a75498c867 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 40018bad58..4c902cf882 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 6639064740..f24580787f 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 d28445bd91..4ad2e2a5f1 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 dfd97cd40d..a34993b212 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 5018c7a6ff..1494159f09 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 77495c274f..2d943cfd16 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 06f9d1a7b5..24ce7caaa5 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 8ca556a882..434f1f6a8c 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 086db4c3db..17c032cc5d 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 e1d3240ef2..6f1692563e 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 b2e68ea695..88489899a4 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 e4c17a7b26..4021447620 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 04e251662b..9ca742d963 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 f9dbef49e4..6c69cbd367 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 6f72e5affc..1e1dd2b052 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 36872f8666..658055408d 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 0fa414f9cc..801cec5a5c 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 cdd895d580..c75e1bb3b6 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 f04f2b02c6..6d024077a2 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 b967a82a48..c77efed49a 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