[Python-ideas] Augmented assignment syntax for objects.

Chris Angelico rosuav at gmail.com
Thu Apr 27 19:54:55 EDT 2017


On Fri, Apr 28, 2017 at 9:21 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> What happens if you use this syntax in a top-level function rather
> than a method? (Or a static method?)
>
> def function(x, y, x.attr):
>     ...
>
> (And don't forget that behind the scenes, methods *are* functions.) What
> would this syntax even mean?
>
>
> Or if you use some other name other than the first parameter?
>
> def method(self, spam, foo.eggs):

Exactly the same thing as:

def function(*args):
    x, y, x.attr = args

def method(*args):
    self, spam, foo.eggs = args

It's well-defined - at least for positional args. Not sure what
keyword arg handling would be though.

ChrisA


More information about the Python-ideas mailing list