Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch base methods to return Self instead of BoundLoggerBase #658

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading