Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for Python 3.7 #1509

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-latest]
isort-version: [4.3.21, 5.6.4]
black-version: [22.1.0, default]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ Model customization:
--keep-model-order Keep generated models' order
--reuse-model Re-use models on the field when a module has the model
with the same content
--target-python-version {3.6,3.7,3.8,3.9,3.10,3.11}
target python version (default: 3.7)
--target-python-version {3.8,3.9,3.10,3.11}
target python version (default: 3.8)
--use-schema-description
Use schema description to populate class docstring
--use-title-as-name use titles as class names of models
Expand Down
2 changes: 1 addition & 1 deletion datamodel_code_generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,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
9 changes: 1 addition & 8 deletions datamodel_code_generator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,6 @@ def validate_url(cls, value: Any) -> Optional[ParseResult]:
def validate_use_generic_container_types(
cls, values: Dict[str, Any]
) -> Dict[str, Any]:
if values.get('use_generic_container_types'):
target_python_version: PythonVersion = values['target_python_version']
if target_python_version == target_python_version.PY_36:
raise Error(
f'`--use-generic-container-types` can not be used with `--target-python_version` {target_python_version.PY_36.value}.\n'
' The version will be not supported in a future version'
)
return values

@model_validator(mode='after')
Expand Down Expand Up @@ -218,7 +211,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 = ''
custom_template_dir: Optional[Path] = None
extra_template_data: Optional[TextIOBase] = None
Expand Down
10 changes: 2 additions & 8 deletions datamodel_code_generator/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@


class PythonVersion(Enum):
PY_36 = '3.6'
PY_37 = '3.7'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorenham
I agree with you it's to drop support 3.7 from runtime support list.
Should we delete PY_37 for output?
Personally, I'm happy to drop the old version from the output model list.
But I want to think about it again. 🤔

PY_38 = '3.8'
PY_39 = '3.9'
PY_310 = '3.10'
Expand All @@ -22,26 +20,22 @@ class PythonVersion(Enum):

@cached_property
def _is_py_38_or_later(self) -> bool: # pragma: no cover
return self.value not in {self.PY_36.value, self.PY_37.value} # type: ignore
return True # type: ignore

@cached_property
def _is_py_39_or_later(self) -> bool: # pragma: no cover
return self.value not in {self.PY_36.value, self.PY_37.value, self.PY_38.value} # type: ignore
return self.value not in {self.PY_38.value} # type: ignore

@cached_property
def _is_py_310_or_later(self) -> bool: # pragma: no cover
return self.value not in {
self.PY_36.value,
self.PY_37.value,
self.PY_38.value,
self.PY_39.value,
} # type: ignore

