__autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code)

Dan Sommers me at privacy.net
Sun Jul 10 19:00:29 EDT 2005


On Sun, 10 Jul 2005 16:26:24 -0400,
"Terry Reedy" <tjreedy at udel.edu> wrote:

> "Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com> wrote in message 
> news:20050710133959.83611.qmail at web31512.mail.mud.yahoo.com...

> I have a suggestion I don't remember seeing for flagging which vars to 
> autoinit without new syntax: use '_' instead of '.'.  I have never seen 
> local vars with a leading '_'.  So, in combination with whatever other 
> mechanism (metaclass, __init__ decorator?)

>    def __init__(self, _x, y, _z) :

> would automatically do self.x = _x, self.z = _z, but not self.y = y.

> Terry J. Reedy

That's a pretty big change; now all formal parameters beginning with an
underscore have a brand new meaning.

How about this:

    def __init__(self, self.x, y, self.z):
        # self.x, self.z from first and third explicit parameters
        do_something_with_y()

where "self" in "self.x" and "self.y" would have to match the first
parameter (so that the pathological among us could write this:

    def __init__(this, this.x, y, this.z):
        do_something_with_y()

instead).

(Sorry if this posts multiple times; gnus and/or my news server were not
happy when I was composing this reply.)

Regards,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>



More information about the Python-list mailing list