[Python-Dev] PEP 318 restrictions on elements (original) (raw)
[Python-Dev] PEP 318 - generality of list; restrictions on elements
Guido van Rossum guido at python.org
Wed Mar 10 11:09:25 EST 2004
- Previous message: [Python-Dev] PEP 318 - generality of list; restrictions on elements
- Next message: [Python-Dev] PEP 318 - generality of list; restrictions on elements
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> So decorators couldn't be used to create read-only properties?
Maybe I'm misunderstanding something. I thought that a property contains a get descriptor, which makes it a kind of callable.
That's irrelevant; the property itself isn't callable.
Also, I thought we had explicitly punted on allowing decorators to create properties because the syntax wasn't sufficiently flexible without contortions.
It would work just fine for read-only descriptors; in fact I believe that
def foo [property] (self): return ...calculated value of foo...
would be all you need (it would be nice if property tried to get the docstring out of the get function).
In any case, I would prefer not to let the semantics require anything, and to make this just a (preferred) shorthand for applying arbitrary transformations to something that starts out as a function.
Two additional thoughts:
I'm not sure I like using the same syntax for classes; the use cases are so different that using similar syntax only adds confusion, and I think the use cases for classes are a lot weaker than for methods.
The syntax should also apply to regular functions.
It needs to be crystal clear that the list of transformations is applied at function/method definition time, not at class definition time (which is later, after all the methods have been collected in a namespace).
--Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] PEP 318 - generality of list; restrictions on elements
- Next message: [Python-Dev] PEP 318 - generality of list; restrictions on elements
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]