[Python-ideas] Accepting keyword arguments for __getitem__
Stefano Borini
stefano.borini at ferrara.linux.it
Mon Jun 23 22:40:26 CEST 2014
On 6/23/14 10:16 PM, Andrew Barnert wrote:
> That last problem is a more general one, which applies to function
> calls at least as much as to your proposed use case, and there's an
> open PEP (466) that could probably use more use cases to convince
> people.
Sorry, I cannot find it. PEP 466 is about network security. It's the
first time I engage in active python proposals, so I might be a bit
clueless if for python3 there's a different repository/numbering system.
> With that PEP, you wouldn't get {'z': 3}, {'r': 4}, but
> OrderedDict(('z', 3), ('r', 4)) or something equivalent. I think that
> would make the function-calling workaround much more usable. And it
> would definitely make your additional proposal a lot simpler: add
> kwargs--which then work exactly the same as in function calls--to
> getitem.
You would however have to skip *args, as it would never make sense in
that context: the full non-keyword arguments would be always packed into
the y tuple.
> There's also a proposal for namedtuple literals, which seems like it
> fit your use case a lot better (especially if, like a regular tuple
> literal, the parens were optional). Unfortunately, if I remember
> right, nobody was able to come up with a good enough solution to the
> semantic problems to make it worth writing a PEP. But you could find
> that in the archives and see if you can come up with a workable
> version of that idea.
I see that the idea spawned some discussion, and at this point I don't
really know what a possible course of action might be. I am certainly
open to do additional research and aggregate what I find into some kind
of proto-PEP, and hack the interpreter for some possible implementation.
Thanks,
Stefano
More information about the Python-ideas
mailing list