I was trying to play around with Python descriptors and Pycharm IDE seems to be complaining
Am I using descriptors incorrectly? Or is this expected?
Complete code:
class Age:
def __set__(self, instance, value):
if value > 200:
raise ValueError("Age cannot be more than 200")
instance._age = value
def __get__(self, instance, owner):
if instance is None:
return self
return instance._age
class Employee:
age = Age()
def __init__(self):
self._age = None
def __str__(self):
return f"Age: {self.age}"
e = Employee()
e.age = 204
print(e)