Skip to content Skip to sidebar Skip to footer

Overloading Operators On Python Properties

Is it possible to overload an operator on a python property? Something like: class Foo( object ): @property def bar( self ): return unfoobar( self._bar ) @bar.setter

Solution 1:

No, operators are applied to the value of an attribute (be it supplied by a property or taken from the __dict__ mapping or a slot), never the attribute itself.

You will have to return a special wrapper implementing __eq__ and return that, I am afraid.


Post a Comment for "Overloading Operators On Python Properties"