Thinking about it some more, I realized it actually means that
x['z']['x']['y']is None, because the caret points at the piece of AST being evaluated, not the part that’s incorrectly None.
Indeed, we will think about it but fixing this is not trivial. Notice that the error is not saying “this is None” but that “None cannot be indexed”. Therefore the highlighted range is the indexed operation, not the part that is None.
Is the same as if you do
X=None
X[7]
What is wrong is X[7] not X.
One of the important points if preserve the AST ranges is that if you get the code represented by the range, it will always be a valid syntactic structure, while in the original example ['z'] is not (is actually valid as a list, but that would be the wrong one
).
In any case, we can fine tune this as part of the implementation, but this doesn’t really modify the proposal so I would prefer to discuss this later if the pep is accepted.