diff --git a/datamodel_code_generator/__init__.py b/datamodel_code_generator/__init__.py index e27a73cb0..251d92529 100644 --- a/datamodel_code_generator/__init__.py +++ b/datamodel_code_generator/__init__.py @@ -236,7 +236,7 @@ def generate( input_file_type: InputFileType = InputFileType.Auto, output: Optional[Path] = None, output_model_type: DataModelType = DataModelType.PydanticBaseModel, - target_python_version: PythonVersion = PythonVersion.PY_37, + target_python_version: PythonVersion = PythonVersion.PY_38, base_class: str = '', additional_imports: Optional[List[str]] = None, custom_template_dir: Optional[Path] = None, diff --git a/datamodel_code_generator/__main__.py b/datamodel_code_generator/__main__.py index 6272bbd3e..907031866 100644 --- a/datamodel_code_generator/__main__.py +++ b/datamodel_code_generator/__main__.py @@ -248,7 +248,7 @@ def validate_root(cls, values: Any) -> Any: output: Optional[Path] = None debug: bool = False disable_warnings: bool = False - target_python_version: PythonVersion = PythonVersion.PY_37 + target_python_version: PythonVersion = PythonVersion.PY_38 base_class: str = '' additional_imports: Optional[List[str]] = (None,) custom_template_dir: Optional[Path] = None diff --git a/datamodel_code_generator/arguments.py b/datamodel_code_generator/arguments.py index 1990b0557..6520f8b19 100644 --- a/datamodel_code_generator/arguments.py +++ b/datamodel_code_generator/arguments.py @@ -157,7 +157,7 @@ def start_section(self, heading: Optional[str]) -> None: ) model_options.add_argument( '--target-python-version', - help='target python version (default: 3.7)', + help='target python version (default: 3.8)', choices=[v.value for v in PythonVersion], ) model_options.add_argument( diff --git a/datamodel_code_generator/model/pydantic/types.py b/datamodel_code_generator/model/pydantic/types.py index 4f0e20982..459079f7f 100644 --- a/datamodel_code_generator/model/pydantic/types.py +++ b/datamodel_code_generator/model/pydantic/types.py @@ -151,7 +151,7 @@ class DataTypeManager(_DataTypeManager): def __init__( self, - python_version: PythonVersion = PythonVersion.PY_37, + python_version: PythonVersion = PythonVersion.PY_38, use_standard_collections: bool = False, use_generic_container_types: bool = False, strict_types: Optional[Sequence[StrictTypes]] = None, diff --git a/datamodel_code_generator/model/pydantic_v2/base_model.py b/datamodel_code_generator/model/pydantic_v2/base_model.py index 4becc601e..7f5cf0757 100644 --- a/datamodel_code_generator/model/pydantic_v2/base_model.py +++ b/datamodel_code_generator/model/pydantic_v2/base_model.py @@ -1,7 +1,6 @@ import re from pathlib import Path from typing import ( - TYPE_CHECKING, Any, ClassVar, DefaultDict, @@ -13,6 +12,7 @@ ) from pydantic import Field +from typing_extensions import Literal from datamodel_code_generator.model.base import UNDEFINED, DataModelFieldBase from datamodel_code_generator.model.pydantic.base_model import ( @@ -28,14 +28,6 @@ from datamodel_code_generator.reference import Reference from datamodel_code_generator.util import field_validator, model_validator -if TYPE_CHECKING: - from typing_extensions import Literal -else: - try: - from typing import Literal - except ImportError: # pragma: no cover - from typing_extensions import Literal - class Constraints(_Constraints): # To override existing pattern alias diff --git a/datamodel_code_generator/model/pydantic_v2/root_model.py b/datamodel_code_generator/model/pydantic_v2/root_model.py index 2cf518874..c88e25083 100644 --- a/datamodel_code_generator/model/pydantic_v2/root_model.py +++ b/datamodel_code_generator/model/pydantic_v2/root_model.py @@ -1,12 +1,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, ClassVar, Optional +from typing import Any, ClassVar, Literal, Optional from datamodel_code_generator.model.pydantic_v2.base_model import BaseModel -if TYPE_CHECKING: - from typing_extensions import Literal - class RootModel(BaseModel): TEMPLATE_FILE_PATH: ClassVar[str] = 'pydantic_v2/RootModel.jinja2' diff --git a/datamodel_code_generator/model/types.py b/datamodel_code_generator/model/types.py index 2371e1f5d..6905f5f40 100644 --- a/datamodel_code_generator/model/types.py +++ b/datamodel_code_generator/model/types.py @@ -52,7 +52,7 @@ def type_map_factory( class DataTypeManager(_DataTypeManager): def __init__( self, - python_version: PythonVersion = PythonVersion.PY_37, + python_version: PythonVersion = PythonVersion.PY_38, use_standard_collections: bool = False, use_generic_container_types: bool = False, strict_types: Optional[Sequence[StrictTypes]] = None, diff --git a/datamodel_code_generator/parser/base.py b/datamodel_code_generator/parser/base.py index 5e2663bb1..2018b2eea 100644 --- a/datamodel_code_generator/parser/base.py +++ b/datamodel_code_generator/parser/base.py @@ -342,7 +342,7 @@ def __init__( additional_imports: Optional[List[str]] = None, custom_template_dir: Optional[Path] = None, extra_template_data: Optional[DefaultDict[str, Dict[str, Any]]] = None, - target_python_version: PythonVersion = PythonVersion.PY_37, + target_python_version: PythonVersion = PythonVersion.PY_38, dump_resolve_reference_action: Optional[Callable[[Iterable[str]], str]] = None, validation: bool = False, field_constraints: bool = False, diff --git a/datamodel_code_generator/parser/graphql.py b/datamodel_code_generator/parser/graphql.py index f61644b28..29ecc8b9b 100644 --- a/datamodel_code_generator/parser/graphql.py +++ b/datamodel_code_generator/parser/graphql.py @@ -98,7 +98,7 @@ def __init__( additional_imports: Optional[List[str]] = None, custom_template_dir: Optional[Path] = None, extra_template_data: Optional[DefaultDict[str, Dict[str, Any]]] = None, - target_python_version: PythonVersion = PythonVersion.PY_37, + target_python_version: PythonVersion = PythonVersion.PY_38, dump_resolve_reference_action: Optional[Callable[[Iterable[str]], str]] = None, validation: bool = False, field_constraints: bool = False, diff --git a/datamodel_code_generator/parser/jsonschema.py b/datamodel_code_generator/parser/jsonschema.py index 428bda0a6..d4f33f70a 100644 --- a/datamodel_code_generator/parser/jsonschema.py +++ b/datamodel_code_generator/parser/jsonschema.py @@ -384,7 +384,7 @@ def __init__( additional_imports: Optional[List[str]] = None, custom_template_dir: Optional[Path] = None, extra_template_data: Optional[DefaultDict[str, Dict[str, Any]]] = None, - target_python_version: PythonVersion = PythonVersion.PY_37, + target_python_version: PythonVersion = PythonVersion.PY_38, dump_resolve_reference_action: Optional[Callable[[Iterable[str]], str]] = None, validation: bool = False, field_constraints: bool = False, diff --git a/datamodel_code_generator/parser/openapi.py b/datamodel_code_generator/parser/openapi.py index 89ad80314..fd52de87b 100644 --- a/datamodel_code_generator/parser/openapi.py +++ b/datamodel_code_generator/parser/openapi.py @@ -165,7 +165,7 @@ def __init__( additional_imports: Optional[List[str]] = None, custom_template_dir: Optional[Path] = None, extra_template_data: Optional[DefaultDict[str, Dict[str, Any]]] = None, - target_python_version: PythonVersion = PythonVersion.PY_37, + target_python_version: PythonVersion = PythonVersion.PY_38, dump_resolve_reference_action: Optional[Callable[[Iterable[str]], str]] = None, validation: bool = False, field_constraints: bool = False, diff --git a/datamodel_code_generator/types.py b/datamodel_code_generator/types.py index 0aff55b85..00ab1a873 100644 --- a/datamodel_code_generator/types.py +++ b/datamodel_code_generator/types.py @@ -261,7 +261,7 @@ class Config: is_func: bool = False kwargs: Optional[Dict[str, Any]] = None import_: Optional[Import] = None - python_version: PythonVersion = PythonVersion.PY_37 + python_version: PythonVersion = PythonVersion.PY_38 is_optional: bool = False is_dict: bool = False is_list: bool = False @@ -567,7 +567,7 @@ class Types(Enum): class DataTypeManager(ABC): def __init__( self, - python_version: PythonVersion = PythonVersion.PY_37, + python_version: PythonVersion = PythonVersion.PY_38, use_standard_collections: bool = False, use_generic_container_types: bool = False, strict_types: Optional[Sequence[StrictTypes]] = None, diff --git a/datamodel_code_generator/util.py b/datamodel_code_generator/util.py index e90029bbf..d8f4e7dc2 100644 --- a/datamodel_code_generator/util.py +++ b/datamodel_code_generator/util.py @@ -24,7 +24,8 @@ PYDANTIC_V2: bool = PYDANTIC_VERSION >= version.parse('2.0b3') if TYPE_CHECKING: - from typing_extensions import Literal + from typing import Literal + from yaml import SafeLoader def load_toml(path: Path) -> Dict[str, Any]: ... diff --git a/tests/data/expected/main/graphql/additional_imports_isort4.py b/tests/data/expected/main/graphql/additional_imports_isort4.py index a7f73690e..51b2a3251 100644 --- a/tests/data/expected/main/graphql/additional_imports_isort4.py +++ b/tests/data/expected/main/graphql/additional_imports_isort4.py @@ -5,10 +5,9 @@ from __future__ import annotations from datetime import date, datetime -from typing import Optional, TypeAlias +from typing import Literal, Optional, TypeAlias from pydantic import BaseModel, Field -from typing_extensions import Literal from mymodule.myclass import MyCustomPythonClass diff --git a/tests/data/expected/main/graphql/additional_imports_isort5.py b/tests/data/expected/main/graphql/additional_imports_isort5.py index ee52103c0..ae6a684b7 100644 --- a/tests/data/expected/main/graphql/additional_imports_isort5.py +++ b/tests/data/expected/main/graphql/additional_imports_isort5.py @@ -5,11 +5,10 @@ from __future__ import annotations from datetime import date, datetime -from typing import Optional, TypeAlias +from typing import Literal ,Optional, TypeAlias from mymodule.myclass import MyCustomPythonClass from pydantic import BaseModel, Field -from typing_extensions import Literal Boolean: TypeAlias = bool """ diff --git a/tests/data/expected/main/graphql/annotated.py b/tests/data/expected/main/graphql/annotated.py index eb5d53ca9..7604294f4 100644 --- a/tests/data/expected/main/graphql/annotated.py +++ b/tests/data/expected/main/graphql/annotated.py @@ -4,10 +4,10 @@ from __future__ import annotations -from typing import List, Optional, TypeAlias +from typing import List, Literal, Optional, TypeAlias from pydantic import BaseModel, Field -from typing_extensions import Annotated, Literal +from typing_extensions import Annotated Boolean: TypeAlias = bool """ diff --git a/tests/data/expected/main/graphql/custom_formatters.py b/tests/data/expected/main/graphql/custom_formatters.py index 10f9c4950..914c2ef6a 100644 --- a/tests/data/expected/main/graphql/custom_formatters.py +++ b/tests/data/expected/main/graphql/custom_formatters.py @@ -5,10 +5,9 @@ # a comment from __future__ import annotations -from typing import Optional, TypeAlias +from typing import Literal, Optional, TypeAlias from pydantic import BaseModel, Field -from typing_extensions import Literal Boolean: TypeAlias = bool """ diff --git a/tests/data/expected/main/graphql/custom_scalar_types.py b/tests/data/expected/main/graphql/custom_scalar_types.py index 628a95971..ae5f89fc7 100644 --- a/tests/data/expected/main/graphql/custom_scalar_types.py +++ b/tests/data/expected/main/graphql/custom_scalar_types.py @@ -4,10 +4,10 @@ from __future__ import annotations -from typing import Optional, TypeAlias +from typing import Literal, Optional, TypeAlias from pydantic import BaseModel, Field -from typing_extensions import Literal + Boolean: TypeAlias = bool """ diff --git a/tests/data/expected/main/graphql/different_types_of_fields.py b/tests/data/expected/main/graphql/different_types_of_fields.py index dd85384b0..63362b5b7 100644 --- a/tests/data/expected/main/graphql/different_types_of_fields.py +++ b/tests/data/expected/main/graphql/different_types_of_fields.py @@ -4,10 +4,10 @@ from __future__ import annotations -from typing import List, Optional, TypeAlias +from typing import Literal, List, Optional, TypeAlias from pydantic import BaseModel, Field -from typing_extensions import Literal + Boolean: TypeAlias = bool """ diff --git a/tests/data/expected/main/graphql/field_aliases.py b/tests/data/expected/main/graphql/field_aliases.py index fd6c81671..669d08aa3 100644 --- a/tests/data/expected/main/graphql/field_aliases.py +++ b/tests/data/expected/main/graphql/field_aliases.py @@ -4,10 +4,9 @@ from __future__ import annotations -from typing import Optional, TypeAlias +from typing import Literal, Optional, TypeAlias from pydantic import BaseModel, Field -from typing_extensions import Literal Boolean: TypeAlias = bool """ diff --git a/tests/data/expected/main/graphql/github_api.py b/tests/data/expected/main/graphql/github_api.py index a21c842cb..92d540cde 100644 --- a/tests/data/expected/main/graphql/github_api.py +++ b/tests/data/expected/main/graphql/github_api.py @@ -6,10 +6,9 @@ from datetime import date, datetime from enum import Enum -from typing import List, Optional, TypeAlias, Union +from typing import Literal, List, Optional, TypeAlias, Union from pydantic import BaseModel, Field -from typing_extensions import Literal Base64String: TypeAlias = str """ diff --git a/tests/data/expected/main/graphql/simple_star_wars.py b/tests/data/expected/main/graphql/simple_star_wars.py index 1bc3d2bde..e5a2f9156 100644 --- a/tests/data/expected/main/graphql/simple_star_wars.py +++ b/tests/data/expected/main/graphql/simple_star_wars.py @@ -4,10 +4,9 @@ from __future__ import annotations -from typing import List, Optional, TypeAlias +from typing import Literal, List, Optional, TypeAlias from pydantic import BaseModel, Field -from typing_extensions import Literal Boolean: TypeAlias = bool """ diff --git a/tests/data/expected/main/graphql/simple_star_wars_dataclass.py b/tests/data/expected/main/graphql/simple_star_wars_dataclass.py index 478bdfd3c..f70986ebd 100644 --- a/tests/data/expected/main/graphql/simple_star_wars_dataclass.py +++ b/tests/data/expected/main/graphql/simple_star_wars_dataclass.py @@ -5,9 +5,8 @@ from __future__ import annotations from dataclasses import dataclass -from typing import List, Optional, TypeAlias +from typing import Literal, List, Optional, TypeAlias -from typing_extensions import Literal Boolean: TypeAlias = bool """ diff --git a/tests/data/expected/main/graphql/union.py b/tests/data/expected/main/graphql/union.py index 34a932a05..b0e208887 100644 --- a/tests/data/expected/main/graphql/union.py +++ b/tests/data/expected/main/graphql/union.py @@ -4,10 +4,9 @@ from __future__ import annotations -from typing import Optional, TypeAlias, Union +from typing import Literal, Optional, TypeAlias, Union from pydantic import BaseModel, Field -from typing_extensions import Literal Boolean: TypeAlias = bool """ diff --git a/tests/data/expected/main/graphql/use_standard_collections.py b/tests/data/expected/main/graphql/use_standard_collections.py index 9cca5195a..c89f239cb 100644 --- a/tests/data/expected/main/graphql/use_standard_collections.py +++ b/tests/data/expected/main/graphql/use_standard_collections.py @@ -4,10 +4,9 @@ from __future__ import annotations -from typing import Optional, TypeAlias +from typing import Literal, Optional, TypeAlias from pydantic import BaseModel, Field -from typing_extensions import Literal Boolean: TypeAlias = bool """ diff --git a/tests/data/expected/main/graphql/use_union_operator.py b/tests/data/expected/main/graphql/use_union_operator.py index 4357b3438..307bcfced 100644 --- a/tests/data/expected/main/graphql/use_union_operator.py +++ b/tests/data/expected/main/graphql/use_union_operator.py @@ -4,10 +4,9 @@ from __future__ import annotations -from typing import List, TypeAlias +from typing import Literal, List, TypeAlias from pydantic import BaseModel, Field -from typing_extensions import Literal Boolean: TypeAlias = bool """ diff --git a/tests/data/expected/main/jsonschema/discriminator_literals.py b/tests/data/expected/main/jsonschema/discriminator_literals.py index 51d18b9f2..da91f1ac9 100644 --- a/tests/data/expected/main/jsonschema/discriminator_literals.py +++ b/tests/data/expected/main/jsonschema/discriminator_literals.py @@ -4,10 +4,9 @@ from __future__ import annotations -from typing import Union +from typing import Literal, Union from pydantic import BaseModel, Field -from typing_extensions import Literal class Type1(BaseModel): diff --git a/tests/data/expected/main/jsonschema/discriminator_with_external_reference.py b/tests/data/expected/main/jsonschema/discriminator_with_external_reference.py index 8d87f2bba..0dd125253 100644 --- a/tests/data/expected/main/jsonschema/discriminator_with_external_reference.py +++ b/tests/data/expected/main/jsonschema/discriminator_with_external_reference.py @@ -4,10 +4,9 @@ from __future__ import annotations -from typing import Optional, Union +from typing import Literal, Optional, Union from pydantic import BaseModel, Field -from typing_extensions import Literal class Type1(BaseModel): diff --git a/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/inner_folder/artificial_folder/type_1.py b/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/inner_folder/artificial_folder/type_1.py index 8df555769..6e9d2a5d0 100644 --- a/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/inner_folder/artificial_folder/type_1.py +++ b/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/inner_folder/artificial_folder/type_1.py @@ -4,8 +4,9 @@ from __future__ import annotations +from typing import Literal + from pydantic import BaseModel, Field -from typing_extensions import Literal class Type1(BaseModel): diff --git a/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/inner_folder/schema.py b/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/inner_folder/schema.py index 21806d292..87d9e336a 100644 --- a/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/inner_folder/schema.py +++ b/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/inner_folder/schema.py @@ -4,10 +4,9 @@ from __future__ import annotations -from typing import Union +from typing import Literal, Union from pydantic import BaseModel, Field -from typing_extensions import Literal from .. import type_4 from ..subfolder import type_5 diff --git a/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/inner_folder/type_2.py b/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/inner_folder/type_2.py index 318b34bd1..02d3e3f5f 100644 --- a/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/inner_folder/type_2.py +++ b/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/inner_folder/type_2.py @@ -4,10 +4,9 @@ from __future__ import annotations -from typing import Optional +from typing import Literal, Optional from pydantic import BaseModel, Field -from typing_extensions import Literal from .artificial_folder import type_1 diff --git a/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/subfolder/type_5.py b/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/subfolder/type_5.py index 103c333e9..cb5dde174 100644 --- a/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/subfolder/type_5.py +++ b/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/subfolder/type_5.py @@ -4,8 +4,9 @@ from __future__ import annotations +from typing import Literal + from pydantic import BaseModel, Field -from typing_extensions import Literal class Type5(BaseModel): diff --git a/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/type_4.py b/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/type_4.py index c414017ff..7b9a0fd4c 100644 --- a/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/type_4.py +++ b/tests/data/expected/main/jsonschema/discriminator_with_external_references_folder/type_4.py @@ -4,8 +4,9 @@ from __future__ import annotations +from typing import Literal + from pydantic import BaseModel, Field -from typing_extensions import Literal class Type4(BaseModel): diff --git a/tests/data/expected/main/jsonschema/imports_correct/type_1.py b/tests/data/expected/main/jsonschema/imports_correct/type_1.py index 153e3afd8..f744cb8df 100644 --- a/tests/data/expected/main/jsonschema/imports_correct/type_1.py +++ b/tests/data/expected/main/jsonschema/imports_correct/type_1.py @@ -5,9 +5,9 @@ from __future__ import annotations from enum import Enum +from typing import Literal from pydantic import BaseModel, Field -from typing_extensions import Literal class Type(Enum): diff --git a/tests/data/expected/main/jsonschema/use_default_with_const.py b/tests/data/expected/main/jsonschema/use_default_with_const.py index 4d7fa6afa..6633c839d 100644 --- a/tests/data/expected/main/jsonschema/use_default_with_const.py +++ b/tests/data/expected/main/jsonschema/use_default_with_const.py @@ -4,8 +4,9 @@ from __future__ import annotations +from typing import Literal + from pydantic import BaseModel -from typing_extensions import Literal class UseDefaultWithConst(BaseModel): diff --git a/tests/data/expected/main/openapi/const_field_msgspec.py b/tests/data/expected/main/openapi/const_field_msgspec.py index 82ff26f92..a209342a7 100644 --- a/tests/data/expected/main/openapi/const_field_msgspec.py +++ b/tests/data/expected/main/openapi/const_field_msgspec.py @@ -4,8 +4,10 @@ from __future__ import annotations +from typing import Literal + from msgspec import Meta, Struct -from typing_extensions import Annotated, Literal +from typing_extensions import Annotated class Api(Struct): diff --git a/tests/data/expected/main/openapi/const_field_pydantic_v2.py b/tests/data/expected/main/openapi/const_field_pydantic_v2.py index 3487a2d7c..9081d5167 100644 --- a/tests/data/expected/main/openapi/const_field_pydantic_v2.py +++ b/tests/data/expected/main/openapi/const_field_pydantic_v2.py @@ -4,8 +4,9 @@ from __future__ import annotations +from typing import Literal + from pydantic import BaseModel, Field -from typing_extensions import Literal class Api(BaseModel): diff --git a/tests/data/expected/main/openapi/const_pydantic_v2.py b/tests/data/expected/main/openapi/const_pydantic_v2.py index b29bbb5fd..f64d03da4 100644 --- a/tests/data/expected/main/openapi/const_pydantic_v2.py +++ b/tests/data/expected/main/openapi/const_pydantic_v2.py @@ -4,8 +4,9 @@ from __future__ import annotations +from typing import Literal + from pydantic import BaseModel -from typing_extensions import Literal class Namespace(BaseModel): diff --git a/tests/data/expected/main/openapi/discriminator/general.py b/tests/data/expected/main/openapi/discriminator/general.py index 9cd6e45fa..d45395c50 100644 --- a/tests/data/expected/main/openapi/discriminator/general.py +++ b/tests/data/expected/main/openapi/discriminator/general.py @@ -5,10 +5,9 @@ from __future__ import annotations from enum import Enum -from typing import Optional, Union +from typing import Literal, Optional, Union from pydantic import BaseModel, Field -from typing_extensions import Literal class Type(Enum): diff --git a/tests/data/expected/main/openapi/discriminator/in_array.py b/tests/data/expected/main/openapi/discriminator/in_array.py index 79a8df5dd..6fd17b258 100644 --- a/tests/data/expected/main/openapi/discriminator/in_array.py +++ b/tests/data/expected/main/openapi/discriminator/in_array.py @@ -5,10 +5,9 @@ from __future__ import annotations from enum import Enum -from typing import List, Optional, Union +from typing import List, Literal, Optional, Union from pydantic import BaseModel, Field -from typing_extensions import Literal class Type(Enum): diff --git a/tests/data/expected/main/openapi/discriminator/in_array_collapse_root_models.py b/tests/data/expected/main/openapi/discriminator/in_array_collapse_root_models.py index 6f9c06708..d4952a5c7 100644 --- a/tests/data/expected/main/openapi/discriminator/in_array_collapse_root_models.py +++ b/tests/data/expected/main/openapi/discriminator/in_array_collapse_root_models.py @@ -5,10 +5,9 @@ from __future__ import annotations from enum import Enum -from typing import List, Optional, Union +from typing import List, Literal, Optional, Union from pydantic import BaseModel, Field -from typing_extensions import Literal class Type(Enum): diff --git a/tests/data/expected/main/openapi/discriminator/without_mapping.py b/tests/data/expected/main/openapi/discriminator/without_mapping.py index 2b91db084..9a4dfb26c 100644 --- a/tests/data/expected/main/openapi/discriminator/without_mapping.py +++ b/tests/data/expected/main/openapi/discriminator/without_mapping.py @@ -5,10 +5,9 @@ from __future__ import annotations from enum import Enum -from typing import Optional, Union +from typing import Literal, Optional, Union from pydantic import BaseModel, Field -from typing_extensions import Literal class Type(Enum): diff --git a/tests/data/expected/main/openapi/typed_dict.py b/tests/data/expected/main/openapi/typed_dict.py index 5f57d8ba0..5fcf7611d 100644 --- a/tests/data/expected/main/openapi/typed_dict.py +++ b/tests/data/expected/main/openapi/typed_dict.py @@ -4,9 +4,9 @@ from __future__ import annotations -from typing import List +from typing import List, TypedDict -from typing_extensions import NotRequired, TypedDict +from typing_extensions import NotRequired class Pet(TypedDict): diff --git a/tests/main/openapi/test_main_openapi.py b/tests/main/openapi/test_main_openapi.py index 0f9c444aa..392076c9e 100644 --- a/tests/main/openapi/test_main_openapi.py +++ b/tests/main/openapi/test_main_openapi.py @@ -1244,6 +1244,8 @@ def test_main_openapi_enum_models_as_literal_py37(capsys): 'openapi', '--enum-field-as-literal', 'all', + '--target-python-version', + '3.7', ] ) diff --git a/tests/test_format.py b/tests/test_format.py index 4274f093d..930b813a0 100644 --- a/tests/test_format.py +++ b/tests/test_format.py @@ -33,7 +33,7 @@ def test_format_code_with_skip_string_normalization( skip_string_normalization: bool, expected_output: str ) -> None: formatter = CodeFormatter( - PythonVersion.PY_37, skip_string_normalization=skip_string_normalization + PythonVersion.PY_38, skip_string_normalization=skip_string_normalization ) formatted_code = formatter.format_code("a = 'b'") @@ -44,7 +44,7 @@ def test_format_code_with_skip_string_normalization( def test_format_code_un_exist_custom_formatter(): with pytest.raises(ModuleNotFoundError): _ = CodeFormatter( - PythonVersion.PY_37, + PythonVersion.PY_38, custom_formatters=[UN_EXIST_FORMATTER], ) @@ -52,7 +52,7 @@ def test_format_code_un_exist_custom_formatter(): def test_format_code_invalid_formatter_name(): with pytest.raises(NameError): _ = CodeFormatter( - PythonVersion.PY_37, + PythonVersion.PY_38, custom_formatters=[WRONG_FORMATTER], ) @@ -60,14 +60,14 @@ def test_format_code_invalid_formatter_name(): def test_format_code_is_not_subclass(): with pytest.raises(TypeError): _ = CodeFormatter( - PythonVersion.PY_37, + PythonVersion.PY_38, custom_formatters=[NOT_SUBCLASS_FORMATTER], ) def test_format_code_with_custom_formatter_without_kwargs(): formatter = CodeFormatter( - PythonVersion.PY_37, + PythonVersion.PY_38, custom_formatters=[ADD_COMMENT_FORMATTER], ) @@ -78,7 +78,7 @@ def test_format_code_with_custom_formatter_without_kwargs(): def test_format_code_with_custom_formatter_with_kwargs(): formatter = CodeFormatter( - PythonVersion.PY_37, + PythonVersion.PY_38, custom_formatters=[ADD_LICENSE_FORMATTER], custom_formatters_kwargs={'license_file': EXAMPLE_LICENSE_FILE}, ) @@ -99,7 +99,7 @@ def test_format_code_with_custom_formatter_with_kwargs(): def test_format_code_with_two_custom_formatters(): formatter = CodeFormatter( - PythonVersion.PY_37, + PythonVersion.PY_38, custom_formatters=[ ADD_COMMENT_FORMATTER, ADD_LICENSE_FORMATTER,