Monkey patching a @property

后端 未结 7 1892
慢半拍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 18:45

    from module import ClassToPatch
    
    def get_foo(self):
        return 'foo'
    
    setattr(ClassToPatch, 'foo', property(get_foo))
    

提交回复
热议问题