chore(pre-commit): Add pyupgrade and pycln hooks (#24197)

This commit is contained in:
John Bodley
2023-06-01 12:01:10 -07:00
committed by GitHub
parent 7d7ce63970
commit a4d5d7c6b9
448 changed files with 3084 additions and 3305 deletions

View File

@@ -29,7 +29,7 @@ from inspect import (
Signature,
)
from logging import Logger
from typing import Any, Callable, cast, Optional, Type, Union
from typing import Any, Callable, cast, Union
_DEFAULT_ENTER_MSG_PREFIX = "enter to "
_DEFAULT_ENTER_MSG_SUFFIX = ""
@@ -48,11 +48,11 @@ empty_and_none = {Signature.empty, "None"}
Function = Callable[..., Any]
Decorated = Union[Type[Any], Function]
Decorated = Union[type[Any], Function]
def log(
decorated: Optional[Decorated] = None,
decorated: Decorated | None = None,
*,
prefix_enter_msg: str = _DEFAULT_ENTER_MSG_PREFIX,
suffix_enter_msg: str = _DEFAULT_ENTER_MSG_SUFFIX,
@@ -85,11 +85,11 @@ def _make_decorator(
def decorator(decorated: Decorated):
decorated_logger = _get_logger(decorated)
def decorator_class(clazz: Type[Any]) -> Type[Any]:
def decorator_class(clazz: type[Any]) -> type[Any]:
_decorate_class_members_with_logs(clazz)
return clazz
def _decorate_class_members_with_logs(clazz: Type[Any]) -> None:
def _decorate_class_members_with_logs(clazz: type[Any]) -> None:
members = getmembers(
clazz, predicate=lambda val: ismethod(val) or isfunction(val)
)
@@ -160,7 +160,7 @@ def _make_decorator(
return _wrapper_func
if isclass(decorated):
return decorator_class(cast(Type[Any], decorated))
return decorator_class(cast(type[Any], decorated))
return decorator_func(cast(Function, decorated))
return decorator