Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
11b53ee
1
Parent(s): 92cf7e6
Use ellipsis default
Browse files
src/fastmcp/server/auth/providers/bearer_env.py
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
|
|
|
|
|
| 1 |
from pydantic_settings import BaseSettings, SettingsConfigDict
|
| 2 |
|
| 3 |
from fastmcp.server.auth.providers.bearer import BearerAuthProvider
|
| 4 |
|
| 5 |
|
| 6 |
-
# Sentinel object to indicate that a setting is not set
|
| 7 |
-
class _NotSet:
|
| 8 |
-
pass
|
| 9 |
-
|
| 10 |
-
|
| 11 |
class EnvBearerAuthProviderSettings(BaseSettings):
|
| 12 |
"""Settings for the BearerAuthProvider."""
|
| 13 |
|
|
@@ -33,11 +30,11 @@ class EnvBearerAuthProvider(BearerAuthProvider):
|
|
| 33 |
|
| 34 |
def __init__(
|
| 35 |
self,
|
| 36 |
-
public_key: str | None |
|
| 37 |
-
jwks_uri: str | None |
|
| 38 |
-
issuer: str | None |
|
| 39 |
-
audience: str | None |
|
| 40 |
-
required_scopes: list[str] | None |
|
| 41 |
):
|
| 42 |
"""
|
| 43 |
Initialize the provider.
|
|
@@ -57,6 +54,6 @@ class EnvBearerAuthProvider(BearerAuthProvider):
|
|
| 57 |
"required_scopes": required_scopes,
|
| 58 |
}
|
| 59 |
settings = EnvBearerAuthProviderSettings(
|
| 60 |
-
**{k: v for k, v in kwargs.items() if v is not
|
| 61 |
)
|
| 62 |
super().__init__(**settings.model_dump())
|
|
|
|
| 1 |
+
from types import EllipsisType
|
| 2 |
+
|
| 3 |
from pydantic_settings import BaseSettings, SettingsConfigDict
|
| 4 |
|
| 5 |
from fastmcp.server.auth.providers.bearer import BearerAuthProvider
|
| 6 |
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
class EnvBearerAuthProviderSettings(BaseSettings):
|
| 9 |
"""Settings for the BearerAuthProvider."""
|
| 10 |
|
|
|
|
| 30 |
|
| 31 |
def __init__(
|
| 32 |
self,
|
| 33 |
+
public_key: str | None | EllipsisType = ...,
|
| 34 |
+
jwks_uri: str | None | EllipsisType = ...,
|
| 35 |
+
issuer: str | None | EllipsisType = ...,
|
| 36 |
+
audience: str | None | EllipsisType = ...,
|
| 37 |
+
required_scopes: list[str] | None | EllipsisType = ...,
|
| 38 |
):
|
| 39 |
"""
|
| 40 |
Initialize the provider.
|
|
|
|
| 54 |
"required_scopes": required_scopes,
|
| 55 |
}
|
| 56 |
settings = EnvBearerAuthProviderSettings(
|
| 57 |
+
**{k: v for k, v in kwargs.items() if v is not ...}
|
| 58 |
)
|
| 59 |
super().__init__(**settings.model_dump())
|
tests/utilities/test_types.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import base64
|
|
|
|
| 2 |
from typing import Annotated, Any
|
| 3 |
|
| 4 |
import pytest
|
|
@@ -308,6 +309,14 @@ class TestFindKwargByType:
|
|
| 308 |
|
| 309 |
assert find_kwarg_by_type(func, SENTINEL) is None # type: ignore
|
| 310 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
def test_missing_type_annotation(self):
|
| 312 |
"""Test finding parameter with a missing type annotation."""
|
| 313 |
|
|
|
|
| 1 |
import base64
|
| 2 |
+
from types import EllipsisType
|
| 3 |
from typing import Annotated, Any
|
| 4 |
|
| 5 |
import pytest
|
|
|
|
| 309 |
|
| 310 |
assert find_kwarg_by_type(func, SENTINEL) is None # type: ignore
|
| 311 |
|
| 312 |
+
def test_ellipsis_annotation(self):
|
| 313 |
+
"""Test finding parameter with an ellipsis annotation."""
|
| 314 |
+
|
| 315 |
+
def func(a: int, b: EllipsisType, c: str): # type: ignore # noqa: F821
|
| 316 |
+
pass
|
| 317 |
+
|
| 318 |
+
assert find_kwarg_by_type(func, EllipsisType) == "b" # type: ignore
|
| 319 |
+
|
| 320 |
def test_missing_type_annotation(self):
|
| 321 |
"""Test finding parameter with a missing type annotation."""
|
| 322 |
|