core: improve mypy coverage
This commit is contained in:
parent
56d5587c20
commit
4ad4f34cda
6 changed files with 60 additions and 43 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue