mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 00:16:23 +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 json
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import inspect
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Optional, Any
|
from typing import Optional, Any
|
||||||
|
|
||||||
|
|
@ -80,7 +81,7 @@ class PromptClient(RequestResponse):
|
||||||
|
|
||||||
if resp.text is not None:
|
if resp.text is not None:
|
||||||
if chunk_callback:
|
if chunk_callback:
|
||||||
if asyncio.iscoroutinefunction(chunk_callback):
|
if inspect.iscoroutinefunction(chunk_callback):
|
||||||
await chunk_callback(resp.text, end_stream)
|
await chunk_callback(resp.text, end_stream)
|
||||||
else:
|
else:
|
||||||
chunk_callback(resp.text, end_stream)
|
chunk_callback(resp.text, end_stream)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ Provides comprehensive error handling, retry logic, and graceful degradation.
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import inspect
|
||||||
from typing import Dict, Any, List, Optional, Callable, Union, Type
|
from typing import Dict, Any, List, Optional, Callable, Union, Type
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
@ -244,7 +245,7 @@ class ErrorRecoveryStrategy:
|
||||||
await asyncio.sleep(delay)
|
await asyncio.sleep(delay)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if asyncio.iscoroutinefunction(operation):
|
if inspect.iscoroutinefunction(operation):
|
||||||
return await operation(*args, **kwargs)
|
return await operation(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
return operation(*args, **kwargs)
|
return operation(*args, **kwargs)
|
||||||
|
|
@ -260,7 +261,7 @@ class ErrorRecoveryStrategy:
|
||||||
if fallback_func:
|
if fallback_func:
|
||||||
logger.info(f"Executing fallback for {context.category.value}")
|
logger.info(f"Executing fallback for {context.category.value}")
|
||||||
try:
|
try:
|
||||||
if asyncio.iscoroutinefunction(fallback_func):
|
if inspect.iscoroutinefunction(fallback_func):
|
||||||
return await fallback_func(context, *args, **kwargs)
|
return await fallback_func(context, *args, **kwargs)
|
||||||
else:
|
else:
|
||||||
return fallback_func(context, *args, **kwargs)
|
return fallback_func(context, *args, **kwargs)
|
||||||
|
|
@ -420,7 +421,7 @@ def with_error_handling(category: ErrorCategory,
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
async def async_wrapper(*args, **kwargs):
|
async def async_wrapper(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
if asyncio.iscoroutinefunction(func):
|
if inspect.iscoroutinefunction(func):
|
||||||
return await func(*args, **kwargs)
|
return await func(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
|
@ -469,7 +470,7 @@ def with_error_handling(category: ErrorCategory,
|
||||||
cause=e
|
cause=e
|
||||||
)
|
)
|
||||||
|
|
||||||
if asyncio.iscoroutinefunction(func):
|
if inspect.iscoroutinefunction(func):
|
||||||
return async_wrapper
|
return async_wrapper
|
||||||
else:
|
else:
|
||||||
return sync_wrapper
|
return sync_wrapper
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ Provides comprehensive monitoring of system performance, query patterns, and res
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import inspect
|
||||||
import threading
|
import threading
|
||||||
from typing import Dict, Any, List, Optional, Callable
|
from typing import Dict, Any, List, Optional, Callable
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
|
@ -579,7 +580,7 @@ def monitor_performance(component: str,
|
||||||
|
|
||||||
async def async_wrapper(*args, **kwargs):
|
async def async_wrapper(*args, **kwargs):
|
||||||
if not monitor or not monitor.monitoring_enabled:
|
if not monitor or not monitor.monitoring_enabled:
|
||||||
if asyncio.iscoroutinefunction(func):
|
if inspect.iscoroutinefunction(func):
|
||||||
return await func(*args, **kwargs)
|
return await func(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
|
@ -591,7 +592,7 @@ def monitor_performance(component: str,
|
||||||
|
|
||||||
success = True
|
success = True
|
||||||
try:
|
try:
|
||||||
if asyncio.iscoroutinefunction(func):
|
if inspect.iscoroutinefunction(func):
|
||||||
result = await func(*args, **kwargs)
|
result = await func(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
result = func(*args, **kwargs)
|
result = func(*args, **kwargs)
|
||||||
|
|
@ -603,7 +604,7 @@ def monitor_performance(component: str,
|
||||||
duration = monitor.metrics_collector.stop_timer(timer)
|
duration = monitor.metrics_collector.stop_timer(timer)
|
||||||
monitor.record_request(component, operation, duration, success)
|
monitor.record_request(component, operation, duration, success)
|
||||||
|
|
||||||
if asyncio.iscoroutinefunction(func):
|
if inspect.iscoroutinefunction(func):
|
||||||
return async_wrapper
|
return async_wrapper
|
||||||
else:
|
else:
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue