Skip to content

Commit 67c03c3

Browse files
authored
Merge pull request pypa#9382 from jdufresne/colorama-import
Remove outdated mypy workaround for colorama import
2 parents adca454 + 9109e1c commit 67c03c3

File tree

2 files changed

+3
-23
lines changed

2 files changed

+3
-23
lines changed

news/a9950589-8b92-4ec1-a3a1-a6657cf6fd5b.trivial.rst

Whitespace-only changes.

src/pip/_internal/utils/logging.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,11 @@
2020

2121

2222
try:
23-
# Use "import as" and set colorama in the else clause to avoid mypy
24-
# errors and get the following correct revealed type for colorama:
25-
# `Union[_importlib_modulespec.ModuleType, None]`
26-
# Otherwise, we get an error like the following in the except block:
27-
# > Incompatible types in assignment (expression has type "None",
28-
# variable has type Module)
29-
# TODO: eliminate the need to use "import as" once mypy addresses some
30-
# of its issues with conditional imports. Here is an umbrella issue:
31-
# https://github.com/python/mypy/issues/1297
32-
from pip._vendor import colorama as _colorama
23+
from pip._vendor import colorama
3324
# Lots of different errors can come from this, including SystemError and
3425
# ImportError.
3526
except Exception:
3627
colorama = None
37-
else:
38-
# Import Fore explicitly rather than accessing below as colorama.Fore
39-
# to avoid the following error running mypy:
40-
# > Module has no attribute "Fore"
41-
# TODO: eliminate the need to import Fore once mypy addresses some of its
42-
# issues with conditional imports. This particular case could be an
43-
# instance of the following issue (but also see the umbrella issue above):
44-
# https://github.com/python/mypy/issues/3500
45-
from pip._vendor.colorama import Fore
46-
47-
colorama = _colorama
4828

4929

5030
_log_state = threading.local()
@@ -162,8 +142,8 @@ class ColorizedStreamHandler(logging.StreamHandler):
162142
if colorama:
163143
COLORS = [
164144
# This needs to be in order from highest logging level to lowest.
165-
(logging.ERROR, _color_wrap(Fore.RED)),
166-
(logging.WARNING, _color_wrap(Fore.YELLOW)),
145+
(logging.ERROR, _color_wrap(colorama.Fore.RED)),
146+
(logging.WARNING, _color_wrap(colorama.Fore.YELLOW)),
167147
]
168148
else:
169149
COLORS = []

0 commit comments

Comments
 (0)