-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: support protocols support protocols * chore: expand scope of test expand scope of test by also testing protocols * chore: upgrade action version and expand python check support upgrade action version and expand python check support * chore: drop 3.11 and 3.12 support drop 3.11 and 3.12 support * chore: update dependencies and address typing update dependencies and address typing * fix: add missing httpx package add missing httpx package * fix: removed outdated timeout arg for pytest, arranged typing arranged typing and removed outdated pytest arg * chore: reinclude support for python 3.11 and 3.12 tests reinclude support for python 3.11 and 3.12 tests * chore: drop support for python 3.7 drop support for python 3.7 Co-authored-by: Capi Etheriel <[email protected]> --------- Co-authored-by: Capi Etheriel <[email protected]>
- Loading branch information
1 parent
ad7b2cd
commit 68dc8ba
Showing
7 changed files
with
433 additions
and
439 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,6 +1,5 @@ | ||
[tool:pytest] | ||
testpaths = tests | ||
timeout = 10 | ||
|
||
[black] | ||
line_length=120 | ||
|
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,16 +1,42 @@ | ||
from abc import ABC | ||
from typing import Protocol, List | ||
|
||
from kink import inject, di | ||
|
||
class Repository: | ||
pass | ||
|
||
class Repository(Protocol): | ||
def __init__(self) -> None: | ||
pass | ||
|
||
|
||
@inject(alias=Repository, use_factory=True) | ||
class PerInstanceRepository(Repository): | ||
pass | ||
pass | ||
|
||
|
||
@inject(alias=Repository) | ||
class Repository1(Repository): | ||
pass | ||
|
||
|
||
@inject(alias=Repository) | ||
class Repository2(Repository): | ||
repo: Repository1 = di[Repository1] | ||
|
||
|
||
@inject | ||
class Service: | ||
def __init__(self, repository: Repository): | ||
pass | ||
|
||
def __init__(self, repositories: List[Repository]): | ||
self._repositories = repositories | ||
|
||
|
||
def test_can_inject_aliased_factory_services(): | ||
di[Service] | ||
service: Service = di[Service] | ||
assert service is not None | ||
assert service._repositories is not None | ||
assert len(service._repositories) == 3 | ||
repository: Repository = di[Repository2] | ||
assert repository.repo is not None | ||
repositories: List[Repository] = di[List[Repository]] | ||
assert repositories is not None | ||
assert len(repositories) == 3 |