Я экспериментально попробовал включить две спецификации полей — repr=False и init=False для двух полей, но я догадался, что они не будут работать, и они не работают.
Код: Выделить всё
@dataclass
class Product:
name: str
description: str = field(repr=False)
N: float = field(init=False, default=0.0)
P: float
K: float
_customer = None #class variable until assigned
self._customer # but 'self' doesn't exist in this context.
@property
def customer(self):
return self._customer
@customer.setter
def customer(self, value):
self._customer = value
Код: Выделить всё
class Product:
def __init__(self, name: str, description: str, N: float, P: float, K: float):
self.name = name
self.description = description
self.N = N
self.P = P
self.K = K
self._customer = None
@property
def customer(self):
return self._customer
@customer.setter
def customer(self, value):
self._customer = value
Подробнее здесь: https://stackoverflow.com/questions/662 ... -in-python