navred61's picture
copied from private space
99a41ea
"""Class inheritance example for testing AST parsing."""
class Animal:
"""Base animal class."""
def __init__(self, name, species):
self.name = name
self.species = species
self.is_alive = True
def speak(self):
return "Some generic animal sound"
def eat(self):
return f"{self.name} is eating"
class Dog(Animal):
"""Dog class inheriting from Animal."""
def __init__(self, name, breed):
super().__init__(name, "Canine")
self.breed = breed
self.is_trained = False
def speak(self):
return "Woof!"
def fetch(self):
return f"{self.name} is fetching the ball"
def train(self):
self.is_trained = True
class Cat(Animal):
"""Cat class inheriting from Animal."""
def __init__(self, name, color):
super().__init__(name, "Feline")
self.color = color
self.lives_left = 9
def speak(self):
return "Meow!"
def climb(self):
return f"{self.name} is climbing"