MYPY_FORCE_COLOR only colours output on Windows, not macOS/Ubuntu
Bug Report
When using MYPY_FORCE_COLOR (or FORCE_COLOR with master) on GitHub Actions (which is not a tty), colour only shows up for Windows, and not for Ubuntu or macOS.
To Reproduce
Test with a worklflow something like this:
name: Test
on: [push, pull_request, workflow_dispatch]
env:
MYPY_FORCE_COLOR: 1
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: [
"3.7",
"3.10",
]
os: [
windows-latest,
macOS-latest,
ubuntu-latest,
]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install mypy
- name: Test
run: |
mypy test.py
Expected Behavior
Colour output for all three operating systems.
Actual Behavior
Colour output only for Windows:
And not for Ubuntu:
Nor macOS:
For example: https://github.com/hugovk/test/actions/runs/3185917456
Your Environment
- Mypy version used: 0.982
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.7 and 3.10
On Debian, this seems to work fine for mypy main.py | head. Weird that it does not appear as such for GitHub Actions's Ubuntu, which should be similar enough.

Asked a friend since this seems weird to me. Supposedly, GHA doesn't provide TERM, which I suppose is required for curses.setupterm. It does seem that adding TERM fixes this, though.
https://github.com/A5rocks/repro-13817/commit/5f65e7d7b2d2c08ba7f5cc0c789c1b72825dfaf0
It would be nice for mypy to explicitly note that somewhere here:
"""Note that, for ``FORCE_COLOR`` to work, there needs to be a suitable ``TERM`` in the enviroment!"""
https://github.com/python/mypy/blob/ff81a1c7abc91d9984fc73b9f2b9eab198001c8e/mypy/util.py#L511-L516
TERM=ansi would be the MWE for mypy
Maybe mypy should just warn if TERM is not present yet the user wants to force color?
Generally it seems like a bug for MYPY_FORCE_COLOR to not force the color. A user wouldn't be setting this if they didn't want color to be enabled. Maybe a fix like https://github.com/python/mypy/issues/7771#issuecomment-876508529 could be considered