I have a superclass where one property is an enumeration.
There are some specific subclasses that inherit from this class where only one case of the enumeration makes sense, so ideally I would like to prevent it being changed in these subclasses.
Here is a minimal example using medical professionals:
from enum import Enum, unique, auto
# My enum for medical specialities
@unique
class Speciality (Enum):
Anaesthetics = auto()
Dermatology = auto()
General_Practice = auto()
Surgery = auto()
# My superclass
class Doctor:
speciality = Specialty # Could be any case
# An example subclass
class GP (Doctor):
speciality = Specialty.GeneralPractice # Must be General Practice
Is there a way to make the speciality
property immutable in the GP subclass? If not, is there a way to implement similar functionality?