Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/dishka/dependency_source/activator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ def __init__(
self.marker_type = marker_type

def __get__(self, instance: Any, owner: Any) -> "Activator":
factory = self.factory.__get__(instance, owner)
factory = factory.replace(
when_active=None,
when_override=None,
)
return Activator(
factory=self.factory.__get__(instance, owner),
factory=factory,
marker=self.marker,
marker_type=self.marker_type,
)
Expand Down
7 changes: 5 additions & 2 deletions src/dishka/entities/marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class BaseMarker:
- marker1 | marker2 (OR)
- marker1 & marker2 (AND)
"""

def __invert__(self) -> Any:
return NotMarker(self)

Expand Down Expand Up @@ -80,8 +81,8 @@ def __eq__(self, other: object) -> bool:
if type(self) is not type(other):
return False
return bool(
(self.left == other.left and self.right == other.right) or
(self.right == other.left and self.left == other.right),
(self.left == other.left and self.right == other.right)
or (self.right == other.left and self.left == other.right),
)

def __ne__(self, other: object) -> bool:
Expand Down Expand Up @@ -146,6 +147,7 @@ class Has(Marker):
Used to check if a dependency can be created or is registered.
"""

def __repr__(self) -> str:
return f"Has({self.value})"

Expand All @@ -155,6 +157,7 @@ class HasContext(Marker):
"""
Special marker for checking if a type is available in current context.
"""

def __repr__(self) -> str:
return f"HasContext({self.value})"

Expand Down
18 changes: 18 additions & 0 deletions tests/unit/container/when/test_provider_when.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Marker,
Provider,
Scope,
activate,
alias,
decorate,
make_container,
Expand Down Expand Up @@ -341,3 +342,20 @@ def get_int(self) -> int:
DefaultProvider(), ConditionalProvider(), activator,
)
assert container.get(float) == expected


def test_activate_in_provider_with_when_no_recursion():
class TestProvider(Provider):
when = Marker("debug")
scope = Scope.APP

@activate(Marker("debug"))
def is_debug(self) -> bool:
return True

@provide()
def provide_int(self) -> int:
return 1

container = make_container(TestProvider())
assert container.get(int) == 1
Loading