[Python-ideas] Augmented assignment syntax for objects.

MRAB python at mrabarnett.plus.com
Wed Apr 26 21:45:41 EDT 2017


On 2017-04-26 23:29, Erik wrote:
> On 26/04/17 19:15, Mike Miller wrote:
>> As the new syntax ideas piggyback on existing syntax, it doesn't feel
>> like that its a complete impossibility to have this solved.  Could be
>> another "fixed papercut" to drive Py3 adoption.  Taken individually not
>> a big deal but they add up.
> 
> *sigh* OK, this has occurred to me over the last couple of days but I
> didn't want to suggest it as I didn't want the discussion to fragment
> even more.
> 
> But, if we're going to bikeshed and there is some weight behind the idea
> that this "papercut" should be addressed, then given my previous
> comparisons with importing, what about having 'import' as an operator:
> 
> def __init__(self, a, b, c):
>      self import a, b
>      self.foo = c * 100
> 
> Also allows renaming:
> 
> def __init__(self, a, b, c):
>      self import a, b, c as _c
> 
> Because people are conditioned to think the comma-separated values after
> "import" are not tuples, perhaps the use of import as an operator rides
> on that wave ...
> 
> (I do realise that blurring the lines between statements and operators
> like this is probably not going to work for technical reasons (and it
> just doesn't quite read correctly anyway), but now we're bikeshedding
> and who knows what someone else might come up with in response ...).
> 
If we're going to bikeshed, then:

def __init__(self, a, b, c):
     for self import a, b
     self.foo = c * 100

and:

def __init__(self, a, b, c):
     for self import a, b, c as _c


More information about the Python-ideas mailing list