[ty] Add contextual secondary annotations in more places#24696
[ty] Add contextual secondary annotations in more places#24696AlexWaygood merged 4 commits intomainfrom
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 87.94%. The percentage of expected errors that received a diagnostic held steady at 83.36%. The number of fully passing files held steady at 79/133. |
Memory usage reportMemory usage unchanged ✅ |
| --> src/mdtest_snippet.py:5:5 | ||
| | | ||
| 5 | @abstractmethod | ||
| | --------------- |
There was a problem hiding this comment.
Showing the @abstractmethod is great! But I wonder if the ---- without any trailing text is confusing. Should we say something like *method is abstract because of the abstractmethod decorator? Curious to hear if others feel the same.
There was a problem hiding this comment.
Hmm, I'm not sure. To me it feels pretty clear why we're highlighting it, given that the primary annotation already says that the issue is that method is an abstract classmethod? And the name of the decorator is pretty clear. Overloading the frame with too many labels also has a cost -- it makes it harder to spot the more important information in the diagnostic.
I feel like I've seen Clippy do similar things with secondary annotations in the past, too.
Here's what it looks like with a bit of colour:
There was a problem hiding this comment.
This example makes me wonder if it's now also necessary to underline raise NotImplementedError or the "trivial body" part isn't visible in the code frame.
Which makes me wonder if the code frame should spawn the entire method (which is generally bad?). You then only need one annotation and it's guaranteed that you see all relevant details.
There was a problem hiding this comment.
That's a great point. Since we know this method has a trivial body in this situation, it's very unlikely that the method body will be huge. That makes a lot of sense
There was a problem hiding this comment.
Do you plan on changing this or did it turn out that it regresses the experience in some cases?
There was a problem hiding this comment.
Ohh, that's different than what I had in mind. I would used the entire func_dev.range as the primary range.
There was a problem hiding this comment.
yeah, that might be better.
|
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
0dc2306 to
8c047d4
Compare
fef8da5 to
8512ce1
Compare
8512ce1 to
17b61b4
Compare
17b61b4 to
290ef82
Compare
290ef82 to
fbce8db
Compare
fbce8db to
cad725c
Compare
| ::: test.py:7:9 | ||
| --> test.py:6:5 | ||
| | | ||
| 6 | @abstractmethod |
There was a problem hiding this comment.
Should we make the same change here?
There was a problem hiding this comment.
No, because here the stub body of the abstractmethod is irrelevant to the diagnostic. In this case, we would still emit the diagnostic if the function body was return 42 rather than raise NotImplementedError, and in this case we do not say anything about how the method has a stub body in the diagnostic message
| --> src/mdtest_snippet.py:5:5 | ||
| | | ||
| 5 | @abstractmethod | ||
| | --------------- |
There was a problem hiding this comment.
Ohh, that's different than what I had in mind. I would used the entire func_dev.range as the primary range.
b657330 to
16600db
Compare
16600db to
b150a43
Compare
Summary
Following #24689, it's now much more likely that a diagnostic regarding an invalid
@final, for example, will not include the@finaldecorator in the code frame.This was already a pre-existing issue, because there's nothing to stop a class from having multiple decorators, so
@finalwas really only "accidentally" in the context window most of the time. E.g. for this class,@finalwould not have been in the context window even with our old context margin of 2:Our diagnostic on the latest release of ty for that was:
But #24689 makes this problem much likelier to occur. This PR therefore adds secondary annotations to several diagnostics that ensure that relevant decorators are included in the diagnostic frames rendered to the user
Test plan
snapshots updated