On Sat, 8 Aug 2020 at 05:12, Ricky Teachey <[email protected]> wrote:
> The semantic meaning of m[1, 2, a=3, b=2] might be made to mean:
>
> 5. m.__getx__(1, 2, a=3, b=4)
>
> ...which would in turn call, by default:
>
> m.__getitem__((1, 2), a=3, b=4)
I am currently in the process of scouting the whole set of threads and
rewrite PEP-472, somehow.
but just as a 2 cents to the discussion, the initial idea was focused
on one thing only: give names to axes.
When you have a getitem operation, you are acting on a set of axes.
e.g. a[4,5,6] acts on three axes. The first axis index is 4, the
second is 5 and the third is 6.
These axes currently are anonymous, but the whole idea is that a name
could be assigned to them.
Which is kind of asymmetric with the whole args/kwargs structure of a
function. In a function, your "axes" (which are your arguments)
_always_ have a name. Not so in getitem operations:
naming axes is optional. There's no such thing as optionally named
function arguments.
Given the asymmetry, and the need for backward compat, would it make a
possible solution to have __getitem__() accept one additional argument
"names" containing a tuple with the names?
e.g. if you call a[1,2] __getitem__(index, names) will receive
index=(1,2), names=(None, None)
if you call a[foo=1, bar=2] __getitem__ will receive index=(1,2),
names=("foo", "bar")
if you call a[1, bar=2] __getitem__ will receive index=(1,2),
names=(None, "bar")
Now, I personally don't like this solution, especially because now
passing names depend if it was declared in the signature to begin
with, but I am just throwing also this idea in the mix. Apologies if
it was already passed by someone else.
My point is that the core of the issue is to name axes (with loose
definition of what axes are. In the case of generic types, they are
the degrees of freedom of the type).
How these names are then handled (and recognised) _could_ be put in
the hands of the user (in other words, python will say "here are the
names, I have no idea if they mean something or not. it's your duty to
find out, if you care about it")
But I would like to raise another question. Is there another language
out there that provides the same feature? I am not aware of any.
--
Kind regards,
Stefano Borini
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/QUXRDOLBUNJGSTTCWA2Y5WBGSGM457D7/
Code of Conduct: http://python.org/psf/codeofconduct/