-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into make_schema_gen_better
- Loading branch information
Showing
7 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,34 @@ | ||
from typing import Literal, Union | ||
|
||
import pytest | ||
from typing_extensions import Annotated | ||
|
||
from pydantic import BaseModel, Discriminator | ||
from pydantic.dataclasses import dataclass | ||
|
||
|
||
@dataclass(frozen=True, kw_only=True) | ||
class Cat: | ||
type: Literal['cat'] = 'cat' | ||
|
||
|
||
@dataclass(frozen=True, kw_only=True) | ||
class Dog: | ||
type: Literal['dog'] = 'dog' | ||
|
||
|
||
@dataclass(frozen=True, kw_only=True) | ||
class NestedDataClass: | ||
animal: Annotated[Union[Cat, Dog], Discriminator('type')] | ||
|
||
|
||
class NestedModel(BaseModel): | ||
animal: Annotated[Union[Cat, Dog], Discriminator('type')] | ||
|
||
|
||
@pytest.mark.benchmark | ||
def test_construct_schema(): | ||
@dataclass(frozen=True, kw_only=True) | ||
class Root: | ||
data_class: NestedDataClass | ||
model: NestedModel |
This file contains 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