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:
karlicoss 2024-10-19 20:55:09 +01:00 committed by GitHub
parent bc7c3ac253
commit d3f9a8e8b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 515 additions and 404 deletions

View file

@ -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