Is it possible to assign property on a function object the similar way we assign it on class instances. My desired behaviour is like this
def prop():
print("I am a property")
def my_func():
print("Just a function call")
my_func.prop = prop
my_func.prop # prints 'I am a property'
I am able to invoke it as a function call my_func.prop()
, but is there a way to override __getattribute__
or something to achieve this result?
I have tried attaching it on a class
setattr(my_func.__class__, "prop", property(prop))
but definitely that's not the way
TypeError: cannot set 'prop' attribute of immutable type 'function'