Skip to content

Commit fee09ac

Browse files
committed
fix: add pyright ignores for deprecated function usage in tests and internal calls
1 parent 621162a commit fee09ac

File tree

5 files changed

+24
-30
lines changed

5 files changed

+24
-30
lines changed

src/replicate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def _reset_client() -> None: # type: ignore[reportUnusedFunction]
253253
use as use,
254254
files as files,
255255
models as models,
256-
stream as stream,
256+
stream as stream, # pyright: ignore[reportDeprecated]
257257
account as account,
258258
hardware as hardware,
259259
webhooks as webhooks,

src/replicate/_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def stream(
350350
"""
351351
from .lib._stream import stream as _stream
352352

353-
return _stream(type(self), ref, input=input) # type: ignore[return-value, arg-type]
353+
return _stream(type(self), ref, input=input) # type: ignore[return-value, arg-type] # pyright: ignore[reportDeprecated]
354354

355355
def copy(
356356
self,
@@ -757,7 +757,7 @@ async def stream(
757757
"""
758758
from .lib._stream import stream as _stream
759759

760-
return _stream(type(self), ref, input=input) # type: ignore[return-value, arg-type]
760+
return _stream(type(self), ref, input=input) # type: ignore[return-value, arg-type] # pyright: ignore[reportDeprecated]
761761

762762
def copy(
763763
self,

src/replicate/_module_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __load__(self) -> PredictionsResource:
8282
__client: Replicate = cast(Replicate, {})
8383
run = __client.run
8484
use = __client.use
85-
stream = __client.stream
85+
stream = __client.stream # pyright: ignore[reportDeprecated]
8686
else:
8787

8888
def _run(*args, **kwargs):

src/replicate/lib/_stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def stream(
9292
)
9393

9494
# Use the existing use() function with streaming=True
95-
model = use(client, ref, streaming=True)
95+
model = use(client, ref, streaming=True) # pyright: ignore[reportUnknownVariableType]
9696

9797
# Call the model with the input
9898
return model(**input) # type: ignore[return-value]

tests/lib/test_stream.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
def test_stream_shows_deprecation_warning():
1515
"""Test that stream() shows a deprecation warning."""
16-
with patch("replicate.lib._predictions_use.use") as mock_use:
16+
with patch("replicate.lib._stream.use") as mock_use:
1717
# Create a mock function that returns an iterator
1818
mock_function = Mock()
1919
mock_function.return_value = iter(["Hello", " ", "world"])
@@ -24,8 +24,8 @@ def test_stream_shows_deprecation_warning():
2424
warnings.simplefilter("always")
2525

2626
client = Replicate(bearer_token="test-token")
27-
result = list(
28-
client.stream(
27+
_ = list( # pyright: ignore[reportDeprecated]
28+
client.stream( # pyright: ignore[reportDeprecated]
2929
"anthropic/claude-4.5-sonnet",
3030
input={"prompt": "Hello"},
3131
)
@@ -39,16 +39,13 @@ def test_stream_shows_deprecation_warning():
3939
# Verify the @deprecated decorator message appears
4040
# (there may be multiple warnings from different decorator levels)
4141
messages = [str(warning.message) for warning in deprecation_warnings]
42-
expected_message = (
43-
"replicate.stream() is deprecated. "
44-
"Use replicate.use() with streaming=True instead"
45-
)
42+
expected_message = "replicate.stream() is deprecated. Use replicate.use() with streaming=True instead"
4643
assert expected_message in messages
4744

4845

4946
def test_stream_calls_use_with_streaming_true():
5047
"""Test that stream() internally calls use() with streaming=True."""
51-
with patch("replicate.lib._predictions_use.use") as mock_use:
48+
with patch("replicate.lib._stream.use") as mock_use:
5249
# Create a mock function that returns an iterator
5350
mock_function = Mock()
5451
mock_function.return_value = iter(["Hello", " ", "world"])
@@ -59,8 +56,8 @@ def test_stream_calls_use_with_streaming_true():
5956
# Suppress deprecation warnings for this test
6057
with warnings.catch_warnings():
6158
warnings.simplefilter("ignore", DeprecationWarning)
62-
result = list(
63-
client.stream(
59+
_ = list( # pyright: ignore[reportDeprecated]
60+
client.stream( # pyright: ignore[reportDeprecated]
6461
"anthropic/claude-4.5-sonnet",
6562
input={"prompt": "Hello"},
6663
)
@@ -70,15 +67,15 @@ def test_stream_calls_use_with_streaming_true():
7067
mock_use.assert_called_once()
7168
call_args = mock_use.call_args
7269
assert call_args.kwargs["streaming"] is True
73-
assert call_args.args[1] == "anthropic/claude-4.5-sonnet"
70+
assert call_args.args[0] == "anthropic/claude-4.5-sonnet"
7471

7572
# Verify the mock function was called with the input
7673
mock_function.assert_called_once_with(prompt="Hello")
7774

7875

7976
def test_stream_returns_iterator():
8077
"""Test that stream() returns an iterator of strings."""
81-
with patch("replicate.lib._predictions_use.use") as mock_use:
78+
with patch("replicate.lib._stream.use") as mock_use:
8279
# Create a mock function that returns an iterator
8380
mock_function = Mock()
8481
mock_function.return_value = iter(["Hello", " ", "world", "!"])
@@ -89,7 +86,7 @@ def test_stream_returns_iterator():
8986
# Suppress deprecation warnings for this test
9087
with warnings.catch_warnings():
9188
warnings.simplefilter("ignore", DeprecationWarning)
92-
result = client.stream(
89+
result = client.stream( # pyright: ignore[reportDeprecated]
9390
"anthropic/claude-4.5-sonnet",
9491
input={"prompt": "Say hello"},
9592
)
@@ -104,7 +101,7 @@ def test_stream_returns_iterator():
104101

105102
def test_stream_works_same_as_use_with_streaming():
106103
"""Test that stream() produces the same output as use() with streaming=True."""
107-
with patch("replicate.lib._predictions_use.use") as mock_use:
104+
with patch("replicate.lib._stream.use") as mock_use:
108105
# Create a mock function that returns an iterator
109106
mock_function = Mock()
110107
expected_output = ["Test", " ", "output"]
@@ -117,7 +114,7 @@ def test_stream_works_same_as_use_with_streaming():
117114
with warnings.catch_warnings():
118115
warnings.simplefilter("ignore", DeprecationWarning)
119116
stream_output = list(
120-
client.stream(
117+
client.stream( # pyright: ignore[reportDeprecated]
121118
"test-model",
122119
input={"prompt": "test"},
123120
)
@@ -136,7 +133,7 @@ def test_stream_works_same_as_use_with_streaming():
136133

137134
def test_module_level_stream_function():
138135
"""Test that the module-level replicate.stream() function works."""
139-
with patch("replicate.lib._predictions_use.use") as mock_use:
136+
with patch("replicate.lib._stream.use") as mock_use:
140137
# Create a mock function that returns an iterator
141138
mock_function = Mock()
142139
mock_function.return_value = iter(["a", "b", "c"])
@@ -146,7 +143,7 @@ def test_module_level_stream_function():
146143
with warnings.catch_warnings():
147144
warnings.simplefilter("ignore", DeprecationWarning)
148145
result = list(
149-
replicate.stream(
146+
replicate.stream( # pyright: ignore[reportDeprecated]
150147
"test-model",
151148
input={"prompt": "test"},
152149
)
@@ -163,7 +160,7 @@ def test_module_level_stream_function():
163160
@pytest.mark.asyncio
164161
async def test_async_stream_shows_deprecation_warning():
165162
"""Test that async stream() shows a deprecation warning."""
166-
with patch("replicate.lib._predictions_use.use") as mock_use:
163+
with patch("replicate.lib._stream.use") as mock_use:
167164
# Create a mock async function that returns an async iterator
168165
async def async_gen():
169166
yield "Hello"
@@ -180,7 +177,7 @@ async def async_gen():
180177

181178
client = AsyncReplicate(bearer_token="test-token")
182179
result = []
183-
async for item in await client.stream(
180+
async for item in await client.stream( # pyright: ignore[reportDeprecated]
184181
"anthropic/claude-4.5-sonnet",
185182
input={"prompt": "Hello"},
186183
):
@@ -193,16 +190,13 @@ async def async_gen():
193190

194191
# Verify the @deprecated decorator message appears
195192
messages = [str(warning.message) for warning in deprecation_warnings]
196-
expected_message = (
197-
"replicate.stream() is deprecated. "
198-
"Use replicate.use() with streaming=True instead"
199-
)
193+
expected_message = "replicate.stream() is deprecated. Use replicate.use() with streaming=True instead"
200194
assert expected_message in messages
201195

202196

203197
def test_deprecation_message_includes_example():
204198
"""Test that the detailed deprecation message includes a helpful example."""
205-
with patch("replicate.lib._predictions_use.use") as mock_use:
199+
with patch("replicate.lib._stream.use") as mock_use:
206200
mock_function = Mock()
207201
mock_function.return_value = iter([])
208202
mock_use.return_value = mock_function
@@ -212,7 +206,7 @@ def test_deprecation_message_includes_example():
212206
with warnings.catch_warnings(record=True) as w:
213207
warnings.simplefilter("always")
214208
list(
215-
client.stream(
209+
client.stream( # pyright: ignore[reportDeprecated]
216210
"anthropic/claude-4.5-sonnet",
217211
input={"prompt": "Hello", "max_tokens": 100},
218212
)

0 commit comments

Comments
 (0)