-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix BaseModel type annotations to be resolvable by typing.get_type_hints #7680
Fix BaseModel type annotations to be resolvable by typing.get_type_hints #7680
Conversation
Thanks for your contribution here. Is this ready to review? If so, could you please rebase to resolve the conflicts with |
CodSpeed Performance ReportMerging #7680 will not alter performanceComparing Summary
|
Currently running into some test issues related to this: #8307 |
I think the right path forward here is to implement a solution that works for Python 3.10+ and add xfails to tests for 3.8 and 3.9. |
Please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with just a brief question on the tests which may or may not be worth following up on.
|
||
def inspect_type_hints( | ||
obj_type, members: Optional[Set[str]] = None, exclude_members: Optional[Set[str]] = None, recursion_limit: int = 3 | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to return the hints from this function, so that they can be asserted to be of the correct form? Or is there just way too much stuff there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. They're pretty gnarly, so I'd opt to skip returning for now. Down the line, if someone's feeling quite invested, they could make the addition, but I don't see it as a blocker on this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
welp, i was in the process of reviewing
|
||
TupleGenerator = typing.Generator[typing.Tuple[str, Any], None, None] | ||
Model = typing.TypeVar('Model', bound='BaseModel') | ||
# should be `set[int] | set[str] | dict[int, IncEx] | dict[str, IncEx] | None`, but mypy can't cope |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment should be moved. Or better yet addressed - can mypy not handle pydantic.config.JsonValue
?
Fix BaseModel type annotations to be resolvable by typing.get_type_hints (#7623)
Change Summary
Updated required
main.py
type definitions used with non-deprecatedBaseModel
methods to always be defined, instead of conditionally whentyping.TYPE_CHECKING
.Related issue number
Fix #7623
Checklist
Selected Reviewer: @davidhewitt