-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix forward ref in generic #6511
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
Fixes #6503 skip change file check
|
please review |
Deploying with
|
| Latest commit: |
b885eac
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c930025c.pydantic-docs2.pages.dev |
| Branch Preview URL: | https://fix-forward-ref-in-generic.pydantic-docs2.pages.dev |
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, just see the suggestions about the tests
| Foo = module.Foo | ||
| Bar = module.Bar | ||
|
|
||
| assert Foo(x={Bar: Bar}).x[Bar] is Bar |
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.
| assert Foo(x={Bar: Bar}).x[Bar] is Bar | |
| assert Foo(x={Bar: Bar}).x[Bar] is Bar | |
| def test_forward_ref_in_generic_separate_modules(create_module: Any) -> None: | |
| """https://github.com/pydantic/pydantic/issues/6503""" | |
| @create_module | |
| def module_1(): | |
| import typing as tp | |
| from pydantic import BaseModel | |
| class Foo(BaseModel): | |
| x: tp.Dict['tp.Type[Bar]', tp.Type['Bar']] | |
| @create_module | |
| def module_2(): | |
| from pydantic import BaseModel | |
| class Bar(BaseModel): | |
| pass | |
| Foo = module_1.Foo | |
| Bar = module_2.Bar | |
| Foo.model_rebuild(_types_namespace={'tp': typing, 'Bar': Bar}) | |
| assert Foo(x={Bar: Bar}).x[Bar] is Bar |
(Also need to add import typing at the top of the file.)
This test makes sure it also works when the types aren't in the same module. I think it's worth adding but defer to you.
Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
Fixes #6503
skip change file check
Selected Reviewer: @samuelcolvin