-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Do not evaluate annotations for private fields #10962
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
Conversation
fe38cc5 to
2861b87
Compare
Deploying pydantic-docs with
|
| Latest commit: |
213b274
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e420a41e.pydantic-docs.pages.dev |
| Branch Preview URL: | https://private-fields-eval.pydantic-docs.pages.dev |
CodSpeed Performance ReportMerging #10962 will not alter performanceComparing Summary
|
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
2d35039 to
76460e2
Compare
|
Nice! |
76460e2 to
8446583
Compare
The `get_cls_type_hints` function is now split up, by defining a new `get_model_type_hints` function that is lenient. `get_cls_type_hints` is made non-lenient because it is used for typed dictionaries and named tuples, where we want to eagerly raise the `NameError`s that can occur during evaluation. While this may introduce some code duplication, this gives more flexibility in the future. For instance, we know from the namespace management refactor that typed dicts behaves quite differently from normal classes when it comes to using the `__annotations__` attribute (collected from bases by cpython, automatically converted to `ForwardRef` instances, etc). So we might define another separate `get_typed_dict_type_hints` function in the future.
8446583 to
213b274
Compare
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.
Looks good, thanks @Viicos.
We might be able to reuse some shared logic between these functions in a future refactor, but the fix here is pretty simple, so I think we should get this across the line now 👍
The Pydantic 2.10.0/2.10.1 workaround implemented in apache#44317 is not needed any more as it has been fixed in Pydantic 2.10.2 in the pydantic/pydantic#10962 This PR removes the workaround and bumps min Pydantic version to 2.10.2.
The Pydantic 2.10.0/2.10.1 workaround implemented in #44317 is not needed any more as it has been fixed in Pydantic 2.10.2 in the pydantic/pydantic#10962 This PR removes the workaround and bumps min Pydantic version to 2.10.2.
The Pydantic 2.10.0/2.10.1 workaround implemented in apache#44317 is not needed any more as it has been fixed in Pydantic 2.10.2 in the pydantic/pydantic#10962 This PR removes the workaround and bumps min Pydantic version to 2.10.2.
The Pydantic 2.10.0/2.10.1 workaround implemented in apache#44317 is not needed any more as it has been fixed in Pydantic 2.10.2 in the pydantic/pydantic#10962 This PR removes the workaround and bumps min Pydantic version to 2.10.2.
The Pydantic 2.10.0/2.10.1 workaround implemented in apache#44317 is not needed any more as it has been fixed in Pydantic 2.10.2 in the pydantic/pydantic#10962 This PR removes the workaround and bumps min Pydantic version to 2.10.2.
The Pydantic 2.10.0/2.10.1 workaround implemented in #44317 is not needed any more as it has been fixed in Pydantic 2.10.2 in the pydantic/pydantic#10962 This PR removes the workaround and bumps min Pydantic version to 2.10.2. GitOrigin-RevId: b134ed089b74021858ded34dbc021ef053427650
Doing so fixes #10958 and gtalarico/pyairtable#411. We don't need to evaluate annotation for private fields because we will not make use of the type hint in any way.
The
get_cls_type_hintsfunction is now split up, by defining a newget_model_type_hintsfunction that is lenient.get_cls_type_hintsis made non-lenient because it is used for typed dictionaries and named tuples, where we want to eagerly raise theNameErrors that can occur during evaluation.While this may introduce some code duplication, this gives more flexibility in the future. For instance, we know from the namespace management refactor that typed dicts behaves quite differently from normal classes when it comes to using the
__annotations__attribute (collected from bases by cpython, automatically converted toForwardRefinstances, etc). So we might define another separateget_typed_dict_type_hintsfunction in the future.Change Summary
Related issue number
Checklist