core: migrate code to benefit from 3.9 stuff

for now keeping ruff on 3.8 target version, need to sort out modules as well
This commit is contained in:
Dima Gerasimov 2024-10-19 20:19:07 +01:00
parent d1511929a8
commit 721fd98dca
37 changed files with 413 additions and 302 deletions

View file

@ -4,16 +4,17 @@ TODO ideally would be great to replace with some existing solution, or find a be
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
@ -25,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