Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Ivan Levkivskyi
typing.NamedTuple was already mentioned in this discussion, I just would like to add few comments: 1. I think that changing Python syntax to support declarative classes is not a realistic option in nearby future. In contrast, there is an existing syntax change - variable annotations - that can be

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Erik
On 28/04/17 10:47, Paul Moore wrote: On 28 April 2017 at 00:18, Erik wrote: The semantics are very different and there's little or no connection between importing a module and setting an attribute on self. At the technical level of what goes on under the covers, yes. At the higher level of wh

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Paul Moore
On 28 April 2017 at 14:07, Nick Coghlan wrote: >> Am I missing some point? > > Yes, the point I attempted to raise earlier: at the language design > level, "How do we make __init__ methods easier to write?" is the > *wrong question* to be asking. It's treating the symptom (writing an > imperative

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Chris Angelico
On Sat, Apr 29, 2017 at 1:31 AM, Steven D'Aprano wrote: > On Fri, Apr 28, 2017 at 05:23:59PM +1000, Chris Angelico wrote: > __init__ is called, the argument 42 is bound to the formal parameter > "attr", the assignment self.attr = attr is run, and THEN the body of the > method is called. (Before yo

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Mike Miller
On 2017-04-28 06:07, Nick Coghlan wrote: …the root cause (writing imperative initialisers is still part of the baseline recommendation for writing classes, and we don't offer any supporting infrastructure for avoiding that directly in the standard library) For a *lot* of classes, what we want t

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Stephan Hoyer
On Fri, Apr 28, 2017 at 4:55 AM, Tin Tvrtković wrote: > I'm going to posit we need declarative classes. (This is what a library > like attrs provides, basically.) For a class to be declarative, it needs to > be possible to inspect the class for its attributes and more. > > I'm putting forward th

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Steven D'Aprano
On Fri, Apr 28, 2017 at 05:23:59PM +1000, Chris Angelico wrote: > Waait a minute. Since when is the *declaration* doing this? That's what the suggested syntax says. You put the attribute assignment you want in the parameter list, which is part of the function/method declaration, not the bo

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Nick Coghlan
On 28 April 2017 at 22:26, Paul Moore wrote: > On 28 April 2017 at 12:55, Tin Tvrtković wrote: >> I'm putting forward three examples. These examples are based on attrs since >> that's what I consider to be the best way of having declarative classes in >> Python today. > > Your comments and exampl

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Nick Coghlan
On 28 April 2017 at 21:55, Tin Tvrtković wrote: > Third example: I work at a mobile games company. The backends are Python, > the games are written in other languages. The backends and the games share > data structures - requests, responses, the save game, game data. I want to > have a single sour

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Paul Moore
On 28 April 2017 at 12:55, Tin Tvrtković wrote: > I'm putting forward three examples. These examples are based on attrs since > that's what I consider to be the best way of having declarative classes in > Python today. Your comments and examples are interesting, but don't they just come down to "

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Tin Tvrtković
I'm gonna take a shot at elaborating this point. We Python programmers often tout Python as a high-level, high-productivity language where complex and useful things are easy to do. However, vanilla Python classes are anything but high level; they're basically glorified dictionaries that require an

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Paul Moore
On 28 April 2017 at 00:18, Erik wrote: >> The semantics are very different and there's little or no connection >> between importing a module and setting an attribute on self. > > At the technical level of what goes on under the covers, yes. At the higher > level of what the words mean in spoken En

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Chris Angelico
On Fri, Apr 28, 2017 at 5:02 PM, Random832 wrote: > On Fri, Apr 28, 2017, at 01:30, Chris Angelico wrote: >> Nothing whatsoever says that this is a good idea, but it's perfectly >> legal, because the for loop is defined in terms of assignment. If this >> were to be accepted (which, fwiw, I'm not a

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Chris Angelico
On Fri, Apr 28, 2017 at 4:57 PM, Steven D'Aprano wrote: > On Fri, Apr 28, 2017 at 03:30:29PM +1000, Chris Angelico wrote: > >> > Obviously we can define syntax to do anything we like, but what is the >> > logical connection between the syntax and the semantics? What part of >> > "function paramete

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Random832
On Fri, Apr 28, 2017, at 01:30, Chris Angelico wrote: > Nothing whatsoever says that this is a good idea, but it's perfectly > legal, because the for loop is defined in terms of assignment. If this > were to be accepted (which, fwiw, I'm not actually advocating, but > IF), it would also be defined