Skip to content

Commit 9d4e23f

Browse files
committed
style: fix linter issues
- Remove unused *args parameter in test function - Fix formatting issues from linter
1 parent e05e719 commit 9d4e23f

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

src/replicate/_module_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def _use(ref, *, hint=None, streaming=False, use_async=False, **kwargs):
9595

9696
return use(lambda: AsyncReplicate(), ref, hint=hint, streaming=streaming, **kwargs)
9797
from .lib._predictions_use import use
98+
9899
return use(_load_client, ref, hint=hint, streaming=streaming, **kwargs)
99100

100101
run = _run

src/replicate/lib/_predictions_use.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -879,10 +879,8 @@ def use(
879879
pass
880880

881881
# Determine if this is async by checking the type
882-
is_async = isinstance(client, AsyncClient) or (
883-
callable(client) and isinstance(client(), AsyncClient)
884-
)
885-
882+
is_async = isinstance(client, AsyncClient) or (callable(client) and isinstance(client(), AsyncClient))
883+
886884
if is_async:
887885
# TODO: Fix type inference for AsyncFunction return type
888886
return AsyncFunction(client, str(ref), streaming=streaming) # type: ignore[return-value]

tests/test_simple_lazy.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,74 @@
11
"""Simple test showing the lazy client fix works."""
22

33
import os
4-
from unittest.mock import MagicMock, patch
54
import sys
5+
from unittest.mock import MagicMock, patch
66

77

88
def test_use_does_not_create_client_immediately():
99
"""Test that replicate.use() does not create a client until the model is called."""
10-
sys.path.insert(0, 'src')
11-
10+
sys.path.insert(0, "src")
11+
1212
# Clear any existing token to simulate the original error condition
1313
with patch.dict(os.environ, {}, clear=True):
1414
with patch.dict(sys.modules, {"cog": None}):
1515
try:
1616
import replicate
17+
1718
# This should work now - no client is created yet
1819
model = replicate.use("test/model")
19-
20+
2021
# Verify we got a Function object back
2122
from replicate.lib._predictions_use import Function
23+
2224
assert isinstance(model, Function)
2325
print("✓ replicate.use() works without immediate client creation")
24-
26+
2527
# Verify the client is stored as a callable (factory function)
2628
assert callable(model._client)
2729
print("✓ Client is stored as factory function")
28-
30+
2931
except Exception as e:
3032
print(f"✗ Test failed: {e}")
3133
raise
3234

3335

3436
def test_client_created_when_model_called():
3537
"""Test that the client is created when the model is called."""
36-
sys.path.insert(0, 'src')
37-
38+
sys.path.insert(0, "src")
39+
3840
# Mock the client creation to track when it happens
3941
created_clients = []
40-
41-
def track_client_creation(*args, **kwargs):
42+
43+
def track_client_creation(**kwargs):
4244
client = MagicMock()
43-
client.bearer_token = kwargs.get('bearer_token', 'no-token')
45+
client.bearer_token = kwargs.get("bearer_token", "no-token")
4446
created_clients.append(client)
4547
return client
46-
48+
4749
# Mock cog to provide a token
4850
mock_scope = MagicMock()
4951
mock_scope.context.items.return_value = [("REPLICATE_API_TOKEN", "cog-token")]
5052
mock_cog = MagicMock()
5153
mock_cog.current_scope.return_value = mock_scope
52-
54+
5355
with patch.dict(os.environ, {}, clear=True):
5456
with patch.dict(sys.modules, {"cog": mock_cog}):
55-
with patch('replicate._module_client._ModuleClient', side_effect=track_client_creation):
57+
with patch("replicate._module_client._ModuleClient", side_effect=track_client_creation):
5658
import replicate
57-
59+
5860
# Create model function - should not create client yet
5961
model = replicate.use("test/model")
6062
assert len(created_clients) == 0
6163
print("✓ No client created when use() is called")
62-
64+
6365
# Try to call the model - this should create a client
6466
try:
6567
model(prompt="test")
6668
except Exception:
6769
# Expected to fail due to mocking, but client should be created
6870
pass
69-
71+
7072
# Verify client was created with the cog token
7173
assert len(created_clients) == 1
7274
assert created_clients[0].bearer_token == "cog-token"
@@ -76,4 +78,4 @@ def track_client_creation(*args, **kwargs):
7678
if __name__ == "__main__":
7779
test_use_does_not_create_client_immediately()
7880
test_client_created_when_model_called()
79-
print("\n✓ All tests passed! The lazy client fix works correctly.")
81+
print("\n✓ All tests passed! The lazy client fix works correctly.")

0 commit comments

Comments
 (0)