Skip to content

Commit

Permalink
Switch base methods to return Self instead of BoundLoggerBase
Browse files Browse the repository at this point in the history
  • Loading branch information
aThorp96 committed Oct 3, 2024
1 parent 9e9711c commit 3f682ca
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/structlog/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
"""
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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`.
Expand Down

0 comments on commit 3f682ca

Please # to comment.