Skip to content

Commit

Permalink
merge shape providers into one provider
Browse files Browse the repository at this point in the history
  • Loading branch information
zhPavel committed Jan 28, 2024
1 parent e951b51 commit b52cd32
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
15 changes: 2 additions & 13 deletions src/adaptix/_internal/morphing/facade/retort.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@
from ...provider.loc_stack_filtering import P
from ...provider.provider_template import ValueProvider
from ...provider.request_cls import DebugTrailRequest, LocMap, LocStack, StrictCoercionRequest, TypeHintLoc
from ...provider.shape_provider import (
ATTRS_SHAPE_PROVIDER,
CLASS_INIT_SHAPE_PROVIDER,
DATACLASS_SHAPE_PROVIDER,
NAMED_TUPLE_SHAPE_PROVIDER,
TYPED_DICT_SHAPE_PROVIDER,
)
from ...provider.shape_provider import BUILTIN_SHAPE_PROVIDER
from ...retort.operating_retort import OperatingRetort
from ...struct_trail import render_trail_as_note
from ...type_tools.basic_utils import is_generic_class
Expand Down Expand Up @@ -165,12 +159,7 @@ class FilledRetort(OperatingRetort, ABC):
ModelLoaderProvider(),
ModelDumperProvider(),

NAMED_TUPLE_SHAPE_PROVIDER,
TYPED_DICT_SHAPE_PROVIDER,
DATACLASS_SHAPE_PROVIDER,
ATTRS_SHAPE_PROVIDER,

CLASS_INIT_SHAPE_PROVIDER,
BUILTIN_SHAPE_PROVIDER,

NewTypeUnwrappingProvider(),
TypeHintTagsUnwrappingProvider(),
Expand Down
17 changes: 12 additions & 5 deletions src/adaptix/_internal/provider/shape_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ..provider.loc_stack_filtering import create_loc_stack_checker
from ..type_tools.generic_resolver import GenericResolver, MembersStorage
from .provider_template import ProviderWithAttachableLSC
from .provider_wrapper import ConcatProvider
from .request_cls import LocatedRequest, TypeHintLoc
from .static_provider import StaticProvider, static_provision_action

Expand All @@ -38,6 +39,9 @@ class ShapeProvider(StaticProvider):
def __init__(self, introspector: ShapeIntrospector):
self._introspector = introspector

def __repr__(self):
return f"{type(self)}({self._introspector})"

@static_provision_action
def _provide_input_shape(self, mediator: Mediator, request: InputShapeRequest) -> InputShape:
loc = request.last_map.get_or_raise(TypeHintLoc, CannotProvide)
Expand Down Expand Up @@ -65,11 +69,14 @@ def _provide_output_shape(self, mediator: Mediator, request: OutputShapeRequest)
return shape.output


NAMED_TUPLE_SHAPE_PROVIDER = ShapeProvider(get_named_tuple_shape)
TYPED_DICT_SHAPE_PROVIDER = ShapeProvider(get_typed_dict_shape)
DATACLASS_SHAPE_PROVIDER = ShapeProvider(get_dataclass_shape)
CLASS_INIT_SHAPE_PROVIDER = ShapeProvider(get_class_init_shape)
ATTRS_SHAPE_PROVIDER = ShapeProvider(get_attrs_shape)
BUILTIN_SHAPE_PROVIDER = ConcatProvider(
ShapeProvider(get_named_tuple_shape),
ShapeProvider(get_typed_dict_shape),
ShapeProvider(get_dataclass_shape),
ShapeProvider(get_attrs_shape),
# class init introspection must be the last
ShapeProvider(get_class_init_shape),
)


class PropertyExtender(StaticProvider):
Expand Down

0 comments on commit b52cd32

Please sign in to comment.