I started using dataclasses recently and having some issues understanding how the inheritance works. I can’t understand the problem with too many variables being passed on. Am I using the super() method correctly here?
Attaching code below
from typing import Optional
@dataclass
class ZooAnimals():
myrange = list(range(10, 16, 1))
food_daily_kg: Optional[int]
price_food: float = 300
area_required: list = field(default_factory=list)
cost_animal_daily: float = field(init=False)
name: str = field(default='Zebra', kw_only=True)
weight: InitVar[int] = field(default = 50, kw_only=True)
weight_pounds: int = field(init=False)
dangerous_animal_warning: str = field(default='No', kw_only=True, init=False)
def __post_init__(self, weight):
self.cost_animal_daily = self.food_daily_kg * self.price_food
self.weight_pounds = self.weight * 2.7
if self.name == 'Crocodile':
self.dangerous_animal_warning = "Dangerous"
@dataclass
class Cats(ZooAnimals):
def __init__(self, area_required, name, weight):
super().__init__(area_required, name, weight)
z = Cats(565, area_required = [30], name='Leopard', weight=35)
TypeError: Cats.__init__() got multiple values for argument 'area_required'