diff --git a/src/customer_attributes.py b/src/customer_attributes.py index 10929ce..fff9121 100644 --- a/src/customer_attributes.py +++ b/src/customer_attributes.py @@ -1,22 +1,25 @@ +from dataclasses import dataclass, field from typing import ClassVar -from pydantic import BaseModel, model_validator + from src.models import KeypadSize from src.utils import generate_random_nonrepeating_list -class CustomerAttributes(BaseModel): +@dataclass +class CustomerAttributes: attr_vals: list[int] set_vals: list[int] keypad_size: KeypadSize MAX_KEYS: ClassVar[int] = 256 MAX_ATTRS_PER_KEY: ClassVar[int] = 256 - @model_validator(mode='after') - def check_keys_vs_attrs(self) -> 'CustomerAttributes': + def __post_init__(self): + self.check_keys_vs_attrs() + + def check_keys_vs_attrs(self) -> None: if self.keypad_size.is_dispersable: raise ValueError("number of keys must be less than the number of " "attributes per key to be dispersion resistant") - return self @classmethod def create(cls, keypad_size: KeypadSize) -> 'CustomerAttributes': @@ -41,4 +44,4 @@ class CustomerAttributes(BaseModel): def get_set_index(self, set_val: int) -> int: if set_val not in self.set_vals: raise ValueError(f"Set value {set_val} not found in set values") - return self.set_vals.index(set_val) + return self.set_vals.index(set_val) \ No newline at end of file