Skip to content

Update Route.respond json type hint to Any to match HTTPX#284

Merged
lundberg merged 3 commits intolundberg:masterfrom
JacobHayes:push-xrntwyqwtoyx
Apr 7, 2026
Merged

Update Route.respond json type hint to Any to match HTTPX#284
lundberg merged 3 commits intolundberg:masterfrom
JacobHayes:push-xrntwyqwtoyx

Conversation

@JacobHayes
Copy link
Copy Markdown
Contributor

The json parameter to Route.respond is missing hints for the List and Dict elements, which makes pyright sad in strict mode:

.../tests/test_url.py:6:5 - error: Type of "respond" is partially unknown
    Type of "respond" is "(status_code: int = 200, *, headers: Headers | Dict[str, str] | Dict[bytes, bytes] | Sequence[Tuple[str, str]] | Sequence[Tuple[bytes, bytes]] | None = None, cookies: Dict[str, str] | Sequence[Tuple[str, str]] | Sequence[SetCookie] | None = None, content: str | bytes | Iterable[bytes] | AsyncIterable[bytes] | None = None, text: str | None = None, html: str | None = None, json: str | List[Unknown] | Dict[Unknown, Unknown] | None = None, stream: SyncByteStream | AsyncByteStream | None = None, content_type: str | None = None, http_version: str | None = None, **kwargs: Any) -> Route" (reportUnknownMemberType)
1 error, 0 warnings, 0 informations

This PR just adds the hints for the elements. I think python's json.dump will accept arbitrary key types, but the JSON spec only defines strings so I used Dict[str, ...]. I'm happy to change that to Any if you'd prefer.

Thanks for the helpful library!

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a499260) to head (5e761fe).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #284   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         2934      2934           
  Branches       200       200           
=========================================
  Hits          2934      2934           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lundberg
Copy link
Copy Markdown
Owner

lundberg commented Jan 24, 2025

@JacobHayes, new discussions regarding this has come up in #290 and we're leaning towards typing json as Any instead, to align with httpx. That should please pyright for you as well, agree?

@JacobHayes JacobHayes force-pushed the push-xrntwyqwtoyx branch 2 times, most recently from 4a3a22c to 26e41e2 Compare January 24, 2025 16:36
@JacobHayes JacobHayes changed the title Add hints to generics in Route.respond Update Route.respond json type hint to Any to match HTTPX Jan 24, 2025
@JacobHayes
Copy link
Copy Markdown
Contributor Author

Yup, that should make pyright happy too! Just updated this PR to use Any, but feel free to merge whichever PR makes sense.

Signed-off-by: Jacob Hayes <jrh@jacobhayes.dev>
@mikenerone
Copy link
Copy Markdown

Just a ping. Hoping this can get in so Pyright will get off my back. :P

Co-authored-by: Mike Nerone <mike@nerone.org>
@JacobHayes
Copy link
Copy Markdown
Contributor Author

FYI @lundberg I'm guessing the nox version has changed and is causing the CI issues (which just does pip install nox, w/o pinning a version).

@lundberg lundberg merged commit e51c2a6 into lundberg:master Apr 7, 2026
12 checks passed
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.

3 participants