From 5c3bc79e77e589884ac18b4b21aaf0bf7e4502ba Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Fri, 26 Jan 2024 08:15:05 +0100 Subject: [PATCH] Black 24 --- .pre-commit-config.yaml | 4 ++-- src/structlog/_config.py | 6 +++--- src/structlog/_output.py | 2 ++ src/structlog/contextvars.py | 6 +++--- src/structlog/testing.py | 1 + src/structlog/tracebacks.py | 14 ++++++++------ src/structlog/twisted.py | 5 +++-- src/structlog/typing.py | 15 +++++---------- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 50998706..44c3c3ed 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,12 +4,12 @@ ci: repos: - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.1.0 hooks: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.11 + rev: v0.1.14 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/src/structlog/_config.py b/src/structlog/_config.py index 1bdcaa50..bd6001bd 100644 --- a/src/structlog/_config.py +++ b/src/structlog/_config.py @@ -63,9 +63,9 @@ class _Configuration: default_processors: Iterable[Processor] = _BUILTIN_DEFAULT_PROCESSORS[:] default_context_class: type[Context] = _BUILTIN_DEFAULT_CONTEXT_CLASS default_wrapper_class: Any = _BUILTIN_DEFAULT_WRAPPER_CLASS - logger_factory: Callable[ - ..., WrappedLogger - ] = _BUILTIN_DEFAULT_LOGGER_FACTORY + logger_factory: Callable[..., WrappedLogger] = ( + _BUILTIN_DEFAULT_LOGGER_FACTORY + ) cache_logger_on_first_use: bool = _BUILTIN_CACHE_LOGGER_ON_FIRST_USE diff --git a/src/structlog/_output.py b/src/structlog/_output.py index c0aad4a5..548d5d3d 100644 --- a/src/structlog/_output.py +++ b/src/structlog/_output.py @@ -257,6 +257,7 @@ class BytesLogger: .. versionadded:: 20.2.0 """ + __slots__ = ("_file", "_write", "_flush", "_lock") def __init__(self, file: BinaryIO | None = None): @@ -339,6 +340,7 @@ class BytesLoggerFactory: .. versionadded:: 20.2.0 """ + __slots__ = ("_file",) def __init__(self, file: BinaryIO | None = None): diff --git a/src/structlog/contextvars.py b/src/structlog/contextvars.py index cc531889..6bc79d72 100644 --- a/src/structlog/contextvars.py +++ b/src/structlog/contextvars.py @@ -33,9 +33,9 @@ STRUCTLOG_KEY_PREFIX = "structlog_" STRUCTLOG_KEY_PREFIX_LEN = len(STRUCTLOG_KEY_PREFIX) -_ASYNC_CALLING_STACK: contextvars.ContextVar[ - FrameType -] = contextvars.ContextVar("_ASYNC_CALLING_STACK") +_ASYNC_CALLING_STACK: contextvars.ContextVar[FrameType] = ( + contextvars.ContextVar("_ASYNC_CALLING_STACK") +) # For proper isolation, we have to use a dict of ContextVars instead of a # single ContextVar with a dict. diff --git a/src/structlog/testing.py b/src/structlog/testing.py index 94107bf6..ba0c96f9 100644 --- a/src/structlog/testing.py +++ b/src/structlog/testing.py @@ -199,6 +199,7 @@ class CapturingLoggerFactory: .. versionadded:: 20.2.0 """ + logger: CapturingLogger def __init__(self) -> None: diff --git a/src/structlog/tracebacks.py b/src/structlog/tracebacks.py index 76c6afc3..83a40f27 100644 --- a/src/structlog/tracebacks.py +++ b/src/structlog/tracebacks.py @@ -177,12 +177,14 @@ def extract( filename=filename or "?", lineno=line_no, name=frame_summary.f_code.co_name, - locals={ - key: to_repr(value, max_string=locals_max_string) - for key, value in frame_summary.f_locals.items() - } - if show_locals - else None, + locals=( + { + key: to_repr(value, max_string=locals_max_string) + for key, value in frame_summary.f_locals.items() + } + if show_locals + else None + ), ) append(frame) diff --git a/src/structlog/twisted.py b/src/structlog/twisted.py index f146eadd..411555b1 100644 --- a/src/structlog/twisted.py +++ b/src/structlog/twisted.py @@ -303,8 +303,9 @@ class EventAdapter: def __init__( self, - dictRenderer: Callable[[WrappedLogger, str, EventDict], str] - | None = None, + dictRenderer: ( + Callable[[WrappedLogger, str, EventDict], str] | None + ) = None, ) -> None: self._dictRenderer = dictRenderer or _BUILTIN_DEFAULT_PROCESSORS[-1] diff --git a/src/structlog/typing.py b/src/structlog/typing.py index ed277847..8a07d60a 100644 --- a/src/structlog/typing.py +++ b/src/structlog/typing.py @@ -116,8 +116,7 @@ class ExceptionTransformer(Protocol): .. versionadded:: 22.1.0 """ - def __call__(self, exc_info: ExcInfo) -> Any: - ... + def __call__(self, exc_info: ExcInfo) -> Any: ... @runtime_checkable @@ -131,17 +130,13 @@ class BindableLogger(Protocol): _context: Context - def bind(self, **new_values: Any) -> BindableLogger: - ... + def bind(self, **new_values: Any) -> BindableLogger: ... - def unbind(self, *keys: str) -> BindableLogger: - ... + def unbind(self, *keys: str) -> BindableLogger: ... - def try_unbind(self, *keys: str) -> BindableLogger: - ... + def try_unbind(self, *keys: str) -> BindableLogger: ... - def new(self, **new_values: Any) -> BindableLogger: - ... + def new(self, **new_values: Any) -> BindableLogger: ... class FilteringBoundLogger(BindableLogger, Protocol):