Моя наивная попытка выглядит примерно так:
Код: Выделить всё
@dataclass
class SensorLocation:
address: int
pins: int
other_details: ...
class Sensors(SensorLocation, Enum):
TOP_SENSOR = SensorLocation(address=0x10, pins=0xf, other_details=...)
BOTTOM_SENSOR = SensorLocation(address=0x10, pins=0xf0, other_details=...)
SIDE_SENSOR = SensorLocation(address=0x15, pins=0xf, other_details=...)
Однако при создании перечисления это не удается и возникает ошибка:
Код: Выделить всё
Traceback (most recent call last):
File "", line 1, in
File "/path/to/python/3.7.10/lib/python3.7/enum.py", line 232, in __new__
enum_member.__init__(*args)
File "", line 3, in __init__
File "/path/to/python/3.7.10/lib/python3.7/types.py", line 175, in __set__
raise AttributeError("can't set attribute")
AttributeError: can't set attribute
Есть ли способ обойти эту ошибку, которую я упускаю, или другое решение, которого я сейчас не вижу?
Подробнее здесь: https://stackoverflow.com/questions/709 ... -instances
Мобильная версия