Override property setter of base class in Python 3 - USE CASE
Peter Otten
__peter__ at web.de
Sun Sep 11 11:28:29 EDT 2016
Nagy László Zsolt wrote:
>
>> Yes, I believe it does. (Others may disagree. This is a design
>> question and very much a matter of style, not hard fact.) I would have
>> an explicit action "set_content" which will set the value of an input
>> field, the inner text of a textarea, the checked state of a check box,
>> etc.
> In other words, you would use simple getter and setter methods instead
> of properties. It is the simplest solution. (And I believe, it is
> non-pythonic, but that is just an opinion.)
>
> I would like to hear other opinions.
Disregarding potential implementation obstacles I think it would be clean
and clear if you could access a property foo in a base class with
super().foo
and set it with
super().foo = value
It looks like the get part already works:
>>> class A:
... @property
... def foo(self): return "foo"
...
>>> class B(A):
... @property
... def foo(self): return super().foo.upper()
...
>>> A().foo
'foo'
>>> B().foo
'FOO'
More information about the Python-list
mailing list