-
-
Notifications
You must be signed in to change notification settings - Fork 932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate Starlette
and Router
decorators
#1897
Conversation
5c14be1
to
465d536
Compare
tests/test_routing.py
Outdated
@@ -864,24 +864,6 @@ def test_mount_asgi_app_with_middleware_url_path_for() -> None: | |||
mounted_app_with_middleware.url_path_for("route") | |||
|
|||
|
|||
def test_add_route_to_app_after_mount( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep this test as long as the feature code exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll readd it with the warning filter.
Won't it emit two same warnings when using |
yep, it's written on the description. I'll remove the duplications. |
303abfd
to
51e22d6
Compare
You literally already mentioned that, my bad. I'd still vote for removing all of the methods in favor of more "immutable" classes, but mostly because of personal preference. |
Those methods may be handy for third party packages. For example, I have a workaround to duplicate endpoint paths that end with "/" with "" and vice-versa, so my application doesn't redirect. Let's not focus on how valid the example is (👀), but the fact that people may be using them for other ideas. Given that the discussions previously were focusing on the decorators, I would prefer to deal with them separately, or even not deal with them at all, and let them stay. |
Okay, I needed a bit of time to get back to speed on this. So, everything listed here is clearly marked in the codebase as "don't use this", and none of these methods or decorators exist in the documentation. Personally I think everything here is on a deprecation line, we just haven't escalated that into warnings or removals yet. But anyways. Where are we?...
|
Sure. We should take a decision on the methods before 1.0.0. Possible paths:
No disagreement, we can proceed.
I'll readd the docstrings. |
I'll remove the deprecation on |
The docstrings I've removed are from methods, not from decorators. JFYK |
This is ready for review. 👀 |
I'm quite happy with the separation b/w treating decorators vs methods. This keeps an escape hatch for users (including frameworks) to use the methods to alter the app after-the-fact, but officialises that as far as Starlette is concerned, the decorator API shouldn't exist anymore. Should there be tests on deprecated code usage? Using this: https://docs.pytest.org/en/7.1.x/how-to/capture-warnings.html#ensuring-code-triggers-a-deprecation-warning def test_decorator_deprecations():
app = Starlette()
with pytest.deprecated_call():
app.middleware(...)
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, looks good! There's probably a bunch of things that will have to be done in FastAPI but this makes sense! 🤓
I'm not going to include this on the 0.22.0 release because it implies FastAPI changes. I'll include this (with tests @florimondmanca 🙏) on the 0.23.0 release. |
09e5b9c
to
d9db160
Compare
Description
The motivation of this PR is to deprecate part of the code that is discouraged for around 4 years.
As we discussed, this PR only deprecates decorators! The methods that are used by them are not deprecated.
Deprecation Table
Methods
add_middleware
add_event_handler
add_route
add_websocket
mount
host
add_exception_handler
Decorators
middleware
on_event
route
websocket
exception_handler