logging: Add a _FilterProtocol type to Filterer.addFilter() filter argument. (#11018)

This commit is contained in:
Jens Tröger
2023-11-14 19:14:19 +10:00
committed by GitHub
parent c88e099e80
commit 590f89b594

View File

@@ -7,7 +7,7 @@ from re import Pattern
from string import Template
from time import struct_time
from types import FrameType, TracebackType
from typing import Any, ClassVar, Generic, TextIO, TypeVar, overload
from typing import Any, ClassVar, Generic, Protocol, TextIO, TypeVar, overload
from typing_extensions import Literal, Self, TypeAlias
if sys.version_info >= (3, 11):
@@ -66,10 +66,20 @@ if sys.version_info >= (3, 12):
_SysExcInfoType: TypeAlias = tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None]
_ExcInfoType: TypeAlias = None | bool | _SysExcInfoType | BaseException
_ArgsType: TypeAlias = tuple[object, ...] | Mapping[str, object]
_FilterType: TypeAlias = Filter | Callable[[LogRecord], bool]
_Level: TypeAlias = int | str
_FormatStyle: TypeAlias = Literal["%", "{", "$"]
if sys.version_info >= (3, 12):
class _SupportsFilter(Protocol):
def filter(self, __record: LogRecord) -> bool | LogRecord: ...
_FilterType: TypeAlias = Filter | Callable[[LogRecord], bool | LogRecord] | _SupportsFilter
else:
class _SupportsFilter(Protocol):
def filter(self, __record: LogRecord) -> bool: ...
_FilterType: TypeAlias = Filter | Callable[[LogRecord], bool] | _SupportsFilter
raiseExceptions: bool
logThreads: bool
logMultiprocessing: bool