-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: π¨ improve metadata decorators api
- Loading branch information
1 parent
8bb6d9d
commit 6624d41
Showing
18 changed files
with
235 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ def tests(session: Session) -> None: | |
'loguru', | ||
'pytest', | ||
'httpx', | ||
'pytest', | ||
'pytest-asyncio', | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,77 @@ | ||
from dataclasses import dataclass, field | ||
from typing import Callable, Generic, Type, TypeVar, Union | ||
|
||
from rodi import ServiceLifeStyle | ||
|
||
from ._meta import Meta, PestType | ||
|
||
try: | ||
from typing import TypeAlias | ||
except ImportError: | ||
from typing_extensions import TypeAlias | ||
|
||
T = TypeVar('T') | ||
|
||
|
||
Factory: TypeAlias = Callable[..., T] | ||
Scope: TypeAlias = ServiceLifeStyle | ||
InjectionToken: TypeAlias = Union[type, Type[T]] | ||
Class: TypeAlias = type | ||
|
||
|
||
@dataclass | ||
class InjectableMeta(Meta): | ||
meta_type: PestType = field(default=PestType.INJECTABLE, init=False) | ||
|
||
|
||
@dataclass | ||
class ProviderBase: | ||
"""π β base class for all providers.""" | ||
|
||
provide: InjectionToken | ||
'''π β unique injection token''' | ||
|
||
|
||
@dataclass | ||
class ClassProvider(ProviderBase): | ||
"""π β defines a `class` type provider""" | ||
|
||
use_class: Class | ||
'''π β type (class) of provider (type of the instance to be injected π)''' | ||
scope: Union[Scope, None] = None | ||
'''π β scope of the provider''' '' | ||
|
||
|
||
@dataclass | ||
class ValueProvider(ProviderBase, Generic[T]): | ||
"""π β defines a `value` (singleton) type provider""" | ||
|
||
use_value: T | ||
'''π β instance to be injected π''' | ||
|
||
|
||
@dataclass | ||
class SingletonProvider(ValueProvider, Generic[T]): | ||
"""π β defines a `singleton` (value) type provider""" | ||
|
||
pass | ||
|
||
|
||
@dataclass | ||
class FactoryProvider(ProviderBase, Generic[T]): | ||
"""π β defines a `factory` type provider""" | ||
|
||
use_factory: Factory[T] | ||
'''π β factory function that returns an instance of the provider''' | ||
scope: Union[Scope, None] = None | ||
'''π β scope of the provider''' | ||
|
||
|
||
@dataclass | ||
class ExistingProvider(ProviderBase, Generic[T]): | ||
"""π β defines an `existing` (aliased) type provider""" | ||
|
||
provide: str | ||
'''π β unique injection token of the existing provider''' | ||
use_existing: InjectionToken | ||
'''π β provider to be aliased by the injection token ''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.