mirror of https://github.com/pypa/pip
Remove outdated mypy workaround for colorama import
This commit is contained in:
parent
97b2b0cdee
commit
9109e1ccde
|
@ -20,31 +20,11 @@ except ImportError:
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Use "import as" and set colorama in the else clause to avoid mypy
|
from pip._vendor import colorama
|
||||||
# errors and get the following correct revealed type for colorama:
|
|
||||||
# `Union[_importlib_modulespec.ModuleType, None]`
|
|
||||||
# Otherwise, we get an error like the following in the except block:
|
|
||||||
# > Incompatible types in assignment (expression has type "None",
|
|
||||||
# variable has type Module)
|
|
||||||
# TODO: eliminate the need to use "import as" once mypy addresses some
|
|
||||||
# of its issues with conditional imports. Here is an umbrella issue:
|
|
||||||
# https://github.com/python/mypy/issues/1297
|
|
||||||
from pip._vendor import colorama as _colorama
|
|
||||||
# Lots of different errors can come from this, including SystemError and
|
# Lots of different errors can come from this, including SystemError and
|
||||||
# ImportError.
|
# ImportError.
|
||||||
except Exception:
|
except Exception:
|
||||||
colorama = None
|
colorama = None
|
||||||
else:
|
|
||||||
# Import Fore explicitly rather than accessing below as colorama.Fore
|
|
||||||
# to avoid the following error running mypy:
|
|
||||||
# > Module has no attribute "Fore"
|
|
||||||
# TODO: eliminate the need to import Fore once mypy addresses some of its
|
|
||||||
# issues with conditional imports. This particular case could be an
|
|
||||||
# instance of the following issue (but also see the umbrella issue above):
|
|
||||||
# https://github.com/python/mypy/issues/3500
|
|
||||||
from pip._vendor.colorama import Fore
|
|
||||||
|
|
||||||
colorama = _colorama
|
|
||||||
|
|
||||||
|
|
||||||
_log_state = threading.local()
|
_log_state = threading.local()
|
||||||
|
@ -162,8 +142,8 @@ class ColorizedStreamHandler(logging.StreamHandler):
|
||||||
if colorama:
|
if colorama:
|
||||||
COLORS = [
|
COLORS = [
|
||||||
# This needs to be in order from highest logging level to lowest.
|
# This needs to be in order from highest logging level to lowest.
|
||||||
(logging.ERROR, _color_wrap(Fore.RED)),
|
(logging.ERROR, _color_wrap(colorama.Fore.RED)),
|
||||||
(logging.WARNING, _color_wrap(Fore.YELLOW)),
|
(logging.WARNING, _color_wrap(colorama.Fore.YELLOW)),
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
COLORS = []
|
COLORS = []
|
||||||
|
|
Loading…
Reference in New Issue