Skip to content

fix: Improve Accept.best_match typing#4487

Merged
provinzkraut merged 4 commits intomainfrom
sobolevn-patch-3
Nov 22, 2025
Merged

fix: Improve Accept.best_match typing#4487
provinzkraut merged 4 commits intomainfrom
sobolevn-patch-3

Conversation

@sobolevn
Copy link
Copy Markdown
Member

@sobolevn sobolevn commented Nov 22, 2025

It used to be this way:

.best_match(['application/json'], default='application/json')
# -> reveals `Optional[str]` as the return type

However, default is str and 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 reveals str as the return type. Full testing is here: https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=8ae293ccffaaa2649ee0dfd5d6ff9245

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
@github-actions
Copy link
Copy Markdown

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/4487

@provinzkraut provinzkraut merged commit 8b74278 into main Nov 22, 2025
30 checks passed
@provinzkraut provinzkraut deleted the sobolevn-patch-3 branch November 22, 2025 10:14
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants