mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-24 16:06:22 +02:00
fix: replace deprecated asyncio.iscoroutinefunction with inspect.iscoroutinefunction (#819)
asyncio.iscoroutinefunction is deprecated since Python 3.14 and slated for removal in 3.16. The inspect equivalent has an identical signature and return semantics. Replaces 8 call sites across 3 modules to silence DeprecationWarnings reported in #818.
This commit is contained in:
parent
ef8bb3aed4
commit
645b6a66fd
3 changed files with 11 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
import json
|
||||
import asyncio
|
||||
import inspect
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional, Any
|
||||
|
||||
|
|
@ -80,7 +81,7 @@ class PromptClient(RequestResponse):
|
|||
|
||||
if resp.text is not None:
|
||||
if chunk_callback:
|
||||
if asyncio.iscoroutinefunction(chunk_callback):
|
||||
if inspect.iscoroutinefunction(chunk_callback):
|
||||
await chunk_callback(resp.text, end_stream)
|
||||
else:
|
||||
chunk_callback(resp.text, end_stream)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ Provides comprehensive error handling, retry logic, and graceful degradation.
|
|||
import logging
|
||||
import time
|
||||
import asyncio
|
||||
import inspect
|
||||
from typing import Dict, Any, List, Optional, Callable, Union, Type
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
|
|
@ -244,7 +245,7 @@ class ErrorRecoveryStrategy:
|
|||
await asyncio.sleep(delay)
|
||||
|
||||
try:
|
||||
if asyncio.iscoroutinefunction(operation):
|
||||
if inspect.iscoroutinefunction(operation):
|
||||
return await operation(*args, **kwargs)
|
||||
else:
|
||||
return operation(*args, **kwargs)
|
||||
|
|
@ -260,7 +261,7 @@ class ErrorRecoveryStrategy:
|
|||
if fallback_func:
|
||||
logger.info(f"Executing fallback for {context.category.value}")
|
||||
try:
|
||||
if asyncio.iscoroutinefunction(fallback_func):
|
||||
if inspect.iscoroutinefunction(fallback_func):
|
||||
return await fallback_func(context, *args, **kwargs)
|
||||
else:
|
||||
return fallback_func(context, *args, **kwargs)
|
||||
|
|
@ -420,7 +421,7 @@ def with_error_handling(category: ErrorCategory,
|
|||
@wraps(func)
|
||||
async def async_wrapper(*args, **kwargs):
|
||||
try:
|
||||
if asyncio.iscoroutinefunction(func):
|
||||
if inspect.iscoroutinefunction(func):
|
||||
return await func(*args, **kwargs)
|
||||
else:
|
||||
return func(*args, **kwargs)
|
||||
|
|
@ -469,7 +470,7 @@ def with_error_handling(category: ErrorCategory,
|
|||
cause=e
|
||||
)
|
||||
|
||||
if asyncio.iscoroutinefunction(func):
|
||||
if inspect.iscoroutinefunction(func):
|
||||
return async_wrapper
|
||||
else:
|
||||
return sync_wrapper
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ Provides comprehensive monitoring of system performance, query patterns, and res
|
|||
import logging
|
||||
import time
|
||||
import asyncio
|
||||
import inspect
|
||||
import threading
|
||||
from typing import Dict, Any, List, Optional, Callable
|
||||
from dataclasses import dataclass, field
|
||||
|
|
@ -579,7 +580,7 @@ def monitor_performance(component: str,
|
|||
|
||||
async def async_wrapper(*args, **kwargs):
|
||||
if not monitor or not monitor.monitoring_enabled:
|
||||
if asyncio.iscoroutinefunction(func):
|
||||
if inspect.iscoroutinefunction(func):
|
||||
return await func(*args, **kwargs)
|
||||
else:
|
||||
return func(*args, **kwargs)
|
||||
|
|
@ -591,7 +592,7 @@ def monitor_performance(component: str,
|
|||
|
||||
success = True
|
||||
try:
|
||||
if asyncio.iscoroutinefunction(func):
|
||||
if inspect.iscoroutinefunction(func):
|
||||
result = await func(*args, **kwargs)
|
||||
else:
|
||||
result = func(*args, **kwargs)
|
||||
|
|
@ -603,7 +604,7 @@ def monitor_performance(component: str,
|
|||
duration = monitor.metrics_collector.stop_timer(timer)
|
||||
monitor.record_request(component, operation, duration, success)
|
||||
|
||||
if asyncio.iscoroutinefunction(func):
|
||||
if inspect.iscoroutinefunction(func):
|
||||
return async_wrapper
|
||||
else:
|
||||
return wrapper
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue