diff --git a/src/structlog/contextvars.py b/src/structlog/contextvars.py index 75bfec83..835b6264 100644 --- a/src/structlog/contextvars.py +++ b/src/structlog/contextvars.py @@ -24,15 +24,15 @@ from collections.abc import Generator, Mapping from types import FrameType -from typing import Any +from typing import Any, Final import structlog from .typing import BindableLogger, EventDict, WrappedLogger -STRUCTLOG_KEY_PREFIX = "structlog_" -STRUCTLOG_KEY_PREFIX_LEN = len(STRUCTLOG_KEY_PREFIX) +STRUCTLOG_KEY_PREFIX: Final = "structlog_" +STRUCTLOG_KEY_PREFIX_LEN: Final = len(STRUCTLOG_KEY_PREFIX) _ASYNC_CALLING_STACK: contextvars.ContextVar[FrameType] = ( contextvars.ContextVar("_ASYNC_CALLING_STACK") diff --git a/src/structlog/dev.py b/src/structlog/dev.py index 7cef73f6..8ab25d15 100644 --- a/src/structlog/dev.py +++ b/src/structlog/dev.py @@ -468,7 +468,7 @@ def __call__(self, sio: TextIO, exc_info: ExcInfo) -> None: if rich is None: - def rich_traceback(*args, **kw): + def rich_traceback(sio: TextIO, exc_info: ExcInfo) -> None: raise ModuleNotFoundError( "RichTracebackFormatter requires Rich to be installed.", name="rich", diff --git a/src/structlog/processors.py b/src/structlog/processors.py index 20e6e1f2..8eefaecc 100644 --- a/src/structlog/processors.py +++ b/src/structlog/processors.py @@ -24,6 +24,7 @@ from typing import ( Any, ClassVar, + Final, NamedTuple, TextIO, cast, @@ -424,7 +425,7 @@ def __call__( return event_dict -format_exc_info = ExceptionRenderer() +format_exc_info: Final = ExceptionRenderer() """ Replace an ``exc_info`` field with an ``exception`` string field using Python's built-in traceback formatting. @@ -445,7 +446,7 @@ def __call__( features. """ -dict_tracebacks = ExceptionRenderer(ExceptionDictTransformer()) +dict_tracebacks: Final = ExceptionRenderer(ExceptionDictTransformer()) """ Replace an ``exc_info`` field with an ``exception`` field containing structured tracebacks suitable for, e.g., JSON output. diff --git a/src/structlog/threadlocal.py b/src/structlog/threadlocal.py index c712f551..f8dba786 100644 --- a/src/structlog/threadlocal.py +++ b/src/structlog/threadlocal.py @@ -21,7 +21,7 @@ import warnings from collections.abc import Generator, Iterator -from typing import Any, TypeVar +from typing import Any, Final, TypeVar import structlog @@ -44,7 +44,7 @@ def _determine_threadlocal() -> type[Any]: return GreenThreadLocal # pragma: no cover -ThreadLocal = _determine_threadlocal() +ThreadLocal: Final[type] = _determine_threadlocal() def _deprecated() -> None: