Skip to content

Commit

Permalink
refactor: cleanup docs and api (#24)
Browse files Browse the repository at this point in the history
* refactor: cleanup docs and api

* test: fix coverage
  • Loading branch information
tlambert03 authored Jul 6, 2022
1 parent 82789f8 commit 4f132c8
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 236 deletions.
4 changes: 2 additions & 2 deletions src/in_n_out/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

from ._global import (
inject,
inject_processors,
iter_processors,
iter_providers,
mark_processor,
mark_provider,
process,
process_output,
provide,
register,
register_processor,
Expand All @@ -36,7 +36,7 @@
"inject",
"iter_processors",
"iter_providers",
"process_output",
"inject_processors",
"process",
"mark_processor",
"provide",
Expand Down
104 changes: 53 additions & 51 deletions src/in_n_out/_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,12 @@ def register_processor(
)


@_add_store_to_doc
def iter_providers(
hint: Union[object, Type[T]], store: Union[str, Store, None] = None
) -> Iterable[Callable[[], Optional[T]]]:
return _store_or_global(store).iter_providers(hint)


@_add_store_to_doc
def iter_processors(
hint: Union[object, Type[T]], store: Union[str, Store, None] = None
) -> Iterable[Callable[[T], Any]]:
return _store_or_global(store).iter_processors(hint)


@overload
def mark_provider(
func: ProviderVar,
*,
weight: float = 0,
for_type: Optional[object] = None,
type_hint: Optional[object] = None,
store: Union[str, Store, None] = None,
) -> ProviderVar:
...
Expand All @@ -120,7 +106,7 @@ def mark_provider(
func: Literal[None] = ...,
*,
weight: float = 0,
for_type: Optional[object] = None,
type_hint: Optional[object] = None,
store: Union[str, Store, None] = None,
) -> Callable[[ProviderVar], ProviderVar]:
...
Expand All @@ -131,34 +117,11 @@ def mark_provider(
func: Optional[ProviderVar] = None,
*,
weight: float = 0,
for_type: Optional[object] = None,
type_hint: Optional[object] = None,
store: Union[str, Store, None] = None,
) -> Union[Callable[[ProviderVar], ProviderVar], ProviderVar]:
return _store_or_global(store).mark_provider(func, weight=weight, for_type=for_type)


@_add_store_to_doc
def provide(
hint: Union[object, Type[T]],
store: Union[str, Store, None] = None,
) -> Optional[T]:
return _store_or_global(store).provide(hint=hint)


@_add_store_to_doc
def process(
result: Any,
*,
hint: Union[object, Type[T], None] = None,
first_processor_only: bool = False,
raise_exception: bool = False,
store: Union[str, Store, None] = None,
) -> None:
return _store_or_global(store).process(
result=result,
hint=hint,
first_processor_only=first_processor_only,
raise_exception=raise_exception,
return _store_or_global(store).mark_provider(
func, weight=weight, type_hint=type_hint
)


Expand All @@ -167,7 +130,7 @@ def mark_processor(
func: ProcessorVar,
*,
weight: float = 0,
for_type: Optional[object] = None,
type_hint: Optional[object] = None,
store: Union[str, Store, None] = None,
) -> ProcessorVar:
...
Expand All @@ -178,7 +141,7 @@ def mark_processor(
func: Literal[None] = ...,
*,
weight: float = 0,
for_type: Optional[object] = None,
type_hint: Optional[object] = None,
store: Union[str, Store, None] = None,
) -> Callable[[ProcessorVar], ProcessorVar]:
...
Expand All @@ -189,11 +152,50 @@ def mark_processor(
func: Optional[ProcessorVar] = None,
*,
weight: float = 0,
for_type: Optional[object] = None,
type_hint: Optional[object] = None,
store: Union[str, Store, None] = None,
) -> Union[Callable[[ProcessorVar], ProcessorVar], ProcessorVar]:
return _store_or_global(store).mark_processor(
func, weight=weight, for_type=for_type
func, weight=weight, type_hint=type_hint
)


@_add_store_to_doc
def iter_providers(
type_hint: Union[object, Type[T]], store: Union[str, Store, None] = None
) -> Iterable[Callable[[], Optional[T]]]:
return _store_or_global(store).iter_providers(type_hint)


@_add_store_to_doc
def iter_processors(
type_hint: Union[object, Type[T]], store: Union[str, Store, None] = None
) -> Iterable[Callable[[T], Any]]:
return _store_or_global(store).iter_processors(type_hint)


@_add_store_to_doc
def provide(
type_hint: Union[object, Type[T]],
store: Union[str, Store, None] = None,
) -> Optional[T]:
return _store_or_global(store).provide(type_hint=type_hint)


@_add_store_to_doc
def process(
result: Any,
*,
type_hint: Union[object, Type[T], None] = None,
first_processor_only: bool = False,
raise_exception: bool = False,
store: Union[str, Store, None] = None,
) -> None:
return _store_or_global(store).process(
result=result,
type_hint=type_hint,
first_processor_only=first_processor_only,
raise_exception=raise_exception,
)


Expand Down Expand Up @@ -247,7 +249,7 @@ def inject(


@overload
def process_output(
def inject_processors(
func: Callable[P, R],
*,
hint: Union[object, Type[T], None] = None,
Expand All @@ -259,7 +261,7 @@ def process_output(


@overload
def process_output(
def inject_processors(
func: Literal[None] = None,
*,
hint: Union[object, Type[T], None] = None,
Expand All @@ -271,17 +273,17 @@ def process_output(


@_add_store_to_doc
def process_output(
def inject_processors(
func: Optional[Callable[P, R]] = None,
*,
hint: Union[object, Type[T], None] = None,
first_processor_only: bool = False,
raise_exception: bool = False,
store: Union[str, Store, None] = None,
) -> Union[Callable[[Callable[P, R]], Callable[P, R]], Callable[P, R]]:
return _store_or_global(store).process_output(
return _store_or_global(store).inject_processors(
func=func,
hint=hint,
type_hint=hint,
first_processor_only=first_processor_only,
raise_exception=raise_exception,
)
Loading

0 comments on commit 4f132c8

Please sign in to comment.