|
20 | 20 |
|
21 | 21 |
|
22 | 22 | 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 |
33 | 24 | # Lots of different errors can come from this, including SystemError and
|
34 | 25 | # ImportError.
|
35 | 26 | except Exception:
|
36 | 27 | 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 |
48 | 28 |
|
49 | 29 |
|
50 | 30 | _log_state = threading.local()
|
@@ -162,8 +142,8 @@ class ColorizedStreamHandler(logging.StreamHandler):
|
162 | 142 | if colorama:
|
163 | 143 | COLORS = [
|
164 | 144 | # 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)), |
167 | 147 | ]
|
168 | 148 | else:
|
169 | 149 | COLORS = []
|
|
0 commit comments