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

Resolve typing of stacked route definitions #2455

Merged
merged 3 commits into from Jun 16, 2022
Merged

Conversation

ahopkins
Copy link
Member

@ahopkins ahopkins commented May 12, 2022

Because of the weird necessity to return a route object for a static route, there is a RouteWrapper type that is meant to handle this use case. However, none of the convenience decorators (app.get, app.post, etc) will ever hit this use case. Therefore they can return RouteHandler.

This overly general typing was causing type annotation failures for this pattern, even though it is intentionally supported:

@app.get("/")
@app.post("/")
async def handler(request: Request):
    return json({"foo": "bar"})

This PR resolves the issue (even if not for app.route).

@ahopkins ahopkins requested a review from a team as a code owner May 12, 2022
@codecov
Copy link

codecov bot commented May 12, 2022

Codecov Report

No coverage uploaded for pull request base (main@1668e15). Click here to learn what that means.
The diff coverage is 100.000%.

@@           Coverage Diff            @@
##             main     #2455   +/-   ##
========================================
  Coverage        ?   87.246%           
========================================
  Files           ?        60           
  Lines           ?      5073           
  Branches        ?       907           
========================================
  Hits            ?      4426           
  Misses          ?       476           
  Partials        ?       171           
Impacted Files Coverage Δ
sanic/mixins/routes.py 92.800% <100.000%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1668e15...d7b3111. Read the comment docs.

@ahopkins ahopkins merged commit a411bc0 into main Jun 16, 2022
27 checks passed
@ahopkins ahopkins deleted the stacked-decorators branch Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant