Skip to content

Commit

Permalink
fix: set defaults in module to make it easier to move to global defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwhalen committed Nov 27, 2024
1 parent 9ed9a07 commit 6f77c6e
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions datamodel_code_generator/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from __future__ import annotations

import sys
from typing import TYPE_CHECKING, Callable, Iterable, List, NamedTuple, Optional, Type

from ..types import DataTypeManager as DataTypeManagerABC
from .base import ConstraintsBase, DataModel, DataModelFieldBase
from .. import DatetimeClassType, PythonVersion

if TYPE_CHECKING:
from .. import DataModelType, DatetimeClassType, PythonVersion
from .. import DataModelType

DEFAULT_TARGET_DATETIME_CLASS = DatetimeClassType.Datetime
DEFAULT_TARGET_PYTHON_VERSION = PythonVersion(
f'{sys.version_info.major}.{sys.version_info.minor}'
)


class DataModelSet(NamedTuple):
Expand All @@ -20,8 +27,8 @@ class DataModelSet(NamedTuple):

def get_data_model_types(
data_model_type: DataModelType,
target_python_version: PythonVersion,
target_datetime_class: DatetimeClassType = DatetimeClassType.Datetime,
target_python_version: PythonVersion = DEFAULT_TARGET_PYTHON_VERSION,
target_datetime_class: DatetimeClassType = DEFAULT_TARGET_DATETIME_CLASS,
) -> DataModelSet:
from .. import DataModelType
from . import dataclass, msgspec, pydantic, pydantic_v2, rootmodel, typed_dict
Expand Down Expand Up @@ -53,13 +60,17 @@ def get_data_model_types(
)
elif data_model_type == DataModelType.TypingTypedDict:
return DataModelSet(
data_model=typed_dict.TypedDict
if target_python_version.has_typed_dict
else typed_dict.TypedDictBackport,
data_model=(
typed_dict.TypedDict
if target_python_version.has_typed_dict
else typed_dict.TypedDictBackport
),
root_model=rootmodel.RootModel,
field_model=typed_dict.DataModelField
if target_python_version.has_typed_dict_non_required
else typed_dict.DataModelFieldBackport,
field_model=(
typed_dict.DataModelField
if target_python_version.has_typed_dict_non_required
else typed_dict.DataModelFieldBackport
),
data_type_manager=DataTypeManager,
dump_resolve_reference_action=None,
)
Expand Down

0 comments on commit 6f77c6e

Please sign in to comment.