[Python-Dev] Definining properties - a use case for class decorators? (original) (raw)
Paul Moore p.f.moore at gmail.com
Wed Oct 19 11:42:25 CEST 2005
- Previous message: [Python-Dev] Definining properties - a use case for class decorators?
- Next message: [Python-Dev] Definining properties - a use case for class decorators?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 10/19/05, Michele Simionato <michele.simionato at gmail.com> wrote:
On 10/18/05, Guido van Rossum <guido at python.org> wrote: > I wonder if at some point in the future Python will have to develop a > macro syntax so that you can write > > Property foo: > def get(self): return self.foo > ...etc...
This reminds me of an idea I have kept in my drawer for a couple of years or so. Here is my proposition: we could have the statement syntax : to be syntactic sugar for = (, , )
Cor. That looks like very neat/scary stuff. I'm not sure if I feel that that is a good thing or a bad thing :-)
One question - in the expansion, "name" is used on both sides of the assignment. Consider
something name():
<definitions>
This expands to
name = something(name, (), <dict>)
What should happen if name wasn't defined before? A literal translation will result in a NameError. Maybe an expansion
name = something('name', (), <dict>)
would be better (ie, the callable gets the name of the target as an argument, rather than the old value).
Also, the bit needs some clarification. I'm guessing that it would be a suite, executed in a new, empty namespace, and the is the resulting modified namespace (with builtins removed?)
In other words, take , and do
d = {}
exec <definitions> in d
del d['__builtins__']
then is the resulting value of d.
Interesting idea...
Paul.
- Previous message: [Python-Dev] Definining properties - a use case for class decorators?
- Next message: [Python-Dev] Definining properties - a use case for class decorators?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]