Skip to content

Commit b06e224

Browse files
style: Apply ruff formatting
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 082491f commit b06e224

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/datajoint/connection.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ def conn(
107107
# Check thread-safe mode
108108
if config.thread_safe:
109109
raise errors.ThreadSafetyError(
110-
"dj.conn() is disabled in thread-safe mode. "
111-
"Use Connection.from_config() with explicit configuration."
110+
"dj.conn() is disabled in thread-safe mode. " "Use Connection.from_config() with explicit configuration."
112111
)
113112

114113
if not hasattr(conn, "connection") or reset:
@@ -376,13 +375,11 @@ def from_config(
376375
# Validate required fields
377376
if effective_user is None:
378377
raise errors.DataJointError(
379-
"Database user is required. "
380-
"Provide user= argument or include 'user' in config dict."
378+
"Database user is required. " "Provide user= argument or include 'user' in config dict."
381379
)
382380
if effective_password is None:
383381
raise errors.DataJointError(
384-
"Database password is required. "
385-
"Provide password= argument or include 'password' in config dict."
382+
"Database password is required. " "Provide password= argument or include 'password' in config dict."
386383
)
387384

388385
# Create connection with explicit backend parameter

src/datajoint/settings.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,7 @@ def __setattr__(self, name: str, value: Any) -> None:
937937
try:
938938
current = object.__getattribute__(self, "thread_safe")
939939
if current and not value:
940-
raise ThreadSafetyError(
941-
"Cannot disable thread-safe mode once enabled."
942-
)
940+
raise ThreadSafetyError("Cannot disable thread-safe mode once enabled.")
943941
except AttributeError:
944942
pass # First time setting during __init__
945943
return object.__setattr__(self, name, value)
@@ -984,9 +982,7 @@ def __setitem__(self, key: str, value: Any) -> None:
984982
# Special handling for thread_safe: allow setting but enforce one-way
985983
if key == "thread_safe":
986984
if self.thread_safe and not value:
987-
raise ThreadSafetyError(
988-
"Cannot disable thread-safe mode once enabled."
989-
)
985+
raise ThreadSafetyError("Cannot disable thread-safe mode once enabled.")
990986
self.thread_safe = value
991987
return
992988

tests/unit/test_settings.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,26 +877,30 @@ class TestThreadSafeMode:
877877
def reset_thread_safe(self):
878878
"""Reset thread_safe before and after each test."""
879879
from datajoint import settings
880+
880881
object.__setattr__(settings.config, "thread_safe", False)
881882
yield
882883
object.__setattr__(settings.config, "thread_safe", False)
883884

884885
def test_thread_safe_default_false(self):
885886
"""Thread-safe mode is disabled by default."""
886887
from datajoint.settings import Config
888+
887889
cfg = Config()
888890
assert cfg.thread_safe is False
889891

890892
def test_thread_safe_can_be_enabled(self):
891893
"""Thread-safe mode can be enabled."""
892894
from datajoint import settings
895+
893896
settings.config.thread_safe = True
894897
assert settings.config.thread_safe is True
895898

896899
def test_thread_safe_one_way_lock(self):
897900
"""Once enabled, thread_safe cannot be disabled."""
898901
from datajoint import settings
899902
from datajoint.errors import ThreadSafetyError
903+
900904
settings.config.thread_safe = True
901905
with pytest.raises(ThreadSafetyError, match="Cannot disable"):
902906
settings.config.thread_safe = False
@@ -905,6 +909,7 @@ def test_getitem_blocked_in_thread_safe_mode(self):
905909
"""Dict-like config access raises ThreadSafetyError in thread-safe mode."""
906910
from datajoint import settings
907911
from datajoint.errors import ThreadSafetyError
912+
908913
settings.config.thread_safe = True
909914
with pytest.raises(ThreadSafetyError, match="Global config is inaccessible"):
910915
_ = settings.config["database.host"]
@@ -913,6 +918,7 @@ def test_setitem_blocked_in_thread_safe_mode(self):
913918
"""Dict-like config modification raises ThreadSafetyError in thread-safe mode."""
914919
from datajoint import settings
915920
from datajoint.errors import ThreadSafetyError
921+
916922
settings.config.thread_safe = True
917923
with pytest.raises(ThreadSafetyError, match="Global config is inaccessible"):
918924
settings.config["database.host"] = "newhost"
@@ -921,13 +927,15 @@ def test_attribute_access_blocked_in_thread_safe_mode(self):
921927
"""Attribute access is also blocked in thread-safe mode."""
922928
from datajoint import settings
923929
from datajoint.errors import ThreadSafetyError
930+
924931
settings.config.thread_safe = True
925932
with pytest.raises(ThreadSafetyError, match="Global config is inaccessible"):
926933
_ = settings.config.database
927934

928935
def test_thread_safe_always_readable(self):
929936
"""The thread_safe setting itself is always readable."""
930937
from datajoint import settings
938+
931939
settings.config.thread_safe = True
932940
# Should not raise
933941
assert settings.config.thread_safe is True
@@ -936,6 +944,7 @@ def test_thread_safe_always_readable(self):
936944
def test_private_attributes_accessible(self):
937945
"""Private attributes (starting with _) are accessible in thread-safe mode."""
938946
from datajoint import settings
947+
939948
settings.config.thread_safe = True
940949
# Private attributes should be accessible for internal operations
941950
_ = settings.config._config_path # Should not raise

0 commit comments

Comments
 (0)