py3k feature proposal: field auto-assignment in constructors

Ben Finney bignose+hates-spam at benfinney.id.au
Sun Jan 27 22:33:42 EST 2008


"Russ P." <Russ.Paielli at gmail.com> writes:

> On Jan 27, 5:13 pm, Wildemar Wildenburger
> <lasses_w... at klapptsowieso.net> wrote:
> > class Server(object):
> >      def __init__(self, self.host, self.port,
> >                   self.protocol, self.bufsize, self.timeout):
> >          pass
> >
> > ?
> 
> That makes sense to me.

Not to me. 'self' is a name that doesn't exist until *after* that
'def' statement is completed; in any other statement, that would mean
'self.foo' in the same statement would raise a NameError.

Special-casing it for a function declaration complicates the language
for little gain: the rules of what is valid when become more
complicated. Special cases aren't special enough to break the rules.

-- 
 \        "I took a course in speed waiting. Now I can wait an hour in |
  `\                              only ten minutes."  -- Steven Wright |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list