[Python-ideas] Assignment decorators (Re: The Descriptor Protocol...)

Guido van Rossum guido at python.org
Fri Mar 4 18:36:03 CET 2011

On Fri, Mar 4, 2011 at 5:15 AM, Joao S. O. Bueno <jsbueno at python.org.br> wrote:
> I am not arguing necessarily for the decorator approach. But I think
> it is relevant to have a syntactic language feature that allows the
> creation of general objects that are aware of their "primary" names.

I think that's a reasonable thought to pursue further. If I could write

class Person(Model):
  name = StringProperty()
  age = IntegerProperty()

without Model needing to have a custom metaclass that goes over the
__dict__ and tells each Property instance its name I would take it.

In other news, exploring the pros and cons of x.(foo) and its
alternatives and variations would also be a fine idea. I find myself
writing getattr() a lot. Although OTOH I also find myself telling
people in code reviews a lot how they can avoid the need for using
getattr(). And OT3H my most common use of getattr() is probably the
3-argument variant, as a best-practice alternative to using hasattr().

--Guido van Rossum (python.org/~guido)

More information about the Python-ideas mailing list