From e03cd89f104e6d8d606fdd71617318766b2889f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Hordy=C5=84ski?= Date: Fri, 29 Nov 2024 12:53:38 +0100 Subject: [PATCH 1/3] fix: context var using default mutable value --- packages/ragbits-core/src/ragbits/core/audit/base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/ragbits-core/src/ragbits/core/audit/base.py b/packages/ragbits-core/src/ragbits/core/audit/base.py index d0e9f7fd..71f8e078 100644 --- a/packages/ragbits-core/src/ragbits/core/audit/base.py +++ b/packages/ragbits-core/src/ragbits/core/audit/base.py @@ -13,12 +13,16 @@ class TraceHandler(Generic[SpanT], ABC): Base class for all trace handlers. """ + _spans: ContextVar[list[SpanT]] + def __init__(self) -> None: """ Constructs a new TraceHandler instance. """ super().__init__() - self._spans = ContextVar[list[SpanT]]("_spans", default=[]) + _spans = ContextVar[list[SpanT] | None]("_spans", default=None) + _spans.set([]) + self._spans = _spans # type: ignore @abstractmethod def start(self, name: str, inputs: dict, current_span: SpanT | None = None) -> SpanT: From 30fb5362c5fbbd75e91bc17e0e830ff0d7064839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Hordy=C5=84ski?= Date: Fri, 29 Nov 2024 13:07:13 +0100 Subject: [PATCH 2/3] better typing --- packages/ragbits-core/src/ragbits/core/audit/base.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/ragbits-core/src/ragbits/core/audit/base.py b/packages/ragbits-core/src/ragbits/core/audit/base.py index 71f8e078..732685c3 100644 --- a/packages/ragbits-core/src/ragbits/core/audit/base.py +++ b/packages/ragbits-core/src/ragbits/core/audit/base.py @@ -20,9 +20,8 @@ def __init__(self) -> None: Constructs a new TraceHandler instance. """ super().__init__() - _spans = ContextVar[list[SpanT] | None]("_spans", default=None) - _spans.set([]) - self._spans = _spans # type: ignore + self._spans = ContextVar[list[SpanT]]("_spans") + self._spans.set([]) @abstractmethod def start(self, name: str, inputs: dict, current_span: SpanT | None = None) -> SpanT: From 4acbb0c552738ca9359b93cc8c53e875a809f055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Hordy=C5=84ski?= Date: Fri, 29 Nov 2024 13:11:36 +0100 Subject: [PATCH 3/3] remove extra typing --- packages/ragbits-core/src/ragbits/core/audit/base.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/ragbits-core/src/ragbits/core/audit/base.py b/packages/ragbits-core/src/ragbits/core/audit/base.py index 732685c3..b8f1a745 100644 --- a/packages/ragbits-core/src/ragbits/core/audit/base.py +++ b/packages/ragbits-core/src/ragbits/core/audit/base.py @@ -13,8 +13,6 @@ class TraceHandler(Generic[SpanT], ABC): Base class for all trace handlers. """ - _spans: ContextVar[list[SpanT]] - def __init__(self) -> None: """ Constructs a new TraceHandler instance.