Skip to content

Commit

Permalink
Merge branch 'main' into duplicate-discriminator
Browse files Browse the repository at this point in the history
  • Loading branch information
koxudaxi authored Mar 16, 2024
2 parents 4343bdd + 33d6666 commit cc6498d
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.2.2'
rev: 'v0.3.2'
hooks:
- id: ruff
files: "^datamodel_code_generator|^tests"
Expand Down
3 changes: 1 addition & 2 deletions datamodel_code_generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def load_yaml_from_path(path: Path, encoding: str) -> Any:

if TYPE_CHECKING:

def get_version() -> str:
...
def get_version() -> str: ...

else:

Expand Down
3 changes: 1 addition & 2 deletions datamodel_code_generator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def __getitem__(self, item: str) -> Any:
if TYPE_CHECKING:

@classmethod
def get_fields(cls) -> Dict[str, Any]:
...
def get_fields(cls) -> Dict[str, Any]: ...

else:

Expand Down
15 changes: 6 additions & 9 deletions datamodel_code_generator/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def has_typed_dict_non_required(self) -> bool:

if TYPE_CHECKING:

class _TargetVersion(Enum):
...
class _TargetVersion(Enum): ...

BLACK_PYTHON_VERSION: Dict[PythonVersion, _TargetVersion]
else:
Expand All @@ -98,8 +97,7 @@ def black_find_project_root(sources: Sequence[Path]) -> Path:

def _find_project_root(
srcs: Union[Sequence[str], Iterable[str]],
) -> Union[Tuple[Path, str], Path]:
...
) -> Union[Tuple[Path, str], Path]: ...

else:
from black import find_project_root as _find_project_root
Expand Down Expand Up @@ -153,9 +151,9 @@ def __init__(
f' for wrapping string literal in {black.__version__}'
)
elif black.__version__ < '24.1.0': # type: ignore
black_kwargs[
'experimental_string_processing'
] = experimental_string_processing
black_kwargs['experimental_string_processing'] = (
experimental_string_processing
)
elif experimental_string_processing:
black_kwargs['preview'] = True
black_kwargs['unstable'] = config.get('unstable', False)
Expand Down Expand Up @@ -240,8 +238,7 @@ def apply_black(self, code: str) -> str:

if TYPE_CHECKING:

def apply_isort(self, code: str) -> str:
...
def apply_isort(self, code: str) -> str: ...

else:
if isort.__version__.startswith('4.'):
Expand Down
1 change: 1 addition & 0 deletions datamodel_code_generator/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,6 @@ def remove_referenced_imports(self, reference_path: str) -> None:
IMPORT_DECIMAL = Import.from_full_path('decimal.Decimal')
IMPORT_DATE = Import.from_full_path('datetime.date')
IMPORT_DATETIME = Import.from_full_path('datetime.datetime')
IMPORT_PATH = Import.from_full_path('pathlib.Path')
IMPORT_TIME = Import.from_full_path('datetime.time')
IMPORT_UUID = Import.from_full_path('uuid.UUID')
3 changes: 1 addition & 2 deletions datamodel_code_generator/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ def __str__(self) -> str:
return self.render()


class BaseClassDataType(DataType):
...
class BaseClassDataType(DataType): ...


