Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/madsci_common/madsci/common/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import contextlib
import contextvars
from collections.abc import Generator
from typing import Any
from typing import Any, Optional

from madsci.common.types.context_types import MadsciContext

Expand All @@ -17,7 +17,7 @@ class GlobalMadsciContext:
to temporarily override values in the context.
"""

_context: MadsciContext | None = None
_context: Optional[MadsciContext] = None

@classmethod
def get_context(cls) -> MadsciContext:
Expand All @@ -42,7 +42,7 @@ def set_context(cls, context: MadsciContext) -> None:
cls._context = context


_current_madsci_context: contextvars.ContextVar[MadsciContext | None] = (
_current_madsci_context: contextvars.ContextVar[Optional[MadsciContext]] = (
contextvars.ContextVar(
"current_madsci_context",
default=None,
Expand Down
4 changes: 3 additions & 1 deletion src/madsci_common/tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def test_global_context_across_threads() -> None:
new_context = original_context.model_copy()
new_context.lab_server_url = test_url
GlobalMadsciContext.set_context(new_context)
assert str(GlobalMadsciContext.get_context().lab_server_url) == "http://test-lab:8000/"
assert (
str(GlobalMadsciContext.get_context().lab_server_url) == "http://test-lab:8000/"
)

def check_context() -> None:
"""Function to check context in a separate thread."""
Expand Down
Loading