|
|
@ -1,13 +1,15 @@ |
|
|
|
# import attr |
|
|
|
# import attr |
|
|
|
from dataclasses import dataclass, field |
|
|
|
from dataclasses import dataclass, field |
|
|
|
from typing import Any, List |
|
|
|
|
|
|
|
from enum import auto |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto_obj = object() |
|
|
|
auto_obj = object() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def apply_auto_defaults(cls): |
|
|
|
def auto_factory(): |
|
|
|
cls_annotations = cls.__annotations__ |
|
|
|
return auto_obj |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def apply_auto_factory(cls): |
|
|
|
|
|
|
|
cls_annotations = cls.__dict__.get('__annotations__', {}) |
|
|
|
for name, typ in cls_annotations.items(): |
|
|
|
for name, typ in cls_annotations.items(): |
|
|
|
current_value = getattr(cls, name, None) |
|
|
|
current_value = getattr(cls, name, None) |
|
|
|
if current_value is auto_obj: |
|
|
|
if current_value is auto_obj: |
|
|
@ -15,12 +17,8 @@ def apply_auto_defaults(cls): |
|
|
|
return cls |
|
|
|
return cls |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def auto_factory(): |
|
|
|
|
|
|
|
return auto_obj |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass |
|
|
|
@dataclass |
|
|
|
@apply_auto_defaults |
|
|
|
@apply_auto_factory |
|
|
|
class CarControl: |
|
|
|
class CarControl: |
|
|
|
enabled: bool = auto_factory() |
|
|
|
enabled: bool = auto_factory() |
|
|
|
pts: list[int] = auto_factory() |
|
|
|
pts: list[int] = auto_factory() |
|
|
|