UNDEFINED: Any = object()
Expand Down
2 changes: 2 additions & 0 deletions datamodel_code_generator/model/pydantic/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
IMPORT_DATE,
IMPORT_DATETIME,
IMPORT_DECIMAL,
IMPORT_PATH,
IMPORT_TIME,
IMPORT_UUID,
)
Expand Down Expand Up @@ -70,6 +71,7 @@ def type_map_factory(
Types.binary: data_type(type='bytes'),
Types.date: data_type.from_import(IMPORT_DATE),
Types.date_time: data_type.from_import(IMPORT_DATETIME),
Types.path: data_type.from_import(IMPORT_PATH),
Types.password: data_type.from_import(IMPORT_SECRET_STR),
Types.email: data_type.from_import(IMPORT_EMAIL_STR),
Types.uuid: data_type.from_import(IMPORT_UUID),
Expand Down
30 changes: 15 additions & 15 deletions datamodel_code_generator/parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,19 +408,19 @@ def __init__(
self.base_class: Optional[str] = base_class
self.target_python_version: PythonVersion = target_python_version
self.results: List[DataModel] = []
self.dump_resolve_reference_action: Optional[
Callable[[Iterable[str]], str]
] = dump_resolve_reference_action
self.dump_resolve_reference_action: Optional[Callable[[Iterable[str]], str]] = (
dump_resolve_reference_action
)
self.validation: bool = validation
self.field_constraints: bool = field_constraints
self.snake_case_field: bool = snake_case_field
self.strip_default_none: bool = strip_default_none
self.apply_default_values_for_required_fields: (
bool
) = apply_default_values_for_required_fields
self.force_optional_for_required_fields: (
bool
) = force_optional_for_required_fields
self.apply_default_values_for_required_fields: bool = (
apply_default_values_for_required_fields
)
self.force_optional_for_required_fields: bool = (
force_optional_for_required_fields
)
self.use_schema_description: bool = use_schema_description
self.use_field_description: bool = use_field_description
self.use_default_kwarg: bool = use_default_kwarg
Expand All @@ -433,9 +433,9 @@ def __init__(
self.use_generic_container_types: bool = use_generic_container_types
self.use_union_operator: bool = use_union_operator
self.enable_faux_immutability: bool = enable_faux_immutability
self.custom_class_name_generator: Optional[
Callable[[str], str]
] = custom_class_name_generator
self.custom_class_name_generator: Optional[Callable[[str], str]] = (
custom_class_name_generator
)
self.field_extra_keys: Set[str] = field_extra_keys or set()
self.field_extra_keys_without_x_prefix: Set[str] = (
field_extra_keys_without_x_prefix or set()
Expand Down Expand Up @@ -568,9 +568,9 @@ def parse_raw(self) -> None:

def __delete_duplicate_models(self, models: List[DataModel]) -> None:
model_class_names: Dict[str, DataModel] = {}
model_to_duplicate_models: DefaultDict[
DataModel, List[DataModel]
] = defaultdict(list)
model_to_duplicate_models: DefaultDict[DataModel, List[DataModel]] = (
defaultdict(list)
)
for model in models[:]:
if isinstance(model, self.data_model_root_type):
root_data_type = model.fields[0].data_type
Expand Down
7 changes: 4 additions & 3 deletions datamodel_code_generator/parser/jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def get_model_by_path(
'date-time': Types.date_time,
'time': Types.time,
'password': Types.password,
'path': Types.path,
'email': Types.email,
'idn-email': Types.email,
'uuid': Types.uuid,
Expand Down Expand Up @@ -632,9 +633,9 @@ def get_ref_data_type(self, ref: str) -> DataType:

def set_additional_properties(self, name: str, obj: JsonSchemaObject) -> None:
if isinstance(obj.additionalProperties, bool):
self.extra_template_data[name][
'additionalProperties'
] = obj.additionalProperties
self.extra_template_data[name]['additionalProperties'] = (
obj.additionalProperties
)

def set_title(self, name: str, obj: JsonSchemaObject) -> None:
if obj.title:
Expand Down
1 change: 1 addition & 0 deletions datamodel_code_generator/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ class Types(Enum):
date = auto()
date_time = auto()
password = auto()
path = auto()
email = auto()
uuid = auto()
uuid1 = auto()
Expand Down
3 changes: 1 addition & 2 deletions datamodel_code_generator/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

from typing_extensions import Literal

def load_toml(path: Path) -> Dict[str, Any]:
...
def load_toml(path: Path) -> Dict[str, Any]: ...

else:
try:
Expand Down
1 change: 1 addition & 0 deletions docs/supported-data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Below are the data types and features recognized by datamodel-code-generator for
- password
- email
- idn-email
- path
- uuid (uuid1/uuid2/uuid3/uuid4/uuid5)
- ipv4
- ipv6
Expand Down
44 changes: 22 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ types-setuptools = ">=67.6.0.5,<70.0.0.0"
pydantic = "*"
httpx = ">=0.24.1"
PySnooper = "*"
ruff = ">=0.0.290,<0.3.2"
ruff = ">=0.0.290,<0.3.3"
ruff-lsp = ">=0.0.39,<0.0.41"
pre-commit = "*"
pytest-xdist = "^3.3.1"
Expand Down
1 change: 1 addition & 0 deletions tests/parser/test_jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def test_parse_nested_array():
('boolean', None, 'bool', None, None),
('string', 'date', 'date', 'datetime', 'date'),
('string', 'date-time', 'datetime', 'datetime', 'datetime'),
('string', 'path', 'Path', 'pathlib', 'Path'),
('string', 'password', 'SecretStr', 'pydantic', 'SecretStr'),
('string', 'email', 'EmailStr', 'pydantic', 'EmailStr'),
('string', 'uri', 'AnyUrl', 'pydantic', 'AnyUrl'),
Expand Down

0 comments on commit cc6498d

Please sign in to comment.