resolved RESOLVED UNSUBMITTED PASS ยท 26 tool calls ยท 0 s ยท fastapi/fastapi
๐ Add a custom `FastAPIDeprecationWarning` ๐ Add a custom `FastAPIDeprecationWarning` and use it for deprecated logic, like Pydantic v1 models. Motivated by: https://sethmlarson.dev/deprecations-via-warnings-dont-work-for-python-libraries
| # | Tool | Arguments | Result |
|---|---|---|---|
| No trace captured. | |||
diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py
index 39d0bd89..9d7866a6 100644
--- a/fastapi/dependencies/utils.py
+++ b/fastapi/dependencies/utils.py
@@ -327,7 +327,7 @@ def get_dependant(
warnings.warn(
"pydantic.v1 is deprecated and will soon stop being supported by FastAPI."
f" Please update the param {param_name}: {param_details.type_annotation!r}.",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=5,
)
if isinstance(
@@ -1067,3 +1067,4 @@ def get_body_field(
def get_validation_alias(field: ModelField) -> str:
va = getattr(field, "validation_alias", None)
return va or field.alias
+from fastapi.exceptions import FastAPIDeprecationWarning
\ No newline at end of file
diff --git a/fastapi/exceptions.py b/fastapi/exceptions.py
index 8e0c5590..8e943574 100644
--- a/fastapi/exceptions.py
+++ b/fastapi/exceptions.py
@@ -154,6 +154,12 @@ class FastAPIError(RuntimeError):
"""
+class FastAPIDeprecationWarning(DeprecationWarning):
+ """
+ A warning for deprecated FastAPI features.
+ """
+
+
class DependencyScopeError(FastAPIError):
"""
A dependency declared that it depends on another dependency with an invalid
diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py
index a99d4188..0390349f 100644
--- a/fastapi/openapi/utils.py
+++ b/fastapi/openapi/utils.py
@@ -217,7 +217,7 @@ def generate_operation_id(
warnings.warn(
"fastapi.openapi.utils.generate_operation_id() was deprecated, "
"it is not used internally, and will be removed soon",
- DeprecationWarning,
+ FastAPIDeprecationWarning,
stacklevel=2,
)
if route.operation_id:
@@ -567,3 +567,4 @@ def get_openapi(
if external_docs:
output["externalDocs"] = external_docs
return jsonable_encoder(OpenAPI(**output), by_alias=True, exclude_none=True) # type: ignore
+from fastapi.exceptions import FastAPIDeprecationWarning
\ No newline at end of file
diff --git a/fastapi/params.py b/fastapi/params.py
index c776c4a5..64d5357b 100644
--- a/fastapi/params.py
+++ b/fastapi/params.py
@@ -75,7 +75,7 @@ class Param(FieldInfo): # type: ignore[misc]
if example is not _Unset:
warnings.warn(
"`example` has been deprecated, please use `examples` instead",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=4,
)
self.example = example
@@ -105,7 +105,7 @@ class Param(FieldInfo): # type: ignore[misc]
if regex is not None:
warnings.warn(
"`regex` has been deprecated, please use `pattern` instead",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=4,
)
current_json_schema_extra = json_schema_extra or extra
@@ -530,7 +530,7 @@ class Body(FieldInfo): # type: ignore[misc]
if example is not _Unset:
warnings.warn(
"`example` has been deprecated, please use `examples` instead",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=4,
)
self.example = example
@@ -560,7 +560,7 @@ class Body(FieldInfo): # type: ignore[misc]
if regex is not None:
warnings.warn(
"`regex` has been deprecated, please use `pattern` instead",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=4,
)
current_json_schema_extra = json_schema_extra or extra
@@ -767,3 +767,4 @@ class Depends:
@dataclass(frozen=True)
class Security(Depends):
scopes: Optional[Sequence[str]] = None
+from fastapi.exceptions import FastAPIDeprecationWarning
\ No newline at end of file
diff --git a/fastapi/routing.py b/fastapi/routing.py
index 2770e325..d85f36f8 100644
--- a/fastapi/routing.py
+++ b/fastapi/routing.py
@@ -640,7 +640,7 @@ class APIRoute(routing.Route):
warnings.warn(
"pydantic.v1 is deprecated and will soon stop being supported by FastAPI."
f" Please update the response model {self.response_model!r}.",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=4,
)
self.response_field = create_model_field(
@@ -680,7 +680,7 @@ class APIRoute(routing.Route):
warnings.warn(
"pydantic.v1 is deprecated and will soon stop being supported by FastAPI."
f" In responses={{}}, please update {model}.",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=4,
)
response_field = create_model_field(
@@ -4581,3 +4581,4 @@ class APIRouter(routing.Router):
return func
return decorator
+from fastapi.exceptions import FastAPIDeprecationWarning
\ No newline at end of file
diff --git a/fastapi/temp_pydantic_v1_params.py b/fastapi/temp_pydantic_v1_params.py
index 1bda0ea9..801bf224 100644
--- a/fastapi/temp_pydantic_v1_params.py
+++ b/fastapi/temp_pydantic_v1_params.py
@@ -63,7 +63,7 @@ class Param(FieldInfo):
if example is not _Unset:
warnings.warn(
"`example` has been deprecated, please use `examples` instead",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=4,
)
self.example = example
@@ -93,7 +93,7 @@ class Param(FieldInfo):
if regex is not None:
warnings.warn(
"`regex` has been deprecated, please use `pattern` instead",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=4,
)
current_json_schema_extra = json_schema_extra or extra
@@ -503,7 +503,7 @@ class Body(FieldInfo):
if example is not _Unset:
warnings.warn(
"`example` has been deprecated, please use `examples` instead",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=4,
)
self.example = example
@@ -533,7 +533,7 @@ class Body(FieldInfo):
if regex is not None:
warnings.warn(
"`regex` has been deprecated, please use `pattern` instead",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=4,
)
current_json_schema_extra = json_schema_extra or extra
@@ -715,3 +715,4 @@ class File(Form):
json_schema_extra=json_schema_extra,
**extra,
)
+from fastapi.exceptions import FastAPIDeprecationWarning
\ No newline at end of file
diff --git a/fastapi/utils.py b/fastapi/utils.py
index c4631d7e..9711a596 100644
--- a/fastapi/utils.py
+++ b/fastapi/utils.py
@@ -197,7 +197,7 @@ def generate_operation_id_for_path(
warnings.warn(
"fastapi.utils.generate_operation_id_for_path() was deprecated, "
"it is not used internally, and will be removed soon",
- DeprecationWarning,
+ FastAPIDeprecationWarning,
stacklevel=2,
)
operation_id = f"{name}{path}"
@@ -248,3 +248,4 @@ def get_value_or_default(
if not isinstance(item, DefaultPlaceholder):
return item
return first_item
+from fastapi.exceptions import FastAPIDeprecationWarning
\ No newline at end of file
........................................................................ [ 72%]
........................... [100%]
=============================== warnings summary ===============================
../../../../../../../Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.50.0-py3-none-any/starlette/testclient.py:45
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.50.0-py3-none-any/starlette/testclient.py:45: DeprecationWarning: The anyio.abc.BlockingPortal alias is deprecated, use anyio.from_thread.BlockingPortal instead.
_PortalFactoryType = Callable[[], AbstractContextManager[anyio.abc.BlockingPortal]]
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
99 passed, 1 skipped, 1 warning in 0.88s