-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add support for nicer error output #7425
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
Conversation
I just realized that these changes don't affect the daemon. When we will agree here, I will make a separate PR to update the daemon. |
Nice! I'd like to play around a little with this before merging to get a feel of how this works. A few quick comments:
|
@JukkaL OK, I made the changes we discussed privately. Also here is how new output looks on white background. |
I like the new look on a light theme. (What does it look now on black theme? Still the same?) I don't recognize Jukka's emoji; let's not go there (error messages are formal speech, where emoji aren't as accepted as in informal speech). |
I want to check on my home Linux machine (Mac and Linux may have slightly different colors). I will post a new screenshot when I am back home. |
Btw I opened mypyc/mypyc#696 for mypyc compilation error. |
mypy/util.py
Outdated
class FancyFormatter: | ||
"""Apply color and bold font to terminal output. | ||
|
||
This currently only works on Linus an Mac. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linux and Mac
mypy/util.py
Outdated
if sys.platform not in ('linux', 'darwin'): | ||
self.dummy_term = True | ||
return | ||
if not f_out.isatty() or not f_err.isatty(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a flag to suppress the isatty checking, since our internal scripts all wrap mypy for logging purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, indeed. I however added just an environment variable, it is probably relatively rarely needed thing.
mypy/util.py
Outdated
return out | ||
|
||
def underline_link(self, note: str) -> str: | ||
match = re.search(r'http://\S*', note) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably want https too
I love this |
@gvanrossum I think the new version still works well on dark background: |
IMO the contrast for "note" is too low. But presumably it's easy enough to tweak later, so don't worry about it. Or just leave it black? |
from typing_extensions import Final, Type, Literal | ||
|
||
try: | ||
import curses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using curses which doesn't support Windows well, perhaps we could use colorama instead? If you don't want to change things in this PR I can open one to redo this in colorama if you want (maybe after the daemon changes).
@gvanrossum I actually like it this way. I would keep it and see what people say. @ethanhs I wanted to start from |
No worries. It turns out my love for this is mostly theoretical, since I usually look at mypy errors through various tools (e.g. the PyCharm plugin or Dropbox CI). IIUC curses on Windows is a 3rd party package: https://pypi.org/project/windows-curses/. |
I opened some follow-up issues. I would propose to merge this soon (today) and then iterate later (if there are no objections). |
What is the trick to enable colors for mypy as I am running on MacOS? All the other python tools are able to use colors but mypy is still plain. I did an I tried: |
@ssbarnea please open a new issue describing what terminal you are using and any other relevant information. |
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, however if you think this is worth doing I can refactor the PR in a more principled way.
To illustrate the result this is how the output would look: