
Alex Hall writes:
OK, that's fair. What about `{foo::}`?
I don't like any of them. People who are going to use the syntax should choose it, not those of us who won't.
I would personally be quite happy if I could replace:
``` class A: def __init__(self, foo, bar, spam): self.foo = foo self.spam = spam self.bar = bar ```
with something like:
``` class A: def __init__(self, foo, bar, spam): setattrs(self, **, foo, bar, spam) ```
Wouldn't you?
No, I doubt I would use that. It's not so much the repetition of identifiers alone, it's the combination with the repetition of self: two dimensional redundancy! Probably a holdover from the implicit 'this' in C++. Although, come to think of it, in C++ to assign to a member with the same name as a formal argument you'd have to explicitly use 'this'. I apologize for wasting your time on that comment. It turns out to be incoherent and I shouldn't have mentioned it.
Please make a PR showing how you would refactor some of these.
Again, you must be joking. You need to show that this is useful enough to be worth a syntax change, which is a high bar. A dozen examples in the whole stdlib? I'm not going to do hours of work understanding those modules to refactor perfectly good code. I will outline what I'd look at, though. In general the vertically formatted examples look fine to me, and I see no reason to refactor them. I'd reformat the others vertically. In code not intended to be maintained, I'd likely use positional arguments and just copy the prototypes (deleting defaults and type annotations). The two dicts look fine to me as they are. But it's easy to say that now I would design them using Enums. For example: class LogLevel(IntEnum): CRITICAL = 6 FATAL = 5 ERROR = 4 WARN = 3 WARNING = 3 INFO = 2 DEBUG = 1 NOTSET = 0 # I wouldn't bother with this alias in my own code. _nameToLevel = LogLevel.__members__ There are four calls to super (all in argparse), which seems to be due to heavy use of mixins, and two calls to cls (in json/__init__.py). Within the stdlib, the calls to super and to cls seem to be idiosyncratic to the authors of those particular modules, but if the plethora of same name arguments is typical of these techniques, that would be some support for a syntax change. I know those techniques are commonly used, I just don't have use for them myself. That leaves four various other examples in the whole stdlib, not very many. Although I'm sure you'd find more with a lower limit, I doubt they're as convincing as the ones with many same name arguments. We'll see what the senior committers have to say, but I think you have an uphill battle on your hands. Steve