mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-23 14:04:18 +02:00
Ensure old settings access still works
This commit is contained in:
parent
384262657c
commit
55d1626eca
2 changed files with 35 additions and 0 deletions
|
|
@ -73,6 +73,8 @@ class Settings(BaseSettings):
|
|||
dotenv_settings: PydanticBaseSettingsSource,
|
||||
file_secret_settings: PydanticBaseSettingsSource,
|
||||
) -> tuple[PydanticBaseSettingsSource, ...]:
|
||||
# can remove this classmethod after deprecated FASTMCP_SERVER_ prefix is
|
||||
# removed
|
||||
return (
|
||||
init_settings,
|
||||
ExtendedEnvSettingsSource(settings_cls),
|
||||
|
|
@ -80,6 +82,20 @@ class Settings(BaseSettings):
|
|||
file_secret_settings,
|
||||
)
|
||||
|
||||
@property
|
||||
def settings(self) -> Self:
|
||||
"""
|
||||
This property is for backwards compatibility with FastMCP < 2.8.0,
|
||||
which accessed fastmcp.settings.settings
|
||||
"""
|
||||
# Deprecated in 2.8.0
|
||||
warnings.warn(
|
||||
"Using fastmcp.settings.settings is deprecated. Use fastmcp.settings instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return self
|
||||
|
||||
home: Path = Path.home() / ".fastmcp"
|
||||
|
||||
test_mode: bool = False
|
||||
|
|
|
|||
|
|
@ -330,3 +330,22 @@ class TestDeprecatedEnvironmentVariables:
|
|||
os.environ[env_var_name] = original_value
|
||||
else:
|
||||
os.environ.pop(env_var_name, None)
|
||||
|
||||
|
||||
class TestDeprecatedSettingsProperty:
|
||||
"""Test deprecated settings property access."""
|
||||
|
||||
def test_settings_property_deprecation_warning(self):
|
||||
"""Test that accessing fastmcp.settings.settings raises a deprecation warning."""
|
||||
from fastmcp import settings
|
||||
|
||||
with pytest.warns(
|
||||
DeprecationWarning,
|
||||
match=r"Using fastmcp\.settings\.settings is deprecated\. Use fastmcp\.settings instead\.",
|
||||
):
|
||||
# Access the deprecated property
|
||||
deprecated_settings = settings.settings
|
||||
|
||||
# Verify it still returns the same settings object
|
||||
assert deprecated_settings is settings
|
||||
assert isinstance(deprecated_settings, Settings)
|
||||
Loading…
Add table
Add a link
Reference in a new issue