Skip to content

Commit

Permalink
Fix support for factory functions that return a different type (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
elfjes authored Jan 19, 2023
1 parent 7004413 commit d981c9c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/gimme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .resolvers import AttributeResolver, TypeHintingResolver
from .types import DependencyInfo

__version__ = "0.3.0"
__version__ = "0.3.1"

__all__ = [
"add",
Expand Down
2 changes: 1 addition & 1 deletion src/gimme/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def create(self, key: t.Type[T], repo=None, kwargs=None) -> T:

inst = self.resolve(info.factory, key=key, repo=repo, kwargs=combined_kwargs)
if do_store:
self.add(inst)
self.add(inst, cls=info.cls)
return inst

def resolve(self, factory, key, repo=None, kwargs=None):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_gimme.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ class MyDummy:
pass

repo.register(MyType, factory=MyDummy)
assert isinstance(repo.get(MyType), MyDummy)
repo.create(MyType)
assert MyType in repo

def test_can_lookup_obj_by_string(self, repo):
obj = object()
Expand Down

0 comments on commit d981c9c

Please sign in to comment.