[Python-ideas] Augmented assignment syntax for objects.

Chris Angelico rosuav at gmail.com
Tue Apr 25 20:12:55 EDT 2017


On Wed, Apr 26, 2017 at 10:05 AM, Ryan Gonzalez <rymg19 at gmail.com> wrote:
> FWIW I always liked
> Dart's/Ruby's/Crystal's/(Coffee|Moon)Script's/WhateverElse's style:
>
>
> class Cls {
>   Cls(this.a);  // IT'S MAGIC
> }
>
>
> but the Python equivalent is admittedly weirder:
>
>
> def ___init__(self, self.attr):

In a sense, what you have is this (modulo keyword arguments):

def __init__(*args):
    self, self.attr = args

which is perfectly legal, albeit weird. So it needn't actually be
magic per se, just a change in the definition of an argument name
(from NAME to whatever is legal as an assignment target).

I don't think it's particularly useful, though.

ChrisA


More information about the Python-ideas mailing list