Closed JimJJewett closed 6 years ago
NB: It's @dataclass
, not @DataClass
.
I've added a note to the PEP. I'll also add some tests about an inheritance case.
I think your example is backward, with respect to which field has a default and which doesn't.
What happens if a field without a default value follows one with a default value? (This may happen directly, or as the result of inheritance). e.g. from the PEP example, if quantity had been defined before unit_price?
@dataclass class InventoryItem: '''Class for keeping track of an item in inventory.''' name: str quantity_on_hand: int = 0 unit_price: float
If the answer is raising an Exception, that is fine ... but this should be explicit, and should also warn about the way it can arise from inheritance. e.g.,
@dataclass class A: a: int
@dataclass class B(A): b: int=4