Deprecate Starlette and Router decorators#1897
Conversation
5c14be1 to
465d536
Compare
| mounted_app_with_middleware.url_path_for("route") | ||
|
|
||
|
|
||
| def test_add_route_to_app_after_mount( |
There was a problem hiding this comment.
I'd keep this test as long as the feature code exists.
There was a problem hiding this comment.
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? def test_decorator_deprecations():
app = Starlette()
with pytest.deprecated_call():
app.middleware(...)
... |
tiangolo
left a comment
There was a problem hiding this comment.
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_middlewareadd_event_handleradd_routeadd_websocketmounthostadd_exception_handlerDecorators
middlewareon_eventroutewebsocketexception_handler