Skip to content

Make mypy more positive #7368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ilevkivskyi opened this issue Aug 19, 2019 · 6 comments · Fixed by #7425
Closed

Make mypy more positive #7368

ilevkivskyi opened this issue Aug 19, 2019 · 6 comments · Fixed by #7425

Comments

@ilevkivskyi
Copy link
Member

Maybe someone already noticed this, but IMO mypy is a bit "grumpy". Currently mypy never says anything good to a user. If there are no errors, then the output is just empty. This can even cause some confusion for a new user trying it on a simple clean file.

What do you think about emitting a simple message like Success: no issues found if there are no errors/notes emitted during type checking?

Btw, we can also optionally add a summary line if there are errors saying something like N issues found in M files. I often want to check how many errors there are and this forces me to re-run mypy with | grep error | wc -l.

@msullivan
Copy link
Collaborator

My gut inclination is for silence in the success case. (Although certainly our internal wrapper scripts are all very noisy?)

@ilevkivskyi
Copy link
Member Author

@msullivan

  • Yes, our internal wrappers add a success message, and I didn't hear anyone complaining about this.
  • I think an important part of reality that we need to accept is that although mypy was intended as a (relatively) advanced tool, it is in fact used a lot by novice programmers.

@JukkaL
Copy link
Collaborator

JukkaL commented Aug 26, 2019

I don't have a strong opinion about this, but at least printing something when there is nothing to report might help new users. It could also be useful to print something like "no issues found in 35 files". One possible failure mode is accidentally checking only a small number of files, when imports aren't being followed.

I think it would make sense to do a quick survey of what other popular developer tools report on success (both Python and non-Python tools).

@JelleZijlstra
Copy link
Member

Here are a few:

$ pylint setup.py 

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

$ flake8 setup.py 
$ black setup.py 
All done! ✨ 🍰 ✨
1 file left unchanged.

@JukkaL
Copy link
Collaborator

JukkaL commented Aug 29, 2019

Another reason for preferring a success/summary message is that otherwise multiple mypy runs can be hard to distinguish in a terminal. Here's an actual example:

(mypy) jukka mypy $ ./chk.sh
mypy/mypy/checker.py:3797: error: Unexpected keyword argument "code" for "report_protocol_problems" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1135: note: "report_protocol_problems" of "MessageBuilder" defined here
mypy/mypy/checker.py:3801: error: Unexpected keyword argument "code" for "note_call" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1102: note: "note_call" of "MessageBuilder" defined here
mypy/mypy/checker.py:3806: error: Unexpected keyword argument "code" for "note_call" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1102: note: "note_call" of "MessageBuilder" defined here
(mypy) jukka mypy $ ./chk.sh
mypy/mypy/messages.py:1208: error: Unexpected keyword argument "code" for "pretty_overload" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1214: error: Unexpected keyword argument "code" for "pretty_overload" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1215: error: Unexpected keyword argument "code" for "print_more" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1240: error: Unexpected keyword argument "code" for "print_more" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1242: note: "pretty_overload" of "MessageBuilder" defined here
mypy/mypy/messages.py:1287: note: "print_more" of "MessageBuilder" defined here
mypy/mypy/checker.py:3797: error: Argument "code" to "report_protocol_problems" of "MessageBuilder" has incompatible type "Optional[ErrorCode]"; expected "ErrorCode"  [arg-type]
mypy/mypy/checker.py:3801: error: Unexpected keyword argument "code" for "note_call" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1102: note: "note_call" of "MessageBuilder" defined here
mypy/mypy/checker.py:3806: error: Unexpected keyword argument "code" for "note_call" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1102: note: "note_call" of "MessageBuilder" defined here
mypy/mypy/checkexpr.py:1335: error: Too few arguments for "report_protocol_problems" of "MessageBuilder"  [call-arg]
(mypy) jukka mypy $

Here's the same with a summary message:

(mypy) jukka mypy $ ./chk.sh
mypy/mypy/checker.py:3797: error: Unexpected keyword argument "code" for "report_protocol_problems" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1135: note: "report_protocol_problems" of "MessageBuilder" defined here
mypy/mypy/checker.py:3801: error: Unexpected keyword argument "code" for "note_call" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1102: note: "note_call" of "MessageBuilder" defined here
mypy/mypy/checker.py:3806: error: Unexpected keyword argument "code" for "note_call" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1102: note: "note_call" of "MessageBuilder" defined here
3 errors in 1 file
(mypy) jukka mypy $ ./chk.sh
mypy/mypy/messages.py:1208: error: Unexpected keyword argument "code" for "pretty_overload" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1214: error: Unexpected keyword argument "code" for "pretty_overload" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1215: error: Unexpected keyword argument "code" for "print_more" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1240: error: Unexpected keyword argument "code" for "print_more" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1242: note: "pretty_overload" of "MessageBuilder" defined here
mypy/mypy/messages.py:1287: note: "print_more" of "MessageBuilder" defined here
mypy/mypy/checker.py:3797: error: Argument "code" to "report_protocol_problems" of "MessageBuilder" has incompatible type "Optional[ErrorCode]"; expected "ErrorCode"  [arg-type]
mypy/mypy/checker.py:3801: error: Unexpected keyword argument "code" for "note_call" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1102: note: "note_call" of "MessageBuilder" defined here
mypy/mypy/checker.py:3806: error: Unexpected keyword argument "code" for "note_call" of "MessageBuilder"  [call-arg]
mypy/mypy/messages.py:1102: note: "note_call" of "MessageBuilder" defined here
mypy/mypy/checkexpr.py:1335: error: Too few arguments for "report_protocol_problems" of "MessageBuilder"  [call-arg]
8 errors in 3 files
(mypy) jukka mypy $

I think that it's easier to see where the new run beings in the second example. Colors (#7410) would also help with this.

ilevkivskyi added a commit that referenced this issue Aug 31, 2019
Fixes #7368
Fixes #7410

This adds some basic support for output styling on Mac and Linux. The formatter does some basic error message parsing because passing them forward in a structured form would be a bigger change.
@snowyurik
Copy link

That's worst idea ever. How I am supposed to use mypy in CI/CD now???????????? Please undo it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants