Skip to content

Fix route handler callable typing#3161

Open
puneetdixit200 wants to merge 1 commit into
sanic-org:mainfrom
puneetdixit200:route-handler-awaitable-type
Open

Fix route handler callable typing#3161
puneetdixit200 wants to merge 1 commit into
sanic-org:mainfrom
puneetdixit200:route-handler-awaitable-type

Conversation

@puneetdixit200

Copy link
Copy Markdown

Fixes #3159.

Summary

  • widen RouteHandler from Coroutine to Awaitable so non-decorator route registration does not trigger mypy's unused coroutine check
  • update the internal handler response annotation to match the widened route handler type
  • add a typing sample for registering a bound async method through app.get(...)(handler)

Testing

  • python -m pytest tests\typing\test_typing.py -q
  • python -m pytest tests\test_handler.py -q
  • python -m ruff check sanic\app.py sanic\models\handler_types.py tests\typing\test_typing.py tests\typing\samples\route_handler_registration.py
  • python -m ruff format --check sanic\app.py sanic\models\handler_types.py tests\typing\test_typing.py tests\typing\samples\route_handler_registration.py
  • git diff --check

@puneetdixit200 puneetdixit200 requested a review from a team as a code owner May 21, 2026 07:45
@codecov

codecov Bot commented May 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.769%. Comparing base (5ffc7b3) to head (03379c5).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #3161   +/-   ##
=========================================
  Coverage   87.769%   87.769%           
=========================================
  Files          105       105           
  Lines         8152      8152           
  Branches      1291      1291           
=========================================
  Hits          7155      7155           
  Misses         692       692           
  Partials       305       305           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@puneetdixit200

Copy link
Copy Markdown
Author

The failed Linux py310-no-ext job no longer has retrievable logs from GitHub (gh run view --log-failed reports log not found: 77510132500), and I do not have permission to rerun it.\n\nI rechecked the changed typing coverage locally with Python 3.10/no-ext:\n\n\nUV_CACHE_DIR=/tmp/sanic-3161-uv-cache PIP_CACHE_DIR=/tmp/sanic-3161-pip-cache TOX_WORK_DIR=/tmp/sanic-3161-tox uv run --python 3.10 --with tox tox -e py310-no-ext -- tests/typing/test_typing.py\n\n\nThat passed: 8 tests. A full local macOS no-ext run stops earlier on the existing daemon test assumption that group root exists on the host, which is unrelated to this PR's changed typing files.\n\nCould someone with repo permissions rerun the failed Linux job?

@puneetdixit200

Copy link
Copy Markdown
Author

Refreshed the current red Linux jobs. GitHub no longer has retrievable logs for the three failed jobs (py310-no-ext, py311, and py311-no-ext all return log not found for their job IDs), and I still do not have permission to rerun them.

I re-ran the changed typing coverage locally:

UV_CACHE_DIR=/tmp/sanic-3161-uv-cache PIP_CACHE_DIR=/tmp/sanic-3161-pip-cache TOX_WORK_DIR=/tmp/sanic-3161-tox-py310-no-ext uv run --python 3.10 --with tox tox -e py310-no-ext -- tests/typing/test_typing.py
# 8 passed

UV_CACHE_DIR=/tmp/sanic-3161-uv-cache PIP_CACHE_DIR=/tmp/sanic-3161-pip-cache TOX_WORK_DIR=/tmp/sanic-3161-tox-py311 uv run --python 3.11 --with tox tox -e py311 -- tests/typing/test_typing.py
# 8 passed

UV_CACHE_DIR=/tmp/sanic-3161-uv-cache PIP_CACHE_DIR=/tmp/sanic-3161-pip-cache TOX_WORK_DIR=/tmp/sanic-3161-tox-py311-no-ext uv run --python 3.11 --with tox tox -e py311-no-ext -- tests/typing/test_typing.py
# 8 passed

git diff --check upstream/main...HEAD also passes. I do not see a branch-scoped change to make from the available evidence; could someone with repo permissions rerun the failed Linux jobs?

@puneetdixit200 puneetdixit200 force-pushed the route-handler-awaitable-type branch from 2d942d8 to 03379c5 Compare June 2, 2026 21:57
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.

unused-coroutine mypy error when not using route handlers as a decorator

1 participant