tartley / colorama

Simple cross-platform colored terminal text in Python
BSD 3-Clause "New" or "Revised" License
3.51k stars 249 forks source link

merge types-colorama #379

Open jmelahman opened 1 year ago

jmelahman commented 1 year ago

Description

Adds types that I believe are fully compliant with PEP-561. Borrows heavily from types-colorama. Includes slight modifications to those to please stubtest and adds type stubs for colorama/tests/.

I tried my best to please stubtest, but it did not like winterm.pyi mostly being gated on sys.platform == 'win32', but that seems informative and desired, and I couldn't find a mechanism within stubtest to ignore these errors without --ignore-missing-stub hence its inclusion in tox.ini.

Closes https://github.com/tartley/colorama/issues/206

How this was tested

You can test the correctness of the stubs with,

tox -e mypy
$ tox -e mypy
...
mypy: install_package> python -I -m pip install --force-reinstall --no-deps /home/jamison/code/third_party/colorama/.tox/.tmp/package/2/colorama-0.4.7.dev1.tar.gz
mypy: commands[0]> mypy .
Success: no issues found in 13 source files
mypy: commands[1]> python -m mypy.stubtest --ignore-missing-stub colorama
Success: no issues found in 13 modules
.pkg: _exit> python /usr/lib/python3.11/site-packages/pyproject_api/_backend.py True hatchling.build
  mypy: OK (8.11=setup[6.47]+cmd[0.13,1.50] seconds)
  congratulations :) (8.16 seconds)

I tested this e2e as follows (outside of the repository),

$ python -m venv venv

$ ./venv/bin/python -m pip install mypy==1.4.1

$ ./venv/bin/python -m mypy <(echo "import colorama")
/dev/fd/63:1: error: Library stubs not installed for "colorama"  [import]
    import colorama
    ^
/dev/fd/63:1: note: Hint: "python3 -m pip install types-colorama"
/dev/fd/63:1: note: (or run "mypy --install-types" to install all missing stub packages)
/dev/fd/63:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

$ ./venv/bin/python -m pip install -e /path/to/colorama
...
Successfully installed colorama-0.4.7.dev1

$ ./venv/bin/python -m mypy <(echo "import colorama")
Success: no issues found in 1 source file

Confirmed existing compatibility,

$ tox 
...
  py27: OK (7.78=setup[7.73]+cmd[0.06] seconds)
  py37: OK (7.27=setup[7.20]+cmd[0.06] seconds)
  py38: OK (6.74=setup[6.61]+cmd[0.13] seconds)
  py39: OK (7.40=setup[7.28]+cmd[0.12] seconds)
  py310: OK (7.23=setup[7.12]+cmd[0.11] seconds)
  pypy: OK (10.44=setup[10.24]+cmd[0.21] seconds)
  pypy3: OK (11.89=setup[11.17]+cmd[0.71] seconds)
  congratulations :) (58.80 seconds)