Skip to content

Commit cd3569b

Browse files
authored
test: align v2 parser baselines before v1 output removal (#3032)
* test: align v2 parser baselines before v1 output removal * test: restore v1 baseline coverage
1 parent 03200be commit cd3569b

335 files changed

Lines changed: 2812 additions & 3078 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/datamodel_code_generator/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
PythonVersion,
4040
PythonVersionMin,
4141
)
42-
from datamodel_code_generator.model import pydantic as pydantic_model
42+
from datamodel_code_generator.model import pydantic_v2
4343
from datamodel_code_generator.model.base import ( # noqa: TC001 - used by Pydantic at runtime
4444
DataModel,
4545
DataModelFieldBase,
@@ -205,10 +205,10 @@ class ParserConfig(BaseModel):
205205

206206
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
207207

208-
data_model_type: type[DataModel] = pydantic_model.BaseModel
209-
data_model_root_type: type[DataModel] = pydantic_model.CustomRootType
210-
data_type_manager_type: type[DataTypeManager] = pydantic_model.DataTypeManager
211-
data_model_field_type: type[DataModelFieldBase] = pydantic_model.DataModelField
208+
data_model_type: type[DataModel] = pydantic_v2.BaseModel
209+
data_model_root_type: type[DataModel] = pydantic_v2.RootModel
210+
data_type_manager_type: type[DataTypeManager] = pydantic_v2.DataTypeManager
211+
data_model_field_type: type[DataModelFieldBase] = pydantic_v2.DataModelField
212212
base_class: str | None = None
213213
base_class_map: dict[str, str | list[str]] | None = None
214214
additional_imports: list[str] | None = None

src/datamodel_code_generator/parser/base.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
)
6565
from datamodel_code_generator.model import dataclass as dataclass_model
6666
from datamodel_code_generator.model import msgspec as msgspec_model
67-
from datamodel_code_generator.model import pydantic as pydantic_model
6867
from datamodel_code_generator.model import pydantic_v2 as pydantic_model_v2
6968
from datamodel_code_generator.model.base import (
7069
ALL_MODEL,
@@ -1112,7 +1111,7 @@ def field_name_model_type(self) -> ModelType:
11121111
"""
11131112
if issubclass(
11141113
self.data_model_type,
1115-
(pydantic_model.BaseModel, pydantic_model_v2.BaseModel),
1114+
(pydantic_model_v2.BaseModel,),
11161115
):
11171116
return ModelType.PYDANTIC
11181117
return ModelType.CLASS
@@ -1532,7 +1531,7 @@ def __apply_discriminator_type( # noqa: PLR0912, PLR0914, PLR0915
15321531
type_names: list[str] = []
15331532

15341533
def check_paths(
1535-
model: pydantic_model.BaseModel | pydantic_model_v2.BaseModel | Reference,
1534+
model: pydantic_model_v2.BaseModel | Reference,
15361535
mapping: dict[str, str],
15371536
type_names: list[str] = type_names,
15381537
) -> None:
@@ -1602,7 +1601,6 @@ def check_paths(
16021601
if not isinstance( # pragma: no cover
16031602
base_model,
16041603
(
1605-
pydantic_model.BaseModel,
16061604
pydantic_model_v2.BaseModel,
16071605
dataclass_model.DataClass,
16081606
msgspec_model.Struct,
@@ -1852,7 +1850,6 @@ def __create_shared_module_from_duplicates( # noqa: PLR0912
18521850
supports_inheritance = issubclass(
18531851
self.data_model_type,
18541852
(
1855-
pydantic_model.BaseModel,
18561853
pydantic_model_v2.BaseModel,
18571854
dataclass_model.DataClass,
18581855
),
@@ -1915,10 +1912,6 @@ def __reuse_model_tree_scope(
19151912
self.__validate_shared_module_name(module_models)
19161913
return self.__create_shared_module_from_duplicates(module_models, duplicates, require_update_action_models)
19171914

1918-
def _is_pydantic_v2_model(self) -> bool:
1919-
"""Check if the output model type is Pydantic v2."""
1920-
return self.data_model_type.__module__.startswith("datamodel_code_generator.model.pydantic_v2")
1921-
19221915
def __collapse_root_models( # noqa: PLR0912, PLR0914, PLR0915
19231916
self,
19241917
models: list[DataModel],
@@ -2037,9 +2030,7 @@ def __collapse_root_models( # noqa: PLR0912, PLR0914, PLR0915
20372030
root_type_field.constraints, model_field.constraints
20382031
)
20392032
discriminator = root_type_field.extras.get("discriminator")
2040-
if discriminator and isinstance(
2041-
root_type_field, (pydantic_model.DataModelField, pydantic_model_v2.DataModelField)
2042-
):
2033+
if discriminator and isinstance(root_type_field, pydantic_model_v2.DataModelField):
20432034
has_any_variant = any(
20442035
dt.type == ANY
20452036
or (not dt.reference and not dt.data_types and not dt.literals and not dt.type)
@@ -2051,8 +2042,7 @@ def __collapse_root_models( # noqa: PLR0912, PLR0914, PLR0915
20512042
if isinstance(discriminator, dict)
20522043
else discriminator
20532044
)
2054-
if self._is_pydantic_v2_model():
2055-
copied_data_type.discriminator = prop_name
2045+
copied_data_type.discriminator = prop_name
20562046
assert isinstance(data_type.parent, DataType)
20572047
data_type.parent.data_types.remove(data_type)
20582048
data_type.parent.data_types.append(copied_data_type)

tests/data/expected/main/class_decorators_pydantic_BaseModel.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/data/expected/main/graphql/additional_imports.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,31 @@
55
from __future__ import annotations
66

77
from datetime import date, datetime
8-
from typing import Literal, TypeAlias
8+
from typing import Literal
99

1010
from mymodule.myclass import MyCustomPythonClass
1111
from pydantic import BaseModel, Field
12+
from typing_extensions import TypeAliasType
1213

13-
Boolean: TypeAlias = bool
14+
Boolean = TypeAliasType("Boolean", bool)
1415
"""
1516
The `Boolean` scalar type represents `true` or `false`.
1617
"""
1718

1819

19-
Date: TypeAlias = date
20+
Date = TypeAliasType("Date", date)
2021

2122

22-
DateTime: TypeAlias = datetime
23+
DateTime = TypeAliasType("DateTime", datetime)
2324
"""
2425
DateTime (ISO8601, example: 2020-01-01T10:11:12+00:00)
2526
"""
2627

2728

28-
MyCustomClass: TypeAlias = MyCustomPythonClass
29+
MyCustomClass = TypeAliasType("MyCustomClass", MyCustomPythonClass)
2930

3031

31-
String: TypeAlias = str
32+
String = TypeAliasType("String", str)
3233
"""
3334
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.
3435
"""

tests/data/expected/main/graphql/annotated_use_default_kwarg.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44

55
from __future__ import annotations
66

7-
from typing import Literal, TypeAlias
7+
from typing import Literal
88

99
from pydantic import BaseModel, Field
10+
from typing_extensions import TypeAliasType
1011

11-
Boolean: TypeAlias = bool
12+
Boolean = TypeAliasType("Boolean", bool)
1213
"""
1314
The `Boolean` scalar type represents `true` or `false`.
1415
"""
1516

1617

17-
String: TypeAlias = str
18+
String = TypeAliasType("String", str)
1819
"""
1920
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.
2021
"""

tests/data/expected/main/graphql/casing.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@
55
from __future__ import annotations
66

77
from enum import Enum
8-
from typing import Literal, TypeAlias
8+
from typing import Literal
99

1010
from pydantic import BaseModel, Field
11+
from typing_extensions import TypeAliasType
1112

12-
Boolean: TypeAlias = bool
13+
Boolean = TypeAliasType("Boolean", bool)
1314
"""
1415
The `Boolean` scalar type represents `true` or `false`.
1516
"""
1617

1718

18-
Int: TypeAlias = int
19+
Int = TypeAliasType("Int", int)
1920
"""
2021
The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
2122
"""
2223

2324

24-
String: TypeAlias = str
25+
String = TypeAliasType("String", str)
2526
"""
2627
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.
2728
"""

tests/data/expected/main/graphql/custom_formatters.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@
55
# a comment
66
from __future__ import annotations
77

8-
from typing import Literal, TypeAlias
8+
from typing import Literal
99

1010
from pydantic import BaseModel, Field
11+
from typing_extensions import TypeAliasType
1112

12-
Boolean: TypeAlias = bool
13+
Boolean = TypeAliasType("Boolean", bool)
1314
"""
1415
The `Boolean` scalar type represents `true` or `false`.
1516
"""
1617

1718

18-
ID: TypeAlias = str
19+
ID = TypeAliasType("ID", str)
1920
"""
2021
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.
2122
"""
2223

2324

24-
Long: TypeAlias = str
25+
Long = TypeAliasType("Long", str)
2526

2627

27-
String: TypeAlias = str
28+
String = TypeAliasType("String", str)
2829
"""
2930
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.
3031
"""

tests/data/expected/main/graphql/custom_scalar_types.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@
44

55
from __future__ import annotations
66

7-
from typing import Literal, TypeAlias
7+
from typing import Literal
88

99
from pydantic import BaseModel, Field
10+
from typing_extensions import TypeAliasType
1011

11-
Boolean: TypeAlias = bool
12+
Boolean = TypeAliasType("Boolean", bool)
1213
"""
1314
The `Boolean` scalar type represents `true` or `false`.
1415
"""
1516

1617

17-
ID: TypeAlias = str
18+
ID = TypeAliasType("ID", str)
1819
"""
1920
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.
2021
"""
2122

2223

23-
Long: TypeAlias = int
24+
Long = TypeAliasType("Long", int)
2425

2526

26-
String: TypeAlias = str
27+
String = TypeAliasType("String", str)
2728
"""
2829
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.
2930
"""

tests/data/expected/main/graphql/default_values_required_use_default.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@
44

55
from __future__ import annotations
66

7-
from typing import Literal, TypeAlias
7+
from typing import Literal
88

99
from pydantic import BaseModel, Field
10+
from typing_extensions import TypeAliasType
1011

11-
Boolean: TypeAlias = bool
12+
Boolean = TypeAliasType("Boolean", bool)
1213
"""
1314
The `Boolean` scalar type represents `true` or `false`.
1415
"""
1516

1617

17-
ID: TypeAlias = str
18+
ID = TypeAliasType("ID", str)
1819
"""
1920
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.
2021
"""
2122

2223

23-
String: TypeAlias = str
24+
String = TypeAliasType("String", str)
2425
"""
2526
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.
2627
"""

tests/data/expected/main/graphql/different_types_of_fields.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44

55
from __future__ import annotations
66

7-
from typing import Literal, TypeAlias
7+
from typing import Literal
88

99
from pydantic import BaseModel, Field
10+
from typing_extensions import TypeAliasType
1011

11-
Boolean: TypeAlias = bool
12+
Boolean = TypeAliasType("Boolean", bool)
1213
"""
1314
The `Boolean` scalar type represents `true` or `false`.
1415
"""
1516

1617

17-
String: TypeAlias = str
18+
String = TypeAliasType("String", str)
1819
"""
1920
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.
2021
"""

0 commit comments

Comments
 (0)