Skip to content
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

Allow route decorators to stack up again #1764

Merged
merged 3 commits into from
Jan 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sanic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ def route(
strict_slashes = self.strict_slashes

def response(handler):
if isinstance(handler, (tuple, list)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some comments here for explaining?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment explaining it

routes, handler = handler
else:
routes = []
args = list(signature(handler).parameters.keys())

if not args:
Expand All @@ -205,7 +209,7 @@ def response(handler):
if stream:
handler.is_stream = stream

routes = self.router.add(
new_routes = self.router.add(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new_routes seems a little bit weird.. maybe we can just extend in place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to inplace extend.

uri=uri,
methods=methods,
handler=handler,
Expand All @@ -214,6 +218,7 @@ def response(handler):
version=version,
name=name,
)
routes.extend(new_routes)
return routes, handler

return response
Expand Down
12 changes: 12 additions & 0 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,18 @@ async def handler4(request, dynamic):
pass


def test_double_stack_route(app):
@app.route("/test/1")
@app.route("/test/2")
async def handler1(request):
return text("OK")

request, response = app.test_client.get("/test/1")
assert response.status == 200
request, response = app.test_client.get("/test/2")
assert response.status == 200


def test_method_not_allowed(app):
@app.route("/test", methods=["GET"])
async def handler(request):
Expand Down