clean up old file

pull/33208/head
Shane Smiskol 11 months ago
parent a06264a8a4
commit e21593e86e
  1. 32
      selfdrive/car/data_structures.py
  2. 43
      selfdrive/car/data_test_kinda_works_chatgpt.py

@ -122,35 +122,3 @@ class CarParams:
programmedFuelInjection = auto()
debug = auto()
@auto_dataclass
class CarControl:
enabled: bool = auto_field()
pts: list[int] = auto_field()
logMonoTime: int = auto_field()
test: None = auto_field()
# testing: if origin_typ in (int, float, str, bytes, list, tuple, set, dict, bool):
@auto_dataclass
class Test997:
a: int = auto_field()
b: float = auto_field()
c: str = auto_field()
d: bytes = auto_field()
e: list[int] = auto_field()
f: tuple[int] = auto_field()
g: set[int] = auto_field()
h: dict[str, int] = auto_field()
i: bool = auto_field()
ecu: CarParams.Ecu = auto_field()
carFw: CarParams.CarFw = auto_field()
# Out[4]: Test997(a=0, b=0.0, c='', d=b'', e=[], f=(), g=set(), h={}, i=False)
CarControl()
CP = CarParams()
CP.carFw = [CarParams.CarFw()]
# CP.carFw = [CarParams.Ecu.eps]

@ -1,43 +0,0 @@
# import attr
from enum import Enum
from typing import get_origin, get_args, get_type_hints
from dataclasses import dataclass, field, is_dataclass
auto_obj = object()
def auto_field():
return auto_obj
def apply_auto_fields(cls):
cls_annotations = cls.__dict__.get('__annotations__', {})
for name, typ in cls_annotations.items():
current_value = getattr(cls, name, None)
if current_value is auto_obj:
origin_typ = get_origin(typ) or typ
if isinstance(origin_typ, str):
raise TypeError(f"Forward references are not supported for auto_field: '{origin_typ}'. Use a default_factory with lambda instead.")
elif origin_typ in (int, float, str, bytes, list, tuple, set, dict, bool) or is_dataclass(origin_typ):
setattr(cls, name, field(default_factory=origin_typ))
elif origin_typ is None:
setattr(cls, name, field(default=origin_typ))
elif issubclass(origin_typ, Enum): # first enum is the default
setattr(cls, name, field(default=next(iter(origin_typ))))
else:
raise TypeError(f"Unsupported type for auto_field: {origin_typ}")
return cls
@dataclass
@apply_auto_fields
class CarControl:
enabled: bool = auto_field()
pts: list[int] = auto_field()
logMonoTime: list[int] = field(default_factory=lambda: [1, 2, 3])
# This will now work with default values set by the decorator
car_control_instance = CarControl()
print(car_control_instance.enabled) # Should print False
print(car_control_instance.pts) # Should print []
Loading…
Cancel
Save