I'm currently patching a property of a class from a library to make it more versatile.
I'm doing this using the following code which works fine:
_orig_is_xhr = BaseRequest.is_xhr.fget
_orig_is_xhr_doc = BaseRequest.is_xhr.__doc__
BaseRequest.is_xhr = property(lambda self: _orig_is_xhr(self) or
'_iframe-xhr' in request.form, doc=_orig_is_xhr_doc)
However, it would be much nicer if i could simply overwrite the getter function so the docstring is preserved:
_orig_is_xhr = BaseRequest.is_xhr.fget
BaseRequest.is_xhr.fget = lambda self: (_orig_is_xhr(self) or
'_iframe-xhr' in request.form)
This doesn't work because property.fget
is a read-only attribute (TypeError: readonly attribute
when trying to assign to it).
I'm curious if there is a special reason for this or it the python developers just thought it makes no sense to modify a property after creating it without replacing it with a new one.