79378179

Date: 2025-01-22 14:44:46
Score: 0.5
Natty:
Report link

As @NotaName stated, this kind of inheritence is impossible. Anyway, it is common good pratice to alternate between encapsulation and inheritence. In your case this would translate as:

from abc import ABC, abstractmethod

class Dog(ABC):
    family: str = "Canidae"

    @abstractmethod
    def bark(self) -> str:
        pass

class Husky(Dog):
    def bark(self) -> str:
        return "Woof Woof"

class Chihuahua(Dog):
    def bark(self) -> str:
        return "Yip Yip"


class NoiseMaker:
    def __init__(self, dog: Dog, name: str) -> None:
        self.dog = dog
        self.name = name
        super().__init__()
    
    def bark_quietly(self) -> str:
        print(f"{self.dog.bark().lower()}")

if __name__ == "__main__":
    chihuaha = Chihuahua()
    noisemaker = NoiseMaker(chihuaha, "Rex")
    noisemaker.bark_quietly()
Reasons:
  • Whitelisted phrase (-1): In your case
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • User mentioned (1): @NotaName
  • Low reputation (1):
Posted by: quickfakename