diff --git a/src/structlog/_base.py b/src/structlog/_base.py index 25f59277..ffde8bd5 100644 --- a/src/structlog/_base.py +++ b/src/structlog/_base.py @@ -9,7 +9,8 @@ from __future__ import annotations -from typing import Any, Iterable, Mapping, Sequence +from typing import Any, Iterable, Mapping, Sequence, Self +from typing_extensions import Self from structlog.exceptions import DropEvent @@ -62,7 +63,7 @@ def __eq__(self, other: object) -> bool: def __ne__(self, other: object) -> bool: return not self.__eq__(other) - def bind(self, **new_values: Any) -> BoundLoggerBase: + def bind(self, **new_values: Any) -> Self: """ Return a new logger with *new_values* added to the existing ones. """ @@ -72,7 +73,7 @@ def bind(self, **new_values: Any) -> BoundLoggerBase: self._context.__class__(self._context, **new_values), ) - def unbind(self, *keys: str) -> BoundLoggerBase: + def unbind(self, *keys: str) -> Self: """ Return a new logger with *keys* removed from the context. @@ -85,7 +86,7 @@ def unbind(self, *keys: str) -> BoundLoggerBase: return bl - def try_unbind(self, *keys: str) -> BoundLoggerBase: + def try_unbind(self, *keys: str) -> Self: """ Like :meth:`unbind`, but best effort: missing keys are ignored. @@ -97,7 +98,7 @@ def try_unbind(self, *keys: str) -> BoundLoggerBase: return bl - def new(self, **new_values: Any) -> BoundLoggerBase: + def new(self, **new_values: Any) -> Self: """ Clear context and binds *new_values* using `bind`.