python-injector / python-injector/injector
Multibind should respect the `@singleton` decorator
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 94
- PR merge metrics
- No merged PRs in 30d
Description
A failing test case:
def test_multibind_respects_the_singleton_decorator() -> None:
@singleton
class SingletonPlugin(Plugin):
pass
def configure(binder: Binder) -> None:
binder.bind(Plugin, to=SingletonPlugin)
binder.multibind(List[Plugin], to=SingletonPlugin)
binder.multibind(List[Plugin], to=[SingletonPlugin])
binder.multibind(Dict[str, Plugin], to={'singleton1': SingletonPlugin, 'singleton2': SingletonPlugin})
injector = Injector([configure])
plugin_singleton = injector.get(Plugin)
plugins_list = injector.get(List[Plugin])
plugins_dict = injector.get(Dict[str, Plugin])
assert plugin_singleton is injector.get(Plugin)
assert plugins_list[0] is plugins_list[1] # Fails
assert plugins_dict['singleton1'] is plugins_dict['singleton2'] # Fails
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating and running the provided test named test_multibind_respects_the_singleton_decorator. Trace the Injector behavior for the direct Plugin binding and the list and dictionary multibind cases. Done means the repeated SingletonPlugin entries resolve to the same instance in both collections and the assertions pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100