[Python-Dev] Defining properties - a use case for class decorators? (original) (raw)
Jim Jewett jimjjewett at gmail.com
Wed Oct 19 15:44:09 CEST 2005
- Previous message: [Python-Dev] Early PEP draft (For Python 3000?)
- Next message: [Python-Dev] Defining properties - a use case for class decorators?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
(In http://mail.python.org/pipermail/python-dev/2005-October/057409.html,) Nick Coghlan suggested allowing attribute references as binding targets.
x = property("Property x (must be less than 5)")
def x.get(instance): ...
Josiah shivered and said it was hard to tell what was even intended, and (in http://mail.python.org/pipermail/python-dev/2005-October/057437.html) Nick agreed that it was worse than
x.get = f given: def f(): ...
Could someone explain to me why it is worse?
I understand not wanting to modify object x outside of its definition.
I understand that there is some trickiness about instancemethods and bound variables.
But these objections seem equally strong for both forms, as well as for the current "equivalent" of
def f(): ...
x.get = f
The first form (def x.get) at least avoids repeating (or even creating) the temporary function name.
The justification for decorators was to solve this very problem within a module or class. How is this different? Is it just that attributes shouldn't be functions, and this might encourage the practice?
-jJ
- Previous message: [Python-Dev] Early PEP draft (For Python 3000?)
- Next message: [Python-Dev] Defining properties - a use case for class decorators?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]