Monkey patching a @property

后端 未结 7 1891
慢半拍i
慢半拍i 2021-02-03 18:33

Is it at all possible to monkey patch the value of a @property of an instance of a class that I do not control?

class Foo:
    @property
    def bar         


        
7条回答
  •  执笔经年
    2021-02-03 19:04

    To monkey patch a property, there is an even simpler way:

    from module import ClassToPatch
    
    def get_foo(self):
        return 'foo'
    
    ClassToPatch.foo = property(get_foo)
    

提交回复
热议问题