@cached_property
def _is_py_311_or_later(self) -> bool: # pragma: no cover
return self.value not in {
self.PY_36.value,
self.PY_37.value,
self.PY_38.value,
self.PY_39.value,
self.PY_310.value,
Expand Down
2 changes: 1 addition & 1 deletion datamodel_code_generator/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Import(BaseModel):
reference_path: Optional[str] = None

@classmethod
@lru_cache()
@lru_cache
def from_full_path(cls, class_path: str) -> Import:
split_class_path: List[str] = class_path.split('.')
return Import(
Expand Down
2 changes: 1 addition & 1 deletion datamodel_code_generator/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def fall_back_to_nullable(self) -> bool:
return True


@lru_cache()
@lru_cache
def get_template(template_file_path: Path) -> Template:
loader = FileSystemLoader(str(TEMPLATE_DIR / template_file_path.parent))
environment: Environment = Environment(loader=loader)
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 @@ -139,7 +139,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
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
5 changes: 2 additions & 3 deletions datamodel_code_generator/parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,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 Expand Up @@ -1136,8 +1136,7 @@ def parse(
self.parse_raw()

if with_import:
if self.target_python_version != PythonVersion.PY_36:
self.imports.append(IMPORT_ANNOTATIONS)
self.imports.append(IMPORT_ANNOTATIONS)

if format_:
code_formatter: Optional[CodeFormatter] = CodeFormatter(
Expand Down
4 changes: 2 additions & 2 deletions datamodel_code_generator/parser/jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def type_has_null(self) -> bool:
return isinstance(self.type, list) and 'null' in self.type


@lru_cache()
@lru_cache
def get_ref_type(ref: str) -> JSONReference:
if ref[0] == '#':
return JSONReference.LOCAL
Expand Down Expand Up @@ -370,7 +370,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
6 changes: 3 additions & 3 deletions datamodel_code_generator/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def context_variable(
_UNDER_SCORE_2: Pattern[str] = re.compile('([a-z0-9])([A-Z])')


@lru_cache()
@lru_cache
def camel_to_snake(string: str) -> str:
subbed = _UNDER_SCORE_1.sub(r'\1_\2', string)
return _UNDER_SCORE_2.sub(r'\1_\2', subbed).lower()
Expand Down Expand Up @@ -731,15 +731,15 @@ def get_valid_field_name_and_alias(
)


@lru_cache()
@lru_cache
def get_singular_name(name: str, suffix: str = SINGULAR_NAME_SUFFIX) -> str:
singular_name = inflect_engine.singular_noun(name)
if singular_name is False:
singular_name = f'{name}{suffix}'
return singular_name


@lru_cache()
@lru_cache
def snake_to_upper_camel(word: str, delimiter: str = '_') -> str:
prefix = ''
if word.startswith(delimiter):
Expand Down
18 changes: 4 additions & 14 deletions datamodel_code_generator/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def chain_as_tuple(*iterables: Iterable[T]) -> Tuple[T, ...]:
return tuple(chain(*iterables))


@lru_cache()
@lru_cache
def _remove_none_from_type(
type_: str, split_pattern: Pattern[str], delimiter: str
) -> List[str]:
Expand Down Expand Up @@ -212,7 +212,7 @@ def _remove_none_from_union(type_: str, use_union_operator: bool) -> str:
return f'{UNION_PREFIX}{UNION_DELIMITER.join(inner_types)}]'


@lru_cache()
@lru_cache
def get_optional_type(type_: str, use_union_operator: bool) -> str:
type_ = _remove_none_from_union(type_, use_union_operator)

Expand Down Expand Up @@ -266,7 +266,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 @@ -471,8 +471,6 @@ def type_hint(self) -> str:
source = self.reference.source
if isinstance(source, Nullable) and source.nullable:
self.is_optional = True
if self.reference and self.python_version == PythonVersion.PY_36:
type_ = f"'{type_}'"
if self.is_list:
if self.use_generic_container:
list_ = SEQUENCE
Expand Down Expand Up @@ -562,7 +560,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 All @@ -578,14 +576,6 @@ def __init__(
)
self.use_union_operator: bool = use_union_operator

if (
use_generic_container_types and python_version == PythonVersion.PY_36
): # pragma: no cover
raise Exception(
'use_generic_container_types can not be used with target_python_version 3.6.\n'
' The version will be not supported in a future version'
)

if TYPE_CHECKING:
self.data_type: Type[DataType]
else:
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ Model customization:
--keep-model-order Keep generated models' order
--reuse-model Re-use models on the field when a module has the model
with the same content
--target-python-version {3.6,3.7,3.8,3.9,3.10,3.11}
target python version (default: 3.7)
--target-python-version {3.8,3.9,3.10,3.11}
target python version (default: 3.8)
--use-schema-description
Use schema description to populate class docstring
--use-title-as-name use titles as class names of models
Expand Down
2 changes: 1 addition & 1 deletion docs/pyproject_toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Example `pyproject.toml`:
field-constraints = true
snake-case-field = true
strip-default-none = false
target-python-version = "3.7"
target-python-version = "3.8"
```