mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
fix: make policy_resolve_endpoints importable without FastAPI
Adds try/except around FastAPI imports with fallback mock classes. This allows the module to be imported in test environments where proxy dependencies (FastAPI) may not be installed. Fixes NameError when MCP tests try to import from proxy_server which imports from this module: - NameError: name 'APIRouter' is not defined - NameError: name 'Depends' is not defined - NameError: name 'HTTPException' is not defined - NameError: name 'Query' is not defined
This commit is contained in:
parent
7a164ba2cc
commit
e6385a6c83
1 changed files with 19 additions and 1 deletions
|
|
@ -6,8 +6,26 @@ Policy resolve and attachment impact estimation endpoints.
|
|||
"""
|
||||
|
||||
import json
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
# FastAPI imports - may not be available in all environments (e.g. during testing)
|
||||
try:
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
except ImportError:
|
||||
# Provide stubs for type checking only
|
||||
if TYPE_CHECKING:
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
else:
|
||||
# Create mock classes that won't be used
|
||||
class APIRouter: # type: ignore[no-redef]
|
||||
def post(self, *args, **kwargs):
|
||||
def decorator(func):
|
||||
return func
|
||||
return decorator
|
||||
|
||||
def Depends(func): return func # type: ignore[misc]
|
||||
HTTPException = Exception # type: ignore[misc,assignment]
|
||||
def Query(*args, **kwargs): return None # type: ignore[misc]
|
||||
|
||||
from litellm._logging import verbose_proxy_logger
|
||||
from litellm.constants import MAX_POLICY_ESTIMATE_IMPACT_ROWS
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue