mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-20 20:44:17 +02:00
Set generics without bounds to default=Any
This change addresses strict type checker warnings by adding default=Any to TypeVar definitions that lack bounds. Uses typing_extensions.TypeVar for compatibility with Python 3.10+. Co-authored-by: William Easton <strawgate@users.noreply.github.com>
This commit is contained in:
parent
b4cd2857bb
commit
25d3266ef4
8 changed files with 22 additions and 18 deletions
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
from typing import Any, Generic, TypeAlias, TypeVar
|
||||
from typing import Any, Generic, TypeAlias
|
||||
|
||||
import mcp.types
|
||||
from mcp import ClientSession
|
||||
|
|
@ -10,12 +10,13 @@ from mcp.shared.context import LifespanContextT, RequestContext
|
|||
from mcp.types import ElicitRequestParams
|
||||
from mcp.types import ElicitResult as MCPElicitResult
|
||||
from pydantic_core import to_jsonable_python
|
||||
from typing_extensions import TypeVar
|
||||
|
||||
from fastmcp.utilities.json_schema_type import json_schema_to_type
|
||||
|
||||
__all__ = ["ElicitRequestParams", "ElicitResult", "ElicitationHandler"]
|
||||
|
||||
T = TypeVar("T")
|
||||
T = TypeVar("T", default=Any)
|
||||
|
||||
|
||||
class ElicitResult(MCPElicitResult, Generic[T]):
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from contextlib import contextmanager
|
|||
from contextvars import ContextVar, Token
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from typing import Any, Literal, TypeVar, cast, get_origin, overload
|
||||
from typing import Any, Literal, cast, get_origin, overload
|
||||
|
||||
from mcp import LoggingLevel, ServerSession
|
||||
from mcp.server.lowlevel.helper_types import ReadResourceContents
|
||||
|
|
@ -31,6 +31,7 @@ from mcp.types import (
|
|||
from mcp.types import CreateMessageRequestParams as SamplingParams
|
||||
from pydantic.networks import AnyUrl
|
||||
from starlette.requests import Request
|
||||
from typing_extensions import TypeVar
|
||||
|
||||
import fastmcp.server.dependencies
|
||||
from fastmcp import settings
|
||||
|
|
@ -47,7 +48,7 @@ from fastmcp.utilities.types import get_cached_typeadapter
|
|||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
T = TypeVar("T")
|
||||
T = TypeVar("T", default=Any)
|
||||
_current_context: ContextVar[Context | None] = ContextVar("context", default=None) # type: ignore[assignment]
|
||||
_flush_lock = asyncio.Lock()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, ParamSpec, TypeVar
|
||||
from typing import TYPE_CHECKING, Any, ParamSpec
|
||||
|
||||
from mcp.server.auth.middleware.auth_context import (
|
||||
get_access_token as _sdk_get_access_token,
|
||||
)
|
||||
from starlette.requests import Request
|
||||
from typing_extensions import TypeVar
|
||||
|
||||
from fastmcp.server.auth import AccessToken
|
||||
|
||||
|
|
@ -13,7 +14,7 @@ if TYPE_CHECKING:
|
|||
from fastmcp.server.context import Context
|
||||
|
||||
P = ParamSpec("P")
|
||||
R = TypeVar("R")
|
||||
R = TypeVar("R", default=Any)
|
||||
|
||||
__all__ = [
|
||||
"get_context",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Generic, Literal, TypeVar
|
||||
from typing import Any, Generic, Literal
|
||||
|
||||
from mcp.server.elicitation import (
|
||||
CancelledElicitation,
|
||||
|
|
@ -10,6 +10,7 @@ from mcp.server.elicitation import (
|
|||
from pydantic import BaseModel
|
||||
from pydantic.json_schema import GenerateJsonSchema, JsonSchemaValue
|
||||
from pydantic_core import core_schema
|
||||
from typing_extensions import TypeVar
|
||||
|
||||
from fastmcp.utilities.json_schema import compress_schema
|
||||
from fastmcp.utilities.logging import get_logger
|
||||
|
|
@ -25,7 +26,7 @@ __all__ = [
|
|||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
T = TypeVar("T")
|
||||
T = TypeVar("T", default=Any)
|
||||
|
||||
|
||||
class ElicitationJsonSchema(GenerateJsonSchema):
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@ from typing import (
|
|||
Generic,
|
||||
Literal,
|
||||
Protocol,
|
||||
TypeVar,
|
||||
runtime_checkable,
|
||||
)
|
||||
|
||||
import mcp.types as mt
|
||||
from typing_extensions import TypeVar
|
||||
|
||||
from fastmcp.prompts.prompt import Prompt
|
||||
from fastmcp.resources.resource import Resource
|
||||
|
|
@ -34,8 +34,8 @@ __all__ = [
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
T = TypeVar("T")
|
||||
R = TypeVar("R", covariant=True)
|
||||
T = TypeVar("T", default=Any)
|
||||
R = TypeVar("R", covariant=True, default=Any)
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ from typing import (
|
|||
Any,
|
||||
Generic,
|
||||
Literal,
|
||||
TypeVar,
|
||||
get_type_hints,
|
||||
)
|
||||
|
||||
|
|
@ -19,6 +18,7 @@ import pydantic_core
|
|||
from mcp.types import ContentBlock, TextContent, ToolAnnotations
|
||||
from mcp.types import Tool as MCPTool
|
||||
from pydantic import Field, PydanticSchemaGenerationError
|
||||
from typing_extensions import TypeVar
|
||||
|
||||
import fastmcp
|
||||
from fastmcp.server.dependencies import get_context
|
||||
|
|
@ -41,7 +41,7 @@ if TYPE_CHECKING:
|
|||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
T = TypeVar("T")
|
||||
T = TypeVar("T", default=Any)
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
from typing import Annotated, Any, TypedDict, TypeVar
|
||||
from typing import Annotated, Any, TypedDict
|
||||
|
||||
from pydantic import BeforeValidator, Field, PrivateAttr
|
||||
from typing_extensions import Self
|
||||
from typing_extensions import Self, TypeVar
|
||||
|
||||
import fastmcp
|
||||
from fastmcp.utilities.types import FastMCPBaseModel
|
||||
|
||||
T = TypeVar("T")
|
||||
T = TypeVar("T", default=Any)
|
||||
|
||||
|
||||
class FastMCPMeta(TypedDict, total=False):
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ from typing import (
|
|||
Any,
|
||||
Protocol,
|
||||
TypeAlias,
|
||||
TypeVar,
|
||||
Union,
|
||||
get_args,
|
||||
get_origin,
|
||||
|
|
@ -23,8 +22,9 @@ from typing import (
|
|||
import mcp.types
|
||||
from mcp.types import Annotations, ContentBlock, ModelPreferences, SamplingMessage
|
||||
from pydantic import AnyUrl, BaseModel, ConfigDict, Field, TypeAdapter, UrlConstraints
|
||||
from typing_extensions import TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
T = TypeVar("T", default=Any)
|
||||
|
||||
# sentinel values for optional arguments
|
||||
NotSet = ...
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue