You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/root-model-and-type-alias.md
+15-4Lines changed: 15 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,12 +10,23 @@ When a schema defines a simple type (not an object with properties), `datamodel-
10
10
- A RootModel or type alias is also generated for the main schema, allowing you to define a single type alias from a schema file (e.g. `model.json` containing `{"title": "MyString", "type": "string"}`)
11
11
- Type aliases cannot be combined with `Annotated` for Pydantic v1
12
12
13
-
## Pydantic v1 vs v2
13
+
## Type Alias Behavior by Output Type and Python Version
14
14
15
-
The type of type alias generated depends on the Pydantic version:
15
+
The type of type alias generated depends on the output model type and target Python version:
-**Pydantic v2** requires `TypeAliasType` because it cannot properly handle `TypeAlias` annotations
28
+
-**Other output types** (TypedDict, dataclasses, msgspec) use `TypeAlias` for better compatibility with libraries that may not expect `TypeAliasType` objects
29
+
-**Python 3.12+** uses the native `type` statement for all output types
Copy file name to clipboardExpand all lines: tests/data/expected/main/graphql/simple_star_wars_dataclass.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -7,27 +7,27 @@
7
7
fromdataclassesimportdataclass
8
8
fromtypingimportList, Literal, Optional
9
9
10
-
fromtyping_extensionsimportTypeAliasType
10
+
fromtyping_extensionsimportTypeAlias
11
11
12
-
Boolean=TypeAliasType("Boolean", bool)
12
+
Boolean: TypeAlias=bool
13
13
"""
14
14
The `Boolean` scalar type represents `true` or `false`.
15
15
"""
16
16
17
17
18
-
ID=TypeAliasType("ID", str)
18
+
ID: TypeAlias=str
19
19
"""
20
20
The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID.
21
21
"""
22
22
23
23
24
-
Int=TypeAliasType("Int", int)
24
+
Int: TypeAlias=int
25
25
"""
26
26
The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
27
27
"""
28
28
29
29
30
-
String=TypeAliasType("String", str)
30
+
String: TypeAlias=str
31
31
"""
32
32
The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
Copy file name to clipboardExpand all lines: tests/data/expected/main/graphql/simple_star_wars_dataclass_arguments.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -7,27 +7,27 @@
7
7
fromdataclassesimportdataclass
8
8
fromtypingimportList, Literal, Optional
9
9
10
-
fromtyping_extensionsimportTypeAliasType
10
+
fromtyping_extensionsimportTypeAlias
11
11
12
-
Boolean=TypeAliasType("Boolean", bool)
12
+
Boolean: TypeAlias=bool
13
13
"""
14
14
The `Boolean` scalar type represents `true` or `false`.
15
15
"""
16
16
17
17
18
-
ID=TypeAliasType("ID", str)
18
+
ID: TypeAlias=str
19
19
"""
20
20
The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID.
21
21
"""
22
22
23
23
24
-
Int=TypeAliasType("Int", int)
24
+
Int: TypeAlias=int
25
25
"""
26
26
The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
27
27
"""
28
28
29
29
30
-
String=TypeAliasType("String", str)
30
+
String: TypeAlias=str
31
31
"""
32
32
The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
0 commit comments