[Python-ideas] Syntax for easy binding __name__, __module__, __qualname__ to arbitrary objects

Greg Ewing greg.ewing at canterbury.ac.nz
Fri May 10 01:08:46 CEST 2013


Paul Moore wrote:
> Overall, I'm somewhat indifferent. The use case seems fairly specialised 
> to me, and yet the syntax "def name = value" seems like it's worth 
> reserving for something a bit more generally useful.

Not sure about the syntax, but I for one would find
something like this useful for other purposes. For
example, in some of my libraries I have a function
that creates a special kind of property that needs
to know its own name. Currently you have to write
it like this:

    class Foo:

       blarg = overridable_property('blarg', "The blarginess of the Foo")

which is an annoying DRY violation. Using the
proposed syntax, it could be written

    class Foo:

       def blarg = overridable_property("The blarginess of the Foo")

> Maybe the def name=value syntax should implement a protocol,

Hmmm. Maybe

    def name = value

could turn into

    name = value.__def__('name', __name__)

-- 
Greg



More information about the Python-ideas mailing list