Skip to content

Commit

Permalink
Merge pull request #1392 from dbluhm/fix/inject-return-type
Browse files Browse the repository at this point in the history
fix: return type of inject
  • Loading branch information
andrewwhitehead authored Sep 3, 2021
2 parents 820971f + 504a3d0 commit 136bed7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion aries_cloudagent/admin/request_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def inject(
self,
base_cls: Type[InjectType],
settings: Mapping[str, object] = None,
) -> Optional[InjectType]:
) -> InjectType:
"""
Get the provided instance of a given class identifier.
Expand Down
24 changes: 21 additions & 3 deletions aries_cloudagent/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ def inject(
self,
base_cls: Type[InjectType],
settings: Mapping[str, object] = None,
*,
required: bool = True,
) -> Optional[InjectType]:
) -> InjectType:
"""
Get the provided instance of a given class identifier.
Expand All @@ -127,6 +125,26 @@ def inject(
"""

@abstractmethod
def inject_or(
self,
base_cls: Type[InjectType],
settings: Mapping[str, object] = None,
default: Optional[InjectType] = None,
) -> Optional[InjectType]:
"""
Get the provided instance of a given class identifier or default if not found.
Args:
base_cls: The base class to retrieve an instance of
settings: An optional dict providing configuration to the provider
default: default return value if no instance is found
Returns:
An instance of the base class, or None
"""

@abstractmethod
def copy(self) -> "BaseInjector":
"""Produce a copy of the injector instance."""
Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/config/injection_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def inject(
self,
base_cls: Type[InjectType],
settings: Mapping[str, object] = None,
) -> Optional[InjectType]:
) -> InjectType:
"""
Get the provided instance of a given class identifier.
Expand Down
4 changes: 2 additions & 2 deletions aries_cloudagent/core/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def inject(
self,
base_cls: Type[InjectType],
settings: Mapping[str, object] = None,
) -> Optional[InjectType]:
) -> InjectType:
"""
Get the provided instance of a given class identifier.
Expand Down Expand Up @@ -255,7 +255,7 @@ def inject(
self,
base_cls: Type[InjectType],
settings: Mapping[str, object] = None,
) -> Optional[InjectType]:
) -> InjectType:
"""
Get the provided instance of a given class identifier.
Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/messaging/request_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def inject(
self,
base_cls: Type[InjectType],
settings: Mapping[str, object] = None,
) -> Optional[InjectType]:
) -> InjectType:
"""
Get the provided instance of a given class identifier.
Expand Down

0 comments on commit 136bed7

Please sign in to comment.