-
-
Notifications
You must be signed in to change notification settings - Fork 449
fix #3034 and #3035 by introducing ValidatedDefault
#3040
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c80e0e6
new fixtures
keyz f9fe0df
one more fixture
keyz ca51faa
fix
keyz d56b746
fix: use resolved.data_types for union branch filtering in _needs_val…
koxudaxi 46c96f6
Merge branch 'main' into keyz-fix-3034
koxudaxi ce4feec
more fixtures
keyz 1a5cb96
another fixture
keyz 7a5c516
use model-level capability, and defer set
keyz 54b947c
fix overrides
keyz f1f9f96
another fix
keyz 31833bf
one more
keyz 6121750
test: stub my_app for py312 exec validation
koxudaxi 3d3896e
Merge branch 'main' into keyz-fix-3034
koxudaxi c318230
test: cover validated default parser helpers
koxudaxi 689c7d6
test: cover remaining validated default branches
koxudaxi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
25 changes: 25 additions & 0 deletions
25
tests/data/expected/main/jsonschema/type_alias_chain_model_default_object_ref.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # generated by datamodel-codegen: | ||
| # filename: type_alias_chain_model_default_object_ref.json | ||
| # timestamp: 2019-07-26T00:00:00+00:00 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Literal | ||
|
|
||
| from pydantic import BaseModel, Field, TypeAdapter | ||
|
|
||
|
|
||
| class A(BaseModel): | ||
| type: Literal['a'] = 'a' | ||
|
|
||
|
|
||
| type Alias1 = A | ||
|
|
||
|
|
||
| type Alias2 = Alias1 | ||
|
|
||
|
|
||
| class Model(BaseModel): | ||
| x: Alias2 | None = Field( | ||
| default_factory=lambda: TypeAdapter(Alias2).validate_python({'type': 'a'}) | ||
| ) |
32 changes: 32 additions & 0 deletions
32
tests/data/expected/main/jsonschema/type_alias_chain_union_default_object_ref.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # generated by datamodel-codegen: | ||
| # filename: type_alias_chain_union_default_object_ref.json | ||
| # timestamp: 2019-07-26T00:00:00+00:00 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Annotated, Literal | ||
|
|
||
| from pydantic import BaseModel, Field, TypeAdapter | ||
|
|
||
|
|
||
| class A(BaseModel): | ||
| type: Literal['a'] = 'a' | ||
|
|
||
|
|
||
| class B(BaseModel): | ||
| type: Literal['b'] = 'b' | ||
|
|
||
|
|
||
| type Alias1 = A | B | ||
|
|
||
|
|
||
| type Alias2 = Alias1 | ||
|
|
||
|
|
||
| class Model(BaseModel): | ||
| x_value: Annotated[ | ||
| Alias2 | None, | ||
| Field( | ||
| default_factory=lambda: TypeAdapter(Alias2).validate_python({'type': 'b'}) | ||
| ), | ||
| ] |
32 changes: 32 additions & 0 deletions
32
tests/data/expected/main/jsonschema/type_alias_dict_union_default_object_ref.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # generated by datamodel-codegen: | ||
| # filename: type_alias_dict_union_default_object_ref.json | ||
| # timestamp: 2019-07-26T00:00:00+00:00 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Annotated, Literal | ||
|
|
||
| from pydantic import BaseModel, Field, TypeAdapter | ||
|
|
||
|
|
||
| class A(BaseModel): | ||
| type: Literal['a'] = 'a' | ||
|
|
||
|
|
||
| class B(BaseModel): | ||
| type: Literal['b'] | ||
| value: int | None = None | ||
|
|
||
|
|
||
| type Alias = dict[str, A | B] | ||
|
|
||
|
|
||
| class Model(BaseModel): | ||
| x_value: Annotated[ | ||
| Alias | None, | ||
| Field( | ||
| default_factory=lambda: TypeAdapter(Alias).validate_python( | ||
| {'k': {'type': 'b', 'value': 1}} | ||
| ) | ||
| ), | ||
| ] |
29 changes: 29 additions & 0 deletions
29
tests/data/expected/main/jsonschema/type_alias_inline_dict_union_default_object.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # generated by datamodel-codegen: | ||
| # filename: type_alias_inline_dict_union_default_object.json | ||
| # timestamp: 2019-07-26T00:00:00+00:00 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Annotated, Literal | ||
|
|
||
| from pydantic import BaseModel, Field, TypeAdapter | ||
|
|
||
|
|
||
| class A(BaseModel): | ||
| type: Literal['a'] = 'a' | ||
|
|
||
|
|
||
| class B(BaseModel): | ||
| type: Literal['b'] | ||
| value: int | None = None | ||
|
|
||
|
|
||
| class Model(BaseModel): | ||
| x_value: Annotated[ | ||
| dict[str, A | B] | None, | ||
| Field( | ||
| default_factory=lambda: TypeAdapter(dict[str, A | B]).validate_python( | ||
| {'k': {'type': 'b', 'value': 1}} | ||
| ) | ||
| ), | ||
| ] |
29 changes: 29 additions & 0 deletions
29
tests/data/expected/main/jsonschema/type_alias_inline_list_union_default_object.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # generated by datamodel-codegen: | ||
| # filename: type_alias_inline_list_union_default_object.json | ||
| # timestamp: 2019-07-26T00:00:00+00:00 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Annotated, Literal | ||
|
|
||
| from pydantic import BaseModel, Field, TypeAdapter | ||
|
|
||
|
|
||
| class A(BaseModel): | ||
| type: Literal['a'] = 'a' | ||
|
|
||
|
|
||
| class B(BaseModel): | ||
| type: Literal['b'] | ||
| value: int | None = None | ||
|
|
||
|
|
||
| class Model(BaseModel): | ||
| x_value: Annotated[ | ||
| list[A | B] | None, | ||
| Field( | ||
| default_factory=lambda: TypeAdapter(list[A | B]).validate_python( | ||
| [{'type': 'b', 'value': 1}] | ||
| ) | ||
| ), | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.