Skip to content

Commit 3bc3268

Browse files
committed
typing: make BindableLogger._context read-only
Nobody is writing into it except a deprecated threadlocal API.
1 parent 89a903b commit 3bc3268

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

src/structlog/stdlib.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,6 @@ class AsyncBoundLogger:
537537
#: synchronously occasionally.
538538
sync_bl: BoundLogger
539539

540-
# Blatant lie, we use a property for _context. Need this for Protocol
541-
# though.
542-
_context: Context
543-
544540
_executor = None
545541
_bound_logger_factory = BoundLogger
546542

@@ -565,11 +561,9 @@ def __init__(
565561
)
566562
self._loop = asyncio.get_running_loop()
567563

568-
# We have to ignore the type because we've already declared it to ensure
569-
# we're a BindableLogger.
570564
# Instances would've been correctly recognized as such, however the class
571565
# not and we need the class in `structlog.configure()`.
572-
@property # type: ignore[no-redef]
566+
@property
573567
def _context(self) -> Context:
574568
return self.sync_bl._context
575569

src/structlog/threadlocal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def as_immutable(logger: TLLogger) -> TLLogger:
127127
processors=logger._processors, # type: ignore[attr-defined]
128128
context={},
129129
)
130-
bl._context = ctx
130+
bl._context = ctx # type: ignore[misc]
131131

132132
return bl
133133
except AttributeError:

src/structlog/typing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ class BindableLogger(Protocol):
136136
.. versionadded:: 20.2.0
137137
"""
138138

139-
_context: Context
139+
@property
140+
def _context(self) -> Context: ...
140141

141142
def bind(self, **new_values: Any) -> Self: ...
142143

0 commit comments

Comments
 (0)