Skip to content

Instantly share code, notes, and snippets.

@ao5357
Created April 11, 2021 20:02
Show Gist options
  • Save ao5357/7a203be81e0335478b6abb61a5b8a12d to your computer and use it in GitHub Desktop.
Save ao5357/7a203be81e0335478b6abb61a5b8a12d to your computer and use it in GitHub Desktop.
Python dataclass allowing dict initialization
@dataclass
class AttributeCriteria:
attribute_type: LocationAttributeType
display_value: str
operators: List[CriteriaOperator]
choices: List[AttributeCriteriaChoice]
def __post_init__(self):
for idx, operator in enumerate(self.operators):
if isinstance(operator, str):
self.operators[idx] = CriteriaOperator[operator]
for idx, choice in enumerate(self.choices):
if isinstance(choice, dict):
self.choices[idx] = AttributeCriteriaChoice(**choice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment