Spaces:
Running
Running
Merge pull request #57 from jurasofish/Avoid-new-try_eval_type-unavailable-on-older-pydantic
Browse files
src/fastmcp/utilities/func_metadata.py
CHANGED
|
@@ -8,7 +8,7 @@ from typing import (
|
|
| 8 |
)
|
| 9 |
from pydantic import Field
|
| 10 |
from fastmcp.exceptions import InvalidSignature
|
| 11 |
-
from pydantic._internal._typing_extra import
|
| 12 |
import json
|
| 13 |
from pydantic import BaseModel
|
| 14 |
from pydantic.fields import FieldInfo
|
|
@@ -178,12 +178,7 @@ def func_metadata(func: Callable, skip_names: Sequence[str] = ()) -> FuncMetadat
|
|
| 178 |
def _get_typed_annotation(annotation: Any, globalns: Dict[str, Any]) -> Any:
|
| 179 |
if isinstance(annotation, str):
|
| 180 |
annotation = ForwardRef(annotation)
|
| 181 |
-
annotation
|
| 182 |
-
|
| 183 |
-
# This check and raise could perhaps be skipped, and we (FastMCP) just call
|
| 184 |
-
# model_rebuild right before using it 🤷
|
| 185 |
-
if status is False:
|
| 186 |
-
raise InvalidSignature(f"Unable to evaluate type annotation {annotation}")
|
| 187 |
|
| 188 |
return annotation
|
| 189 |
|
|
|
|
| 8 |
)
|
| 9 |
from pydantic import Field
|
| 10 |
from fastmcp.exceptions import InvalidSignature
|
| 11 |
+
from pydantic._internal._typing_extra import eval_type_lenient
|
| 12 |
import json
|
| 13 |
from pydantic import BaseModel
|
| 14 |
from pydantic.fields import FieldInfo
|
|
|
|
| 178 |
def _get_typed_annotation(annotation: Any, globalns: Dict[str, Any]) -> Any:
|
| 179 |
if isinstance(annotation, str):
|
| 180 |
annotation = ForwardRef(annotation)
|
| 181 |
+
annotation = eval_type_lenient(annotation, globalns, globalns)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
return annotation
|
| 184 |
|