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

Ethan Furman ethan at stoneleaf.us
Tue May 14 02:14:32 CEST 2013


On 05/13/2013 05:03 PM, Greg Ewing wrote:
>
> I'd like to propose something a bit different:
>
>
>     def name as expr(arg, ...)
>
> which would expand to something like
>
>     name = expr(arg, ..., __name__ = 'name', __module__ = 'module')
>
> For example,
>
>     def Animal as Enum('cat dog platypus')
>
> This reads quite naturally: "define Animal as an
> Enum with these arguments."
>
> Another example based on my own use case:
>
>     def width as overridable_property("The width of the widget.")

+1 for the idea


> (Yes, this is yet another, different use of the word "as",
> but I don't see anything wrong with that. Small words in
> English often don't mean much on their own and derive most
> of their meaning from their context.)

and another +1  :)

--
~Ethan~


More information about the Python-ideas mailing list