Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#2251)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.8.4 → v0.9.1](astral-sh/ruff-pre-commit@v0.8.4...v0.9.1)
- [github.com/python-poetry/poetry: 1.8.0 → 2.0.1](python-poetry/poetry@1.8.0...2.0.1)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
pre-commit-ci[bot] authored Jan 14, 2025
1 parent de3b2cd commit dd92cd0
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .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.8.4'
rev: 'v0.9.1'
hooks:
- id: ruff
files: "^datamodel_code_generator|^tests"
Expand All @@ -18,6 +18,6 @@ repos:
- tomli
exclude: "^tests/|^CODE_OF_CONDUCT.md"
- repo: https://github.com/python-poetry/poetry
rev: 1.8.0
rev: 2.0.1
hooks:
- id: poetry-check
2 changes: 1 addition & 1 deletion datamodel_code_generator/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _set_alias(self, from_: Optional[str], imports: Set[str]) -> List[str]:

def create_line(self, from_: Optional[str], imports: Set[str]) -> str:
if from_:
return f"from {from_} import {', '.join(self._set_alias(from_, imports))}"
return f'from {from_} import {", ".join(self._set_alias(from_, imports))}'
return '\n'.join(f'import {i}' for i in self._set_alias(from_, imports))

def dump(self) -> str:
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 @@ -423,7 +423,7 @@ def class_name(self) -> str:
def class_name(self, class_name: str) -> None:
if '.' in self.reference.name:
self.reference.name = (
f"{self.reference.name.rsplit('.', 1)[0]}.{class_name}"
f'{self.reference.name.rsplit(".", 1)[0]}.{class_name}'
)
else:
self.reference.name = class_name
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 @@ -338,7 +338,7 @@ def _get_type(type_: str, format__: Optional[str] = None) -> Types:
if data_formats is not None:
return data_formats

warn(f'format of {format__!r} not understood for {type_!r} - using default' '')
warn(f'format of {format__!r} not understood for {type_!r} - using default')
return json_schema_data_formats[type_]['default']


Expand Down
4 changes: 2 additions & 2 deletions datamodel_code_generator/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def resolve_ref(self, path: Union[Sequence[str], str]) -> str:
else:
joined_path = self.join_path(path)
if joined_path == '#':
return f"{'/'.join(self.current_root)}#"
return f'{"/".join(self.current_root)}#'
if (
self.current_base_path
and not self.base_url
Expand All @@ -498,7 +498,7 @@ def resolve_ref(self, path: Union[Sequence[str], str]) -> str:

delimiter = joined_path.index('#')
file_path = ''.join(joined_path[:delimiter])
ref = f"{''.join(joined_path[:delimiter])}#{''.join(joined_path[delimiter + 1:])}"
ref = f'{"".join(joined_path[:delimiter])}#{"".join(joined_path[delimiter + 1 :])}'
if self.root_id_base_path and not (
is_url(joined_path) or Path(self._base_path, file_path).is_file()
):
Expand Down
2 changes: 1 addition & 1 deletion datamodel_code_generator/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def type_hint(self) -> str:
elif len(self.data_types) == 1:
type_ = self.data_types[0].type_hint
elif self.literals:
type_ = f"{LITERAL}[{', '.join(repr(literal) for literal in self.literals)}]"
type_ = f'{LITERAL}[{", ".join(repr(literal) for literal in self.literals)}]'
else:
if self.reference:
type_ = self.reference.short_name
Expand Down
4 changes: 2 additions & 2 deletions tests/model/pydantic/test_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_base_model():
assert base_model.name == 'test_model'
assert base_model.fields == [field]
assert base_model.decorators == []
assert base_model.render() == 'class test_model(BaseModel):\n' ' a: str'
assert base_model.render() == 'class test_model(BaseModel):\n a: str'


def test_base_model_optional():
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_base_model_strict_non_nullable_required():
assert base_model.name == 'test_model'
assert base_model.fields == [field]
assert base_model.decorators == []
assert base_model.render() == 'class test_model(BaseModel):\n' ' a: str'
assert base_model.render() == 'class test_model(BaseModel):\n a: str'


def test_base_model_decorator():
Expand Down
4 changes: 2 additions & 2 deletions tests/model/pydantic/test_custom_root_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_custom_root_type():
]

assert custom_root_type.render() == (
'class test_model(BaseModel):\n' " __root__: Optional[str] = 'abc'"
"class test_model(BaseModel):\n __root__: Optional[str] = 'abc'"
)


Expand All @@ -48,7 +48,7 @@ def test_custom_root_type_required():
]

assert custom_root_type.render() == (
'class test_model(BaseModel):\n' ' __root__: str'
'class test_model(BaseModel):\n __root__: str'
)


Expand Down
10 changes: 3 additions & 7 deletions tests/model/pydantic/test_data_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_data_class():
assert data_class.name == 'test_model'
assert data_class.fields == [field]
assert data_class.decorators == []
assert data_class.render() == '@dataclass\n' 'class test_model:\n' ' a: str'
assert data_class.render() == '@dataclass\nclass test_model:\n a: str'


def test_data_class_base_class():
Expand All @@ -31,9 +31,7 @@ def test_data_class_base_class():
assert data_class.name == 'test_model'
assert data_class.fields == [field]
assert data_class.decorators == []
assert (
data_class.render() == '@dataclass\n' 'class test_model(Base):\n' ' a: str'
)
assert data_class.render() == '@dataclass\nclass test_model(Base):\n a: str'


def test_data_class_optional():
Expand All @@ -49,9 +47,7 @@ def test_data_class_optional():
assert data_class.name == 'test_model'
assert data_class.fields == [field]
assert data_class.decorators == []
assert (
data_class.render() == '@dataclass\n' 'class test_model:\n' " a: str = 'abc'"
)
assert data_class.render() == "@dataclass\nclass test_model:\n a: str = 'abc'"


def test_data_class_get_data_type():
Expand Down
11 changes: 3 additions & 8 deletions tests/model/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_template_base():

def test_data_model():
field = DataModelFieldBase(
name='a', data_type=DataType(type='str'), default='' 'abc' '', required=True
name='a', data_type=DataType(type='str'), default='abc', required=True
)

with NamedTemporaryFile('w', delete=False) as dummy_template:
Expand All @@ -88,17 +88,12 @@ def test_data_model():
assert data_model.fields == [field]
assert data_model.decorators == ['@validate']
assert data_model.base_class == 'Base'
assert (
data_model.render() == '@validate\n'
'@dataclass\n'
'class test_model:\n'
' a: str'
)
assert data_model.render() == '@validate\n@dataclass\nclass test_model:\n a: str'


def test_data_model_exception():
field = DataModelFieldBase(
name='a', data_type=DataType(type='str'), default='' 'abc' '', required=True
name='a', data_type=DataType(type='str'), default='abc', required=True
)
with pytest.raises(Exception, match='TEMPLATE_FILE_PATH is undefined'):
C(
Expand Down

0 comments on commit dd92cd0

Please sign in to comment.