fix: Improve Accept.best_match typing#4487
Merged
provinzkraut merged 4 commits intomainfrom Nov 22, 2025
Merged
Conversation
It used to be this way: ```python .best_match(['application/json'], default='application/json') # -> reveals `Optional[str]` as the return type ``` However, default is `str` and this is a typing error. Now it works as expected when passing `best_match(['application/json'], default='application/json')` and reveals `str` as the return type. Full testing is here: https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=bf3a081c25f31ddfd2da6614fb59deff
|
Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/4487 |
provinzkraut
approved these changes
Nov 22, 2025
provinzkraut
pushed a commit
that referenced
this pull request
Dec 13, 2025
* Improve `Accept.best_match` typing It used to be this way: ```python .best_match(['application/json'], default='application/json') # -> reveals `Optional[str]` as the return type ``` However, default is `str` and this is a typing error. Now it works as expected when passing `best_match(['application/json'], default='application/json')` and reveals `str` as the return type. Full testing is here: https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=bf3a081c25f31ddfd2da6614fb59deff * Update headers.py * Update headers.py * Update headers.py (cherry picked from commit 8b74278)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It used to be this way:
However, default is
strand this is a typing error.Example: https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=60f387573191d8b6357b6d1a6bf4383d
Now it works as expected when passing
best_match(['application/json'], default='application/json')and revealsstras the return type. Full testing is here: https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=8ae293ccffaaa2649ee0dfd5d6ff9245