I would like to override an attribute with a property, but only on one instance. Here is how I try to solve it, but it does not do what I would like to:
class Foo:
def __init__(self):
self.bar = True
self._hidden = False
a = Foo()
print(a.bar)
a.bar = property(lambda self: self._hidden)
print(a.bar)
>>> C:\Users\Ilya\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/Ilya/pydolons/experiment.py
>>> True
>>> <property object at 0x0323B960>
Can it be done? what is the actual mechanics of dunder calls that enable class property, but not the one which is set on the instance?
Following code does what I want to do, but it modifies the class:
class Foo:
def __init__(self):
self.bar = True
self._hidden = False
a = Foo()
print(a.bar)
Foo.bar = property(lambda self: self._hidden)
print(a.bar)
>>> C:\Users\Ilya\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/Ilya/pydolons/experiment.py
>>> True
>>> False