I am trying to define an abstract class with an abstract property that can then be inherited in a concrete class. But it is giving me maximum recursion depth exceeded
.
Vechile
is an abstract class and Car
implements that class. The base class has a property called parking_ticket
which I am keeping out of the __init__
of the abstract class and defining a property called parking_ticket
to act as a getter and setter. Please help me to point out where is the mistake.
Abstract Class
"""
module string
"""
from abc import ABC, abstractmethod
from vehicle_type import VehicleType
from parking_ticket import ParkingTicket
class Vechile(ABC):
"""
class docstring
"""
@abstractmethod
def __init__(self, license_plate: str,
kind_of_vehicle: VehicleType) -> None:
self.plate_number = license_plate
self.vehicle_type = kind_of_vehicle
self.parking_ticket = None
@property
@abstractmethod
def parking_ticket(self):
pass
@parking_ticket.setter
@abstractmethod
def parking_ticket(self, parking_ticket: ParkingTicket):
pass
Concrete Class
from vehicle import Vechile
from vehicle_type import VehicleType
from parking_ticket import ParkingTicket
from datetime import datetime, timedelta
class Car(Vechile):
def __init__(self,
license_plate: str) -> None:
super().__init__(license_plate, VehicleType.CAR)
@property
def parking_ticket(self):
return self.parking_ticket
@parking_ticket.setter
def parking_ticket(self,
ticket: ParkingTicket):
self.parking_ticket = ticket
p_ticket = ParkingTicket(ticket_number="123",
plate_number="12345",
allocated_spot_id=10,
issued_at=datetime.utcnow(),
vaccated_at=datetime.utcnow() + timedelta(hours=5),
charges=50
)
c = Car('MH53TS7618')
c.parking_ticket = p_ticket
print(c)