Skip to content

Commit c434635

Browse files
committed
Fix deprecated asyncio.get_event_loop() and PendingDeprecationWarning
- Replace asyncio.get_event_loop() with asyncio.get_running_loop() in files.py (lines 277 and 331). get_event_loop() is deprecated in Python 3.10+ when called inside async contexts; get_running_loop() is the correct replacement inside async def functions. - Replace PendingDeprecationWarning with DeprecationWarning in aio/chat.py and sync/chat.py (3 occurrences each). PendingDeprecationWarning is ignored by default Python warning filters, so users never see the deprecation notice. DeprecationWarning is the standard choice and is visible by default.
1 parent b383fe6 commit c434635

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/xai_sdk/aio/chat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async def sample_batch(self, n: int) -> Sequence[Response]:
140140
"""
141141
warnings.warn(
142142
"chat.sample_batch will be deprecated in a future version release. Use chat.sample() instead.",
143-
PendingDeprecationWarning,
143+
DeprecationWarning,
144144
stacklevel=2,
145145
)
146146

@@ -236,7 +236,7 @@ async def stream_batch(self, n: int) -> AsyncIterator[tuple[Sequence[Response],
236236
"""
237237
warnings.warn(
238238
"chat.stream_batch will be deprecated in a future version release. Use chat.stream() instead.",
239-
PendingDeprecationWarning,
239+
DeprecationWarning,
240240
stacklevel=2,
241241
)
242242

@@ -423,7 +423,7 @@ async def defer_batch(
423423
"""
424424
warnings.warn(
425425
"chat.defer_batch will be deprecated in a future version release. Use chat.defer() instead.",
426-
PendingDeprecationWarning,
426+
DeprecationWarning,
427427
stacklevel=2,
428428
)
429429

src/xai_sdk/files.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ async def _async_chunk_file_from_path(
274274
)
275275

276276
# Use asyncio to read file without blocking
277-
loop = asyncio.get_event_loop()
277+
loop = asyncio.get_running_loop()
278278

279279
def read_chunk(f):
280280
return f.read(_CHUNK_SIZE)
@@ -328,7 +328,7 @@ async def _async_chunk_file_from_fileobj(
328328
)
329329

330330
# Use asyncio to read file without blocking
331-
loop = asyncio.get_event_loop()
331+
loop = asyncio.get_running_loop()
332332

333333
def read_chunk():
334334
return file_obj.read(_CHUNK_SIZE)

src/xai_sdk/sync/chat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def sample_batch(self, n: int) -> Sequence[Response]:
137137
"""
138138
warnings.warn(
139139
"chat.sample_batch will be deprecated in a future version release. Use chat.sample() instead.",
140-
PendingDeprecationWarning,
140+
DeprecationWarning,
141141
stacklevel=2,
142142
)
143143

@@ -229,7 +229,7 @@ def stream_batch(self, n: int) -> Iterator[tuple[Sequence[Response], Sequence[Ch
229229
"""
230230
warnings.warn(
231231
"chat.stream_batch will be deprecated in a future version release. Use chat.stream() instead.",
232-
PendingDeprecationWarning,
232+
DeprecationWarning,
233233
stacklevel=2,
234234
)
235235

@@ -409,7 +409,7 @@ def defer_batch(
409409
"""
410410
warnings.warn(
411411
"chat.defer_batch will be deprecated in a future version release. Use chat.defer() instead.",
412-
PendingDeprecationWarning,
412+
DeprecationWarning,
413413
stacklevel=2,
414414
)
415415

0 commit comments

Comments
 (0)