`obj[key]` is sugar for `obj.__getitem__(key)`. The first step is to look up 
the `__getitem__` method, and the second is to call it with the key. While it's 
possible that the code that raises the `TypeError` has access to all three 
objects, it can already be raised just by attempting `getattr(obj, 
'__getitem__')`, so I would not assume that this is a trivial thing to do at 
the level that the exception is being raised.

The traceback generator, on the other hand, has access to both the exception 
and the code objects that created it, which I suspect is why you are able to 
get the helpful underlines at that point.

Also, note that reporting the key is also probably non-trivial. When it's a 
string or integer literal, that's one thing, but it could be an arbitrary 
expression that has up to that point not been evaluated. Attempting to execute 
it could trigger another exception, and attempting to report it could be quite 
long.

Anyway, this is not a part of the code I've spent much time in, but I suspect 
it's not an easy QOL win.





---
[Visit 
Topic](https://discuss.python.org/t/small-suggestion-regarding-type-errors-and-subscription/67898/15)
 or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.python.org/email/unsubscribe/866906ba4030eeeba815a41997c217aa221ab9a14462d1bfd05ef48b2b4eef81).

Reply via email to