[Python-Dev] Definining properties - a use case for class decorators?

Michele Simionato michele.simionato at gmail.com
Wed Oct 19 12:10:53 CEST 2005

On 10/19/05, Paul Moore <p.f.moore at gmail.com> wrote:
> 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 <definitions> bit needs some clarification. I'm guessing
> that it would be a suite, executed in a new, empty namespace, and the
> <dict-of-definitions> is the resulting modified namespace (with
> __builtins__ removed?)
> In other words, take <definitions>, and do
>     d = {}
>     exec <definitions> in d
>     del d['__builtins__']
> then <dict-of-definitions> is the resulting value of d.
> Interesting idea...
> Paul.

<name> would be a string and <dict-of-definitions> a dictionary.
As I said, the semantic would be exactly the same as the current
way of doing it:

class <name> <args>:
    __metaclass__ = <callable>

I am just advocating for syntactic sugar, the functionality is already there.

           Michele Simionato

More information about the Python-Dev mailing list