Dear ChrisA, Steve, Thank you for your comments. ChrisA, it was off the main topic, but for me, the issue was just one of wording in the exception message. It's good to hear changes to wording can be done without compatibility concerns. I'll find out about merge request suggested by Stephen J. Turnbull. Steve, I think care is necessary to decide whether the validity of
t = *(1,2), a[t]
suffices to justify the expression "a[*(1,2),]". It could only justify a[ (*(1,2),) ] Note for example,
s = (1,2) t = *s, [t] == [*s,] False
Another exmaple:
t = *s, f(t) == f(*s,) False
However, for an appropriate object "a", we have
t = *(1,2), a[t] == a[1,2] True
which must be a special thing. I think this should be compared with
t = *s, (t) == (*s,) True
(In the above, I constructed "a" (and "f") by
def f(*args, **kwargs): ... return locals() ... class A: ... @property ... def __getitem__(self): ... return f ... a = A()
) Here's another piece of similarity.
[1,] == [1] True f(1,) == f(1) True (1,) == (1) False a[1,] == a[1] False
Thank you for your suggestion to submit a merge request. Best regards, Takuo On Fri, 20 Aug 2021 at 01:33, Stephen J. Turnbull <turnbull.stephen.fw@u.tsukuba.ac.jp> wrote:
Matsuoka Takuo writes:
*(1,2), (1, 2)
Yes, this works, and now that I see you just want that to work in "a[*(1,2),]", I agree, I don't know why that is a syntax error. This works, of course:
t = *(1,2), a[t]
(in the sense that if a is a sequence you get a TypeError because the index isn't an integer or slice, but if it's a mapping you'll get the value corresponding to (1,2) or a KeyError because it's not in the mapping). I think it's not good that "a[*(1,2),]" gives a SyntaxError, but I don't know why it was made that way in the first place.
I find it unfortunate SyntaxError you got with
*(1,2)
says "can't use starred expression here" since "*(1,2)" is not really a "starred expression" as defined in the Language Reference.
I don't have time to go into that tonight but if the appropriate thread gets takeup I'll comment there. You could promote the issue by submitting a merge request.
Steve