*: use dataclass slots wherever applicable (#6005)

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L 2023-06-19 18:31:07 +02:00 committed by GitHub
parent 0bebcc4eff
commit a5db60129d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 16 additions and 17 deletions

View File

@ -8,7 +8,7 @@ from authentik.core.api.utils import PassiveSerializer
from authentik.flows.challenge import Challenge from authentik.flows.challenge import Challenge
@dataclass @dataclass(slots=True)
class UILoginButton: class UILoginButton:
"""Dataclass for Source's ui_login_button""" """Dataclass for Source's ui_login_button"""

View File

@ -30,7 +30,7 @@ class StageMarker:
return binding return binding
@dataclass @dataclass(slots=True)
class ReevaluateMarker(StageMarker): class ReevaluateMarker(StageMarker):
"""Reevaluate Marker, forces stage's policies to be evaluated again.""" """Reevaluate Marker, forces stage's policies to be evaluated again."""

View File

@ -45,7 +45,7 @@ def cache_key(flow: Flow, user: Optional[User] = None) -> str:
return prefix return prefix
@dataclass @dataclass(slots=True)
class FlowPlan: class FlowPlan:
"""This data-class is the output of a FlowPlanner. It holds a flat list """This data-class is the output of a FlowPlanner. It holds a flat list
of all Stages that should be run.""" of all Stages that should be run."""

View File

@ -28,7 +28,7 @@ class WebsocketMessageInstruction(IntEnum):
TRIGGER_UPDATE = 2 TRIGGER_UPDATE = 2
@dataclass @dataclass(slots=True)
class WebsocketMessage: class WebsocketMessage:
"""Complete Websocket Message that is being sent""" """Complete Websocket Message that is being sent"""

View File

@ -19,7 +19,7 @@ LOGGER = get_logger()
CACHE_PREFIX = "goauthentik.io/policies/" CACHE_PREFIX = "goauthentik.io/policies/"
@dataclass @dataclass(slots=True)
class PolicyRequest: class PolicyRequest:
"""Data-class to hold policy request data""" """Data-class to hold policy request data"""
@ -27,14 +27,14 @@ class PolicyRequest:
http_request: Optional[HttpRequest] http_request: Optional[HttpRequest]
obj: Optional[Model] obj: Optional[Model]
context: dict[str, Any] context: dict[str, Any]
debug: bool = False debug: bool
def __init__(self, user: User): def __init__(self, user: User):
super().__init__()
self.user = user self.user = user
self.http_request = None self.http_request = None
self.obj = None self.obj = None
self.context = {} self.context = {}
self.debug = False
def set_http_request(self, request: HttpRequest): # pragma: no cover def set_http_request(self, request: HttpRequest): # pragma: no cover
"""Load data from HTTP request, including geoip when enabled""" """Load data from HTTP request, including geoip when enabled"""
@ -67,7 +67,7 @@ class PolicyRequest:
return text + ">" return text + ">"
@dataclass @dataclass(slots=True)
class PolicyResult: class PolicyResult:
"""Result from evaluating a policy.""" """Result from evaluating a policy."""
@ -81,7 +81,6 @@ class PolicyResult:
log_messages: Optional[list[dict]] log_messages: Optional[list[dict]]
def __init__(self, passing: bool, *messages: str): def __init__(self, passing: bool, *messages: str):
super().__init__()
self.passing = passing self.passing = passing
self.messages = messages self.messages = messages
self.raw_result = None self.raw_result = None

View File

@ -41,7 +41,7 @@ class SubModes(models.TextChoices):
) )
@dataclass @dataclass(slots=True)
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes
class IDToken: class IDToken:
"""The primary extension that OpenID Connect makes to OAuth 2.0 to enable End-Users to be """The primary extension that OpenID Connect makes to OAuth 2.0 to enable End-Users to be

View File

@ -74,7 +74,7 @@ SESSION_KEY_LAST_LOGIN_UID = "authentik/providers/oauth2/last_login_uid"
ALLOWED_PROMPT_PARAMS = {PROMPT_NONE, PROMPT_CONSENT, PROMPT_LOGIN} ALLOWED_PROMPT_PARAMS = {PROMPT_NONE, PROMPT_CONSENT, PROMPT_LOGIN}
@dataclass @dataclass(slots=True)
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes
class OAuthAuthorizationParams: class OAuthAuthorizationParams:
"""Parameters required to authorize an OAuth Client""" """Parameters required to authorize an OAuth Client"""

View File

@ -14,7 +14,7 @@ from authentik.providers.oauth2.utils import TokenResponse, authenticate_provide
LOGGER = get_logger() LOGGER = get_logger()
@dataclass @dataclass(slots=True)
class TokenIntrospectionParams: class TokenIntrospectionParams:
"""Parameters for Token Introspection""" """Parameters for Token Introspection"""

View File

@ -58,7 +58,7 @@ from authentik.stages.password.stage import PLAN_CONTEXT_METHOD, PLAN_CONTEXT_ME
LOGGER = get_logger() LOGGER = get_logger()
@dataclass @dataclass(slots=True)
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes
class TokenParams: class TokenParams:
"""Token params""" """Token params"""

View File

@ -14,7 +14,7 @@ from authentik.providers.oauth2.utils import TokenResponse, authenticate_provide
LOGGER = get_logger() LOGGER = get_logger()
@dataclass @dataclass(slots=True)
class TokenRevocationParams: class TokenRevocationParams:
"""Parameters for Token Revocation""" """Parameters for Token Revocation"""

View File

@ -31,7 +31,7 @@ ERROR_SIGNATURE_REQUIRED_BUT_ABSENT = (
ERROR_FAILED_TO_VERIFY = "Failed to verify signature" ERROR_FAILED_TO_VERIFY = "Failed to verify signature"
@dataclass @dataclass(slots=True)
class AuthNRequest: class AuthNRequest:
"""AuthNRequest Dataclass""" """AuthNRequest Dataclass"""

View File

@ -12,7 +12,7 @@ from authentik.providers.saml.utils.encoding import decode_base64_and_inflate
from authentik.sources.saml.processors.constants import NS_SAML_PROTOCOL from authentik.sources.saml.processors.constants import NS_SAML_PROTOCOL
@dataclass @dataclass(slots=True)
class LogoutRequest: class LogoutRequest:
"""Logout Request""" """Logout Request"""

View File

@ -35,7 +35,7 @@ def format_pem_certificate(unformatted_cert: str) -> str:
return "\n".join(lines) return "\n".join(lines)
@dataclass @dataclass(slots=True)
class ServiceProviderMetadata: class ServiceProviderMetadata:
"""SP Metadata Dataclass""" """SP Metadata Dataclass"""