Skip to content

Conversation

@JacobHayes
Copy link

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

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (1f3626d) to head (d477ddc).
Report is 3 commits behind head on master.

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

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

@lundberg
Copy link
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
Author

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

@mikenerone
Copy link

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

Co-authored-by: Mike Nerone <[email protected]>
@JacobHayes
Copy link
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).

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