On Jun 23, 2013, at 16:34, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
Steven D'Aprano wrote:
The special case "parameter name matches exactly argument expression" is far too special, and the benefit far too minor, to deserve special syntax.
It occurs more often than you might think, because taking parameters that you've been passed and passing them on to another function is a common pattern
Yes, I do that all the time. But I can't think of a single case where there's any benefit to using keyword arguments. When you're forwarding your parameters exactly, the keywords are pure noise. Reducing the noise a little bit isn't nearly as good as just not creating it in the first place. Let's look at a typical such case: a class that encapsulates and delegates to another class--say, str. You'll have a bunch of methods like this: def encode(self, encoding, errors): return self.wrapped_str.encode(encoding, errors) What would be gained by changing it to: def encode(self, encoding, errors): return self.wrapped_str.encode(encoding=encoding, errors=errors) Or: def encode(self, encoding, errors): return self.wrapped_str.encode(=encoding, =errors) The reason for using keyword arguments is that often the meaning of positional arguments is unclear without looking up the function. That clearly isn't the case here. The meaning of the encoding and errors arguments is exactly as obvious without the keywords as with them. So, while I'll agree that the third version may be better than the second, it's still worse than the first, and Python already allows the first. This is an attempt to solve a problem that doesn't exist, and it doesn't even succeed in the attempt.