Skip to content

Commit

Permalink
fix linters and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhPavel committed Jul 27, 2024
1 parent e33182b commit 4f6eb94
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 26 deletions.
20 changes: 8 additions & 12 deletions src/adaptix/_internal/morphing/model/dumper_gen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import contextlib
from dataclasses import replace
from string import Template
from typing import Any, Callable, Dict, Mapping, NamedTuple, Optional, Tuple
from typing import Any, Callable, Dict, Mapping, NamedTuple, Tuple

from ...code_tools.cascade_namespace import BuiltinCascadeNamespace, CascadeNamespace
from ...code_tools.code_builder import CodeBuilder
Expand Down Expand Up @@ -679,17 +679,13 @@ def _convert_dict_crown(self, crown: OutDictCrown) -> JSONSchema:
if self._is_required_crown(value)
],
properties={
key: value
for key, value in (
(key, self.convert_crown(value))
for key, value in crown.map.items()
)
if value is not None
key: self.convert_crown(value)
for key, value in crown.map.items()
},
additional_properties=self._extra_move is not None,
)

def _convert_list_crown(self, crown: OutListCrown) -> Optional[JSONSchema]:
def _convert_list_crown(self, crown: OutListCrown) -> JSONSchema:
items = [
self.convert_crown(sub_crown)
for sub_crown in crown.map
Expand All @@ -701,27 +697,27 @@ def _convert_list_crown(self, crown: OutListCrown) -> Optional[JSONSchema]:
min_items=len(items),
)

def _convert_field_crown(self, crown: OutFieldCrown) -> Optional[JSONSchema]:
def _convert_field_crown(self, crown: OutFieldCrown) -> JSONSchema:
field = self._shape.fields_dict[crown.id]
json_schema = self._field_json_schema_getter(field)
if field.default == NoDefault():
return json_schema
return replace(json_schema, default=self._field_default_dumper(field))

def _convert_none_crown(self, crown: OutNoneCrown) -> Optional[JSONSchema]:
def _convert_none_crown(self, crown: OutNoneCrown) -> JSONSchema:
value = (
crown.placeholder.factory()
if isinstance(crown.placeholder, DefaultFactory) else
crown.placeholder.value
)
return self._placeholder_dumper(value)
return JSONSchema(const=self._placeholder_dumper(value))

def _is_required_crown(self, crown: OutCrown) -> bool:
if isinstance(crown, OutFieldCrown):
return self._shape.fields_dict[crown.id].is_required
return True

def convert_crown(self, crown: OutCrown) -> Optional[JSONSchema]:
def convert_crown(self, crown: OutCrown) -> JSONSchema:
if isinstance(crown, OutDictCrown):
return self._convert_dict_crown(crown)
if isinstance(crown, OutListCrown):
Expand Down
18 changes: 7 additions & 11 deletions src/adaptix/_internal/morphing/model/loader_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,17 +804,13 @@ def _convert_dict_crown(self, crown: InpDictCrown) -> JSONSchema:
if self._is_required_crown(value)
],
properties={
key: value
for key, value in (
(key, self.convert_crown(value))
for key, value in crown.map.items()
)
if value is not None
key: self.convert_crown(value)
for key, value in crown.map.items()
},
additional_properties=crown.extra_policy != ExtraForbid(),
)

def _convert_list_crown(self, crown: InpListCrown) -> Optional[JSONSchema]:
def _convert_list_crown(self, crown: InpListCrown) -> JSONSchema:
items = [
self.convert_crown(sub_crown)
for sub_crown in crown.map
Expand All @@ -826,15 +822,15 @@ def _convert_list_crown(self, crown: InpListCrown) -> Optional[JSONSchema]:
min_items=len(items),
)

def _convert_field_crown(self, crown: InpFieldCrown) -> Optional[JSONSchema]:
def _convert_field_crown(self, crown: InpFieldCrown) -> JSONSchema:
field = self._shape.fields_dict[crown.id]
json_schema = self._field_json_schema_getter(field)
if field.default == NoDefault():
return json_schema
return replace(json_schema, default=self._field_default_dumper(field))

def _convert_none_crown(self, crown: InpNoneCrown) -> Optional[JSONSchema]:
return None
def _convert_none_crown(self, crown: InpNoneCrown) -> JSONSchema:
return JSONSchema()

def _is_required_crown(self, crown: InpCrown) -> bool:
if isinstance(crown, InpFieldCrown):
Expand All @@ -843,7 +839,7 @@ def _is_required_crown(self, crown: InpCrown) -> bool:
return False
return True

def convert_crown(self, crown: InpCrown) -> Optional[JSONSchema]:
def convert_crown(self, crown: InpCrown) -> JSONSchema:
if isinstance(crown, InpDictCrown):
return self._convert_dict_crown(crown)
if isinstance(crown, InpListCrown):
Expand Down
3 changes: 1 addition & 2 deletions src/adaptix/_internal/morphing/name_layout/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from dataclasses import dataclass
from typing import Callable, DefaultDict, Dict, Iterable, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union

from adaptix import ProviderNotFoundError

from ...common import VarTuple
from ...model_tools.definitions import (
BaseField,
Expand All @@ -22,6 +20,7 @@
from ...provider.located_request import LocatedRequest
from ...provider.overlay_schema import Overlay, Schema, provide_schema
from ...retort.operating_retort import OperatingRetort
from ...retort.searching_retort import ProviderNotFoundError
from ...special_cases_optimization import with_default_clause
from ...utils import Omittable, get_prefix_groups
from ..model.crown_definitions import (
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/morphing/facade/test_retort.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_retort_extend():
extended_retort = retort.extend(recipe=to_extend)

assert retort._get_full_recipe() == recipe_before_extend
assert extended_retort._get_full_recipe()[:len(to_extend)] == to_extend
assert extended_retort._get_full_recipe()[1:len(to_extend)+1] == to_extend
assert not extended_retort._loader_cache
assert not extended_retort._dumper_cache

Expand Down

0 comments on commit 4f6eb94

Please sign in to comment.