DEV Community


Discussion on: Reconciling Dataclasses And Properties In Python

paddyroddy profile image
Patrick Roddy

do you how to combine this with abstract classes? If I do the following:

from dataclasses import dataclass, field
from abc import abstractmethod

@dataclass # type: ignore
class Vehicle:

    wheels: int
    _wheels: int = field(init=False, repr=False)

    def wheels(self) -> int:
        print('getting wheels')
        return self._wheels

    def wheels(self, wheels: int):
        print('setting wheels to', wheels)
        self._wheels = wheels

    def sound_horn(self):
        raise NotImplementedError

then I get the warning error: Name 'wheels' already defined on line 7