On Tue, Aug 25, 2020, 2:09 AM Christopher Barker <python...@gmail.com> wrote:
> On Mon, Aug 24, 2020 at 11:10 AM Ricky Teachey <ri...@teachey.org> wrote: > >> \The interpreter wouldn't. I'm talking about adding this knowledge of >> signature dependent semantics to `type`. >> >> To implement this, under the hood `type` would detect the signatures with >> different semantics, and choose to wrap the functions with those >> signatures in a closure based on the intended semantic meaning. Then >> everything proceeds as it does today. >> > > but it would still not know that: > > t = (1,2,3) > something[t] > > is the same as: > > something[1,2,3] > > would it? > Definitely not. But I'm not sure that poses any kind of problem unless a person is trying to abuse the subscript operator to be some kind of alternative function call syntax, and they are wanting/expecting d[t] and d(t) to behave the same way. If I were to imagine myself explaining this to a beginner: 1. If you provide an item related dunder method that only accepts a single argument for the index or key, the index or key will be passed as a single object to that argument no matter how many "parameters" were passed to the subscript operator. This is because you are not passing positional parameters like a function call, you are passing an index. This is why, unlike a regular function call, you cannot unpack a list or tuple in an subscript operation. There would be no purpose. 2. Sometimes it is convenient to write item dunder methods that partially mimic a function call, breaking up an index into positional parameters in a similar way. When this is needed, just provide the desired number of positional arguments in the signature for it to be broken up. But this isn't intended to be a real function call. So there's no difference between these no matter how many arguments are in your dunder method signatures: d[1,2,3] d[(1,2,3)] But maybe I'm not a great teacher. >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/PT4ZQKGSPYXTLKRFVRSR6R7PW6RZ6D75/ Code of Conduct: http://python.org/psf/codeofconduct/