core: migrate code to benefit from 3.9 stuff (#401)
for now keeping ruff on 3.8 target version, need to sort out modules as well
This commit is contained in:
parent
bc7c3ac253
commit
d3f9a8e8b6
43 changed files with 515 additions and 404 deletions
|
@ -5,14 +5,16 @@ since who looks at the terminal output?
|
|||
E.g. would be nice to propagate the warnings in the UI (it's even a subclass of Exception!)
|
||||
'''
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import warnings
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import click
|
||||
|
||||
|
||||
def _colorize(x: str, color: Optional[str] = None) -> str:
|
||||
def _colorize(x: str, color: str | None = None) -> str:
|
||||
if color is None:
|
||||
return x
|
||||
|
||||
|
@ -24,7 +26,7 @@ def _colorize(x: str, color: Optional[str] = None) -> str:
|
|||
return click.style(x, fg=color)
|
||||
|
||||
|
||||
def _warn(message: str, *args, color: Optional[str] = None, **kwargs) -> None:
|
||||
def _warn(message: str, *args, color: str | None = 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) # noqa: B028
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue