Skip to content

Commit

Permalink
Change default target python version to 3.8 (#2061)
Browse files Browse the repository at this point in the history
* Change default target python version to 3.8

* Fix format
  • Loading branch information
koxudaxi authored Aug 8, 2024
1 parent 04d6b03 commit f12341e
Show file tree
Hide file tree
Showing 45 changed files with 64 additions and 85 deletions.
2 changes: 1 addition & 1 deletion datamodel_code_generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion datamodel_code_generator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion datamodel_code_generator/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion datamodel_code_generator/model/pydantic/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 1 addition & 9 deletions datamodel_code_generator/model/pydantic_v2/base_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import re
from pathlib import Path
from typing import (
TYPE_CHECKING,
Any,
ClassVar,
DefaultDict,
Expand All @@ -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 (
Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions datamodel_code_generator/model/pydantic_v2/root_model.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion datamodel_code_generator/model/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion datamodel_code_generator/parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion datamodel_code_generator/parser/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion datamodel_code_generator/parser/jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion datamodel_code_generator/parser/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions datamodel_code_generator/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion datamodel_code_generator/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/data/expected/main/graphql/annotated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/data/expected/main/graphql/custom_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/data/expected/main/graphql/custom_scalar_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

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 Literal

Boolean: TypeAlias = bool
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/data/expected/main/graphql/field_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/data/expected/main/graphql/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

from datetime import date, datetime
from enum import Enum
from typing import List, Optional, TypeAlias, Union
from typing import List, Literal, Optional, TypeAlias, Union

from pydantic import BaseModel, Field
from typing_extensions import Literal

Base64String: TypeAlias = str
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/data/expected/main/graphql/simple_star_wars.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

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 Literal

Boolean: TypeAlias = bool
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import List, Optional, TypeAlias

from typing_extensions import Literal
from typing import List, Literal, Optional, TypeAlias

Boolean: TypeAlias = bool
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/data/expected/main/graphql/union.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/data/expected/main/graphql/use_standard_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/data/expected/main/graphql/use_union_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

from __future__ import annotations

from typing import List, TypeAlias
from typing import List, Literal, TypeAlias

from pydantic import BaseModel, Field
from typing_extensions import Literal

Boolean: TypeAlias = bool
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading

0 comments on commit f12341e

Please sign in to comment.