remove pydantic from customer_attributes.py
This commit is contained in:
@@ -1,22 +1,25 @@
|
|||||||
|
from dataclasses import dataclass, field
|
||||||
from typing import ClassVar
|
from typing import ClassVar
|
||||||
from pydantic import BaseModel, model_validator
|
|
||||||
from src.models import KeypadSize
|
from src.models import KeypadSize
|
||||||
from src.utils import generate_random_nonrepeating_list
|
from src.utils import generate_random_nonrepeating_list
|
||||||
|
|
||||||
|
|
||||||
class CustomerAttributes(BaseModel):
|
@dataclass
|
||||||
|
class CustomerAttributes:
|
||||||
attr_vals: list[int]
|
attr_vals: list[int]
|
||||||
set_vals: list[int]
|
set_vals: list[int]
|
||||||
keypad_size: KeypadSize
|
keypad_size: KeypadSize
|
||||||
MAX_KEYS: ClassVar[int] = 256
|
MAX_KEYS: ClassVar[int] = 256
|
||||||
MAX_ATTRS_PER_KEY: ClassVar[int] = 256
|
MAX_ATTRS_PER_KEY: ClassVar[int] = 256
|
||||||
|
|
||||||
@model_validator(mode='after')
|
def __post_init__(self):
|
||||||
def check_keys_vs_attrs(self) -> 'CustomerAttributes':
|
self.check_keys_vs_attrs()
|
||||||
|
|
||||||
|
def check_keys_vs_attrs(self) -> None:
|
||||||
if self.keypad_size.is_dispersable:
|
if self.keypad_size.is_dispersable:
|
||||||
raise ValueError("number of keys must be less than the number of "
|
raise ValueError("number of keys must be less than the number of "
|
||||||
"attributes per key to be dispersion resistant")
|
"attributes per key to be dispersion resistant")
|
||||||
return self
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, keypad_size: KeypadSize) -> 'CustomerAttributes':
|
def create(cls, keypad_size: KeypadSize) -> 'CustomerAttributes':
|
||||||
@@ -41,4 +44,4 @@ class CustomerAttributes(BaseModel):
|
|||||||
def get_set_index(self, set_val: int) -> int:
|
def get_set_index(self, set_val: int) -> int:
|
||||||
if set_val not in self.set_vals:
|
if set_val not in self.set_vals:
|
||||||
raise ValueError(f"Set value {set_val} not found in set values")
|
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)
|
||||||
Reference in New Issue
Block a user