KEMBAR78
Update dmypy/client.py: Enable ANSI color codes for windows cmd by wyattscarpenter · Pull Request #19088 · python/mypy · GitHub
Skip to content

Conversation

wyattscarpenter
Copy link
Contributor

I still use windows cmd, and the color codes emitted by dmypy do not work on there. instead printing a bunch of codes like ←[37m ←[39;49;00ms. However, for whatever reason you can fix this simply by calling os.system("") once. (The main mypy program works fine, presumably because it makes an os system call somewhere before it prints.)

I did not write a test of this, as that seems difficult and unnecessary. Instead, I manually tested it, and it worked great.

I still use windows cmd, and the color codes used by dmypy do not work on there. instead printing a bunch of codes like ←[37m    ←[39;49;00ms. However, for whatever reason you can fix this simply by calling os.system("") once. (The main mypy program works fine, presumably because it makes an os system call somewhere before it prints.)
@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in mypy proper we do this with the initialize_win_colors thing in mypy util

@wyattscarpenter
Copy link
Contributor Author

Thanks for the info! However, I've now tried importing and calling initialize_win_colors in various ways, from directly running the kernel32.SetConsoleMode function to instantiating the FancyFormatter class, but it actually seemed to have the opposite effect: it gets rid of the ansi codes, but just displays plain, black-and-white text. Regular mypy continues to work as normal.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay well, was worth a look, thank you! Merging this, but if someone knows what main mypy is doing, would be good to share code

@hauntsaninja hauntsaninja merged commit 644a20c into python:master May 15, 2025
18 checks passed
@wyattscarpenter wyattscarpenter deleted the patch-4 branch May 15, 2025 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants