"""Test #1"""
class D:
def __getitem__(self, key):
return key
d = D()
# note the commas
assert d[1,] == f((1,))
################
Where f is some function that mimicks how python "translates" the "stuff" inside the square brackets. It is something like this, not quite:
def f(*args):
if not args:
# empty brackets not allowed
raise SyntaxError()
if len(args) ==1:
return args[0]
return args
The desire of many (me included) seems to be to make it possible for the subscript operator to utilize syntax very similar, or identical, to the behavior of a function call.
In other words, to make it possible to write some class, Q, that allows the following tests to pass:
#################
"""Test #2"""
# note the commas
assert q[1,] == f(1,)
assert q[1] == f(1)
assert q[(1,)] == f((1,))
##################
The problem is, I don't think it is possible to change python internals in a backwards compatible way so that we can write a function that passes all of these tests. Because the index operator recognizes this as a tuple:
1,
But function calls do not. This is an impasse.
Does this constitute a big problem for the idea of providing new dunders? I'm not sure.