refactor: Improve type annotations and use python 3.10+ syntax#14943
Closed
argoarsiks wants to merge 1 commit into
Closed
refactor: Improve type annotations and use python 3.10+ syntax#14943argoarsiks wants to merge 1 commit into
argoarsiks wants to merge 1 commit into
Conversation
YuriiMotov
reviewed
Feb 19, 2026
|
|
||
|
|
||
| def is_union_of_base_models(field_type: Any) -> bool: | ||
| def is_union_of_base_models(field_type: type) -> bool: |
Member
There was a problem hiding this comment.
mypy check...............................................................Failed
- hook id: local-mypy
- exit code: 1
fastapi/dependencies/utils.py:866: error: Argument 1 to "is_union_of_base_models" has incompatible type "type[Any] | None"; expected "type" [arg-type]
Found 1 error in 1 file (checked 47 source files)
5f006e5 to
1f89f7b
Compare
YuriiMotov
reviewed
Feb 23, 2026
Member
YuriiMotov
left a comment
There was a problem hiding this comment.
@argoarsiks, thanks for your interest!
I think we don't need these changes..
| scheme_name: str | None, | ||
| auto_error: bool, | ||
| ): | ||
| ) -> None: |
Member
There was a problem hiding this comment.
It's not necessary to specify return type annotation for __init__ methods.
If we want to enforce this, we should enable such rule for linter
| arg | ||
| for arg in annotated_args[1:] | ||
| if isinstance(arg, (FieldInfo, params.Depends)) | ||
| if isinstance(arg, FieldInfo | params.Depends) |
Member
There was a problem hiding this comment.
With this syntax, performance decreases.
See astral-sh/ruff#7871
|
|
||
|
|
||
| def is_union_of_base_models(field_type: Any) -> bool: | ||
| def is_union_of_base_models(field_type: type | None) -> bool: |
Member
There was a problem hiding this comment.
I don't think this is necessary. In utils.py we still pass first_field.field_info.annotation which is of type Any
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.
X | Ysyntax for isinstance calls