-
-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support standard collections for type hinting (list, dict) (#263)
* support standard collections for type hinting (list, dict) * fix types
- Loading branch information
Showing
18 changed files
with
296 additions
and
40 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
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
34 changes: 34 additions & 0 deletions
34
tests/data/expected/main/main_use_standard_collections/__init__.py
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 @@ | ||
# generated by datamodel-codegen: | ||
# filename: modular.yaml | ||
# timestamp: 1985-10-26T08:21:00+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
from . import foo, models | ||
from .nested import foo as foo_1 | ||
|
||
|
||
class Id(BaseModel): | ||
__root__: str | ||
|
||
|
||
class Error(BaseModel): | ||
code: int | ||
message: str | ||
|
||
|
||
class Result(BaseModel): | ||
event: Optional[models.Event] = None | ||
|
||
|
||
class Source(BaseModel): | ||
country: Optional[str] = None | ||
|
||
|
||
class DifferentTea(BaseModel): | ||
foo: Optional[foo.Tea] = None | ||
nested: Optional[foo_1.Tea] = None |
42 changes: 42 additions & 0 deletions
42
tests/data/expected/main/main_use_standard_collections/collections.py
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,42 @@ | ||
# generated by datamodel-codegen: | ||
# filename: modular.yaml | ||
# timestamp: 1985-10-26T08:21:00+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
|
||
from pydantic import AnyUrl, BaseModel, Field | ||
|
||
from . import models | ||
|
||
|
||
class Pets(BaseModel): | ||
__root__: list[models.Pet] | ||
|
||
|
||
class Users(BaseModel): | ||
__root__: list[models.User] | ||
|
||
|
||
class Rules(BaseModel): | ||
__root__: list[str] | ||
|
||
|
||
class Api(BaseModel): | ||
apiKey: Optional[str] = Field( | ||
None, description='To be used as a dataset parameter value' | ||
) | ||
apiVersionNumber: Optional[str] = Field( | ||
None, description='To be used as a version parameter value' | ||
) | ||
apiUrl: Optional[AnyUrl] = Field( | ||
None, description="The URL describing the dataset's fields" | ||
) | ||
apiDocumentationUrl: Optional[AnyUrl] = Field( | ||
None, description='A URL to the API console for each API' | ||
) | ||
|
||
|
||
class Apis(BaseModel): | ||
__root__: list[Api] |
20 changes: 20 additions & 0 deletions
20
tests/data/expected/main/main_use_standard_collections/foo/__init__.py
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,20 @@ | ||
# generated by datamodel-codegen: | ||
# filename: modular.yaml | ||
# timestamp: 1985-10-26T08:21:00+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
from .. import Id | ||
|
||
|
||
class Tea(BaseModel): | ||
flavour: Optional[str] = None | ||
id: Optional[Id] = None | ||
|
||
|
||
class Cocoa(BaseModel): | ||
quality: Optional[int] = None |
21 changes: 21 additions & 0 deletions
21
tests/data/expected/main/main_use_standard_collections/foo/bar.py
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,21 @@ | ||
# generated by datamodel-codegen: | ||
# filename: modular.yaml | ||
# timestamp: 1985-10-26T08:21:00+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Any, Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Thing(BaseModel): | ||
attributes: Optional[dict[str, Any]] = None | ||
|
||
|
||
class Thang(BaseModel): | ||
attributes: Optional[list[dict[str, Any]]] = None | ||
|
||
|
||
class Clone(Thing): | ||
pass |
Oops, something went wrong.