Coverage for functions \ flipdare \ request \ authentication_result.py: 77%
13 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
1#!/usr/bin/env python
2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved.
3#
4# This file is part of Flipdare's proprietary software and contains
5# confidential and copyrighted material. Unauthorised copying,
6# modification, distribution, or use of this file is strictly
7# prohibited without prior written permission from Flipdare Pty Ltd.
8#
9# This software includes third-party components licensed under MIT,
10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details.
11#
14from dataclasses import dataclass, replace
15from typing import Any, Self
17__all__ = ["AuthenticationResult"]
20@dataclass(frozen=True, slots=True)
21class AuthenticationResult:
22 is_authenticated: bool
23 is_allowed: bool
24 user_id: str | None = None
26 def merge(self, other: "AuthenticationResult") -> Self:
27 """
28 Creates a new result by taking all non-None values from 'other'.
29 Use this when you have a second AuthenticationResult object.
30 """
31 # Convert the other object to a dict of values to override
32 # We use vars() or __dict__ for a shallow copy (best for performance)
33 overrides = {
34 k: v
35 for k, v in vars(other).items()
36 if v is not None or k in ("is_authenticated", "is_allowed")
37 }
38 return replace(self, **overrides)
40 def copy_with(self, **changes: Any) -> Self:
41 # replace() handles copying all existing fields + merging your changes
42 return replace(self, **changes)