[issue1388872] Polymorphic getters / setters

Amaury Forgeot d'Arc report at bugs.python.org
Tue Jun 30 18:34:15 CEST 2009


Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:

This is normal behavior: the property is created with the functions
created just above, even before they belong to any class.

To make the property search the class hierarchy, you could write: 
  foo = property(lambda x: x.get_foo(), lambda x, v: x.set_foo(v))

or make it a function:
  def polymorphic_property(getter, setter):
      return property(lambda x  : getattr(x, getter)(),
                      lambda x,v: getattr(x, setter)(v))
  [...]
  foo = polymorphic_property('get_foo', 'set_foo')

----------
nosy: +amaury.forgeotdarc
resolution:  -> works for me
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1388872>
_______________________________________


More information about the Python-bugs-list mailing list