Skip to content

Update dmypy/client.py: Enable ANSI color codes for windows cmd #19088

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

Merged
merged 1 commit into from
May 15, 2025

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.)
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