On Thu, Aug 20, 2020 at 09:03:40AM -0400, Random832 wrote:
> On Mon, Aug 17, 2020, at 14:00, Christopher Barker wrote:
> > From an implementation perspective, the [] operator is another way to
> > call __getitem__ and __setitem__. And from that perspective, why not
> > have it act like a function call: no arguments, positional arguments,
> > keyword arguments, the whole shebang.
> >
> > But from a language design perspective, the [] operator is a way to
> > "index" a container -- get part of the container's contents. And from
> > this perspective, no index makes no sense.
>
> I think it makes perfect sense. Remember that numpy *currently* has a
> concept of "no index" [an empty tuple is used for this], it results in
> a view of the whole array, or the content as a scalar for a
> 0-dimensional array.
I wouldn't necessarily be taking numpy as the gold standard of good API
design.
Treating a missing index as the object itself makes a certain logical
sense. Here's a variable with a subscript:
xₑ
and here it is again with a missing subscript:
x
So by analogy, we might say that `x[]` should be treated as just `x`.
But honestly that's more likely to be an error, not a feature.
I think that zero dimensional arrays are a pretty dubious concept, but
if you did have one, since it has *no dimensions* it cannot contain
any content at all.
> [I've occasionally been tempted to try the same thing on ctypes
> objects, incidentally, I think it might be useful to make obj[]
> equivalent to obj.value]
And what about all the objects that don't have a .value attribute?
What's so special about that attribute that subscripting with a missing
subscript should return that attribute rather than some other?
--
Steve
_______________________________________________
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/WVE3CS7LFSKWSM7F2DKFLWTS4UST6DOA/
Code of Conduct: http://python.org/psf/codeofconduct/