[Python-Dev] reducing self.x=x; self.y=y; self.z=z boilerplate code
Reinhold Birkenfeld
reinhold-birkenfeld-nospam at wolke7.net
Sat Jul 2 09:02:52 CEST 2005
Nick Coghlan wrote:
[...]
> If the right hand side of 'as' permitted the same forms as are going
> to be permitted for the 'as' clause in 'with' statements, then Ralf's
> situation could be handled via:
>
> def __init__(self as s, x as s.x, y as s.y, z as s.z):
> pass
>
> Essentially, it allows arguments to be given two names - a public name
> (before the 'as', used for keyword arguments), and a private name
> (after the 'as', not used for keyword arguments, allows easy shorthand
> aliasing of self, unpacking of tuple arguments, and easy assignment of
> instance variables).
There once was a suggestion like this on c.l.py, expanding this to other
statements, like:
if re.match('a.*b', text) as m:
# do something
What has become of this? It seems to be a wanted feature, and while I concur
that classic 'C-style' assignment-as-expression is undesirable (because of
the =/== bug-source), this would be a way, wouldn't it?
Reinhold
--
Mail address is perfectly valid!
More information about the Python-Dev
mailing list