Overriding vs Non-overriding Descriptors

Python
Author

Imad Dabbura

Published

January 29, 2023

class Test:
    def __init__(self):
        self._x = 1
    
    @property
    def x(self):
        return self._x

c = Test()
print(c.x)  #=> 1
c.x = 10    #=> AttributeError: can't set attribute 'x'
class Test:
    def f(self):
        return 1

c = Test()
type(c.f)   #=> method
print(c.f())    #=> 1

c.f = 0
type(c.f)   #=> int
print(c.f)  #=> 0