core: improve mypy coverage

This commit is contained in:
Dima Gerasimov 2021-02-17 23:10:37 +00:00 committed by karlicoss
parent 56d5587c20
commit 4ad4f34cda
6 changed files with 60 additions and 43 deletions

View file

@ -6,12 +6,13 @@ E.g. would be nice to propagate the warnings in the UI (it's even a subclass of
'''
import sys
from typing import Optional
import warnings
# just bring in the scope of this module for convenience
from warnings import warn
def _colorize(x: str, color=None) -> str:
def _colorize(x: str, color: Optional[str]=None) -> str:
if color is None:
return x
@ -28,8 +29,7 @@ def _colorize(x: str, color=None) -> str:
# todo log something?
return x
def _warn(message: str, *args, color=None, **kwargs) -> None:
def _warn(message: str, *args, color: Optional[str]=None, **kwargs) -> None:
stacklevel = kwargs.get('stacklevel', 1)
kwargs['stacklevel'] = stacklevel + 2 # +1 for this function, +1 for medium/high wrapper
warnings.warn(_colorize(message, color=color), *args, **kwargs)