Remove deprecated component-import __getattr__ shims

This commit is contained in:
Jeremiah Lowin 2026-07-06 21:52:52 -04:00
commit 7c2133a52f
No known key found for this signature in database
4 changed files with 0 additions and 201 deletions

View file

@ -2,7 +2,6 @@
from __future__ import annotations as _annotations
import warnings
from collections.abc import Callable
from typing import TYPE_CHECKING, Any, ClassVar, Literal, overload
@ -29,7 +28,6 @@ from mcp_types import PromptArgument as SDKPromptArgument
from pydantic import Field
from pydantic.json_schema import SkipJsonSchema
from fastmcp.exceptions import FastMCPDeprecationWarning
from fastmcp.utilities.authorization import AuthCheck
from fastmcp.utilities.components import FastMCPComponent
from fastmcp.utilities.logging import get_logger
@ -414,27 +412,3 @@ __all__ = [
"PromptArgument",
"PromptResult",
]
def __getattr__(name: str) -> Any:
"""Deprecated re-exports for backwards compatibility."""
deprecated_exports = {
"FunctionPrompt": "FunctionPrompt",
"prompt": "prompt",
}
if name in deprecated_exports:
import fastmcp
if fastmcp.settings.deprecation_warnings:
warnings.warn(
f"Importing {name} from fastmcp.prompts.prompt is deprecated. "
f"Import from fastmcp.prompts.function_prompt instead.",
FastMCPDeprecationWarning,
stacklevel=2,
)
from fastmcp.prompts import function_prompt
return getattr(function_prompt, name)
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

View file

@ -30,7 +30,6 @@ from pydantic import (
from pydantic.json_schema import SkipJsonSchema
from typing_extensions import Self
from fastmcp.exceptions import FastMCPDeprecationWarning
from fastmcp.utilities.authorization import AuthCheck
from fastmcp.utilities.components import FastMCPComponent
from fastmcp.utilities.tasks import TaskConfig, TaskMeta
@ -469,29 +468,3 @@ __all__ = [
"ResourceContent",
"ResourceResult",
]
def __getattr__(name: str) -> Any:
"""Deprecated re-exports for backwards compatibility."""
deprecated_exports = {
"FunctionResource": "FunctionResource",
"resource": "resource",
}
if name in deprecated_exports:
import warnings
import fastmcp
if fastmcp.settings.deprecation_warnings:
warnings.warn(
f"Importing {name} from fastmcp.resources.resource is deprecated. "
f"Import from fastmcp.resources.function_resource instead.",
FastMCPDeprecationWarning,
stacklevel=2,
)
from fastmcp.resources import function_resource
return getattr(function_resource, name)
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

View file

@ -1,6 +1,5 @@
from __future__ import annotations
import warnings
from collections.abc import Callable
from typing import (
TYPE_CHECKING,
@ -25,7 +24,6 @@ from mcp_types import Tool as MCPTool
from pydantic import BaseModel, Field, model_validator
from pydantic.json_schema import SkipJsonSchema
from fastmcp.exceptions import FastMCPDeprecationWarning
from fastmcp.utilities.authorization import AuthCheck
from fastmcp.utilities.components import FastMCPComponent
from fastmcp.utilities.logging import get_logger
@ -593,28 +591,3 @@ def _convert_to_content(
__all__ = ["Tool", "ToolResult"]
def __getattr__(name: str) -> Any:
"""Deprecated re-exports for backwards compatibility."""
deprecated_exports = {
"FunctionTool": "FunctionTool",
"ParsedFunction": "ParsedFunction",
"tool": "tool",
}
if name in deprecated_exports:
import fastmcp
if fastmcp.settings.deprecation_warnings:
warnings.warn(
f"Importing {name} from fastmcp.tools.tool is deprecated. "
f"Import from fastmcp.tools.function_tool instead.",
FastMCPDeprecationWarning,
stacklevel=2,
)
from fastmcp.tools import function_tool
return getattr(function_tool, name)
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

View file

@ -1,121 +0,0 @@
"""Test that deprecated import paths for function components still work."""
import warnings
import pytest
from fastmcp.utilities.tests import temporary_settings
class TestDeprecatedFunctionToolImports:
def test_function_tool_from_tool_module(self):
with temporary_settings(deprecation_warnings=True):
with pytest.warns(
DeprecationWarning, match="Import from fastmcp.tools.function_tool"
):
from fastmcp.tools.base import FunctionTool
# Verify it's the real class
from fastmcp.tools.function_tool import (
FunctionTool as CanonicalFunctionTool,
)
assert FunctionTool is CanonicalFunctionTool
def test_parsed_function_from_tool_module(self):
with temporary_settings(deprecation_warnings=True):
with pytest.warns(
DeprecationWarning, match="Import from fastmcp.tools.function_tool"
):
from fastmcp.tools.base import ParsedFunction
from fastmcp.tools.function_tool import (
ParsedFunction as CanonicalParsedFunction,
)
assert ParsedFunction is CanonicalParsedFunction
def test_tool_decorator_from_tool_module(self):
with temporary_settings(deprecation_warnings=True):
with pytest.warns(
DeprecationWarning, match="Import from fastmcp.tools.function_tool"
):
from fastmcp.tools.base import tool
from fastmcp.tools.function_tool import tool as canonical_tool
assert tool is canonical_tool
def test_no_warning_when_disabled(self):
with temporary_settings(deprecation_warnings=False):
with warnings.catch_warnings():
warnings.simplefilter("error")
from fastmcp.tools.base import FunctionTool # noqa: F401
class TestDeprecatedFunctionResourceImports:
def test_function_resource_from_resource_module(self):
with temporary_settings(deprecation_warnings=True):
with pytest.warns(
DeprecationWarning,
match="Import from fastmcp.resources.function_resource",
):
from fastmcp.resources.base import FunctionResource
from fastmcp.resources.function_resource import (
FunctionResource as CanonicalFunctionResource,
)
assert FunctionResource is CanonicalFunctionResource
def test_resource_decorator_from_resource_module(self):
with temporary_settings(deprecation_warnings=True):
with pytest.warns(
DeprecationWarning,
match="Import from fastmcp.resources.function_resource",
):
from fastmcp.resources.base import resource
from fastmcp.resources.function_resource import (
resource as canonical_resource,
)
assert resource is canonical_resource
def test_no_warning_when_disabled(self):
with temporary_settings(deprecation_warnings=False):
with warnings.catch_warnings():
warnings.simplefilter("error")
from fastmcp.resources.base import FunctionResource # noqa: F401
class TestDeprecatedFunctionPromptImports:
def test_function_prompt_from_prompt_module(self):
with temporary_settings(deprecation_warnings=True):
with pytest.warns(
DeprecationWarning, match="Import from fastmcp.prompts.function_prompt"
):
from fastmcp.prompts.base import FunctionPrompt
from fastmcp.prompts.function_prompt import (
FunctionPrompt as CanonicalFunctionPrompt,
)
assert FunctionPrompt is CanonicalFunctionPrompt
def test_prompt_decorator_from_prompt_module(self):
with temporary_settings(deprecation_warnings=True):
with pytest.warns(
DeprecationWarning, match="Import from fastmcp.prompts.function_prompt"
):
from fastmcp.prompts.base import prompt
from fastmcp.prompts.function_prompt import prompt as canonical_prompt
assert prompt is canonical_prompt
def test_no_warning_when_disabled(self):
with temporary_settings(deprecation_warnings=False):
with warnings.catch_warnings():
warnings.simplefilter("error")
from fastmcp.prompts.base import FunctionPrompt # noqa: F401