You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have mentioned this on gitter, but I think it might be a good idea to open an issue to track this. Current mypy output is a bit harsh. Compare (I know these are different kind of errors, but still)
~/src/mypy [master] λ cat x.rs
fn main(){let v:&[usize] = Vec::with_capacity("10");}
~/src/mypy [master] λ rustc x.rs
error[E0308]: mismatched types
--> x.rs:2:42
|
2 | let v:&[usize] = Vec::with_capacity("10");
| ^^^^ expected usize, found reference
|
= note: expected type `usize`
found type `&'static str`
= help: here are some functions which might fulfill your needs:
- .len()
error[E0308]: mismatched types
--> x.rs:2:23
|
2 | let v:&[usize] = Vec::with_capacity("10");
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected &[usize], found struct `std::vec::Vec`
|
= note: expected type `&[usize]`
found type `std::vec::Vec<_>`
= help: here are some functions which might fulfill your needs:
- .as_slice()
error: aborting due to 2 previous errors
I don't have any ideas other than that we could start adding at least come colors. I'm pretty sure that we should keep the old format as an option, because it is useful for various tools like neomake, it drives current test-cases-as-data and simply some people might prefer that.
Even though I agree that some of mypy's errors confuse users, I'm not a big fan of that kind of ultra-verbose output. It's better to make some specific errors better while keeping the general style. I'm also not a big fan of colors (but I know I am in the minority there).
It would be useful to have better error messages, but I agree with @gvanrossum that just fixing specific errors that aren't very good should be enough. We might make certain error messages much longer but I'm not a fan of making every message verbose, as it arguably makes it slower for a human to scan the output from mypy.
I'm not saying we should have output as verbose as rustc. Rust needs it primarily because of steep learning curve associated with borrow checker - typing Python code is way easier.
Created a separate issues to discuss colors (#7410) and printing the offending line (#7411). This issue will continue to cover other suggestions, but I'd say that the linked issues are the highest-priority improvements.
I was also thinking something that might be nice is to make the output less dense. At least for me, it is much harder to read/scan the output of more than a dozen errors because it turns into a huge wall of text. This likely would require breaking things across lines however, and I could see that being problematic with the test suite :/
The main problem I have is with errors like "expression has type XXX, expected type YYY". Sometimes XXX and YYY are very long (e.g. List[Tuple[int, int, Dict[str, Tuple[str, str]]] and it's hard to even find where one ends and the other starts; it's also hard to compare them item by item (e.g. if the key type to Dict is bytes in one and str in the other. We could use color to highlight the types different than the rest of the message, and maybe we could even do some kind of diff between the two types and highlight the actual difference in red/green (like code diffs).
Highlighting types and quoted strings in messages when using colors sounds helpful.
I like the idea of an aligned diff with colors, and maybe a ^ pointing to the first difference (useful if colors are disabled). This should probably only be enabled in some cases, such as when the types are long enough, and there is a common prefix (so finding the difference can be hard).
Maybe we should split some messages to multiple lines, but only if the types are very long. For example, we could show expression type and expected type each on a separate line after the main message. If we don't do this always, we likely wouldn't have to change many test cases.
We could show each file name only once like a header, on a separate line. Messages would be shorter since the file name would not be shown for each message, and the messages would be better aligned due to variable-length file paths.
I'm skeptical about formatting things differently depending on (e.g.) the size of the types. This makes things harder for tools that parse errors. So does breaking errors across lines. Though maybe those tools could be taught to only care about the error code, and further detail could be added as notes.
I feel like tools should not expect error messages to be easily parseable. We change them not infrequently, and with error codes I see no reason why they should even try to parse the messages?
Activity
gvanrossum commentedon May 24, 2017
Even though I agree that some of mypy's errors confuse users, I'm not a big fan of that kind of ultra-verbose output. It's better to make some specific errors better while keeping the general style. I'm also not a big fan of colors (but I know I am in the minority there).
JukkaL commentedon May 24, 2017
It would be useful to have better error messages, but I agree with @gvanrossum that just fixing specific errors that aren't very good should be enough. We might make certain error messages much longer but I'm not a fan of making every message verbose, as it arguably makes it slower for a human to scan the output from mypy.
miedzinski commentedon May 24, 2017
I'm not saying we should have output as verbose as rustc. Rust needs it primarily because of steep learning curve associated with borrow checker - typing Python code is way easier.
I think we should go more into gcc direction:
image
and we're actually close to that. Three things:
JukkaL commentedon Aug 29, 2019
Created a separate issues to discuss colors (#7410) and printing the offending line (#7411). This issue will continue to cover other suggestions, but I'd say that the linked issues are the highest-priority improvements.
emmatyping commentedon Aug 30, 2019
I was also thinking something that might be nice is to make the output less dense. At least for me, it is much harder to read/scan the output of more than a dozen errors because it turns into a huge wall of text. This likely would require breaking things across lines however, and I could see that being problematic with the test suite :/
gvanrossum commentedon Aug 30, 2019
The main problem I have is with errors like "expression has type XXX, expected type YYY". Sometimes XXX and YYY are very long (e.g.
List[Tuple[int, int, Dict[str, Tuple[str, str]]]and it's hard to even find where one ends and the other starts; it's also hard to compare them item by item (e.g. if the key type toDictisbytesin one andstrin the other. We could use color to highlight the types different than the rest of the message, and maybe we could even do some kind of diff between the two types and highlight the actual difference in red/green (like code diffs).JukkaL commentedon Aug 30, 2019
Some thoughts about very long errors:
gvanrossum commentedon Aug 30, 2019
I'm skeptical about formatting things differently depending on (e.g.) the size of the types. This makes things harder for tools that parse errors. So does breaking errors across lines. Though maybe those tools could be taught to only care about the error code, and further detail could be added as notes.
emmatyping commentedon Aug 31, 2019
I feel like tools should not expect error messages to be easily parseable. We change them not infrequently, and with error codes I see no reason why they should even try to parse the messages?
gvanrossum commentedon Aug 31, 2019
We (or Ivan) have some ad-hoc scripts that grep for certain errors and auto-insert type-ignores. But that's probably going the way of the dodo.
hauntsaninja commentedon Aug 3, 2022
On latest master, mypy looks pretty close to the gcc output when using
--pretty