Repository navigation
Add support for nicer error output - #7425
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. |
| class FancyFormatter: | ||
| """Apply color and bold font to terminal output. | ||
|
|
||
| This currently only works on Linus an Mac. |
| 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.
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.
Yes, indeed. I however added just an environment variable, it is probably relatively rarely needed thing.
| return out | ||
|
|
||
| def underline_link(self, note: str) -> str: | ||
| match = re.search(r'http://\S*', note) |
There was a problem hiding this comment.
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.
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: