Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

raises ConflictingExplicitBindingsError when it shouldn't #12

Open
danmilon opened this issue Nov 9, 2016 · 0 comments
Open

raises ConflictingExplicitBindingsError when it shouldn't #12

danmilon opened this issue Nov 9, 2016 · 0 comments

Comments

@danmilon
Copy link

danmilon commented Nov 9, 2016

I bumped into a very very weird issue.

#! /usr/bin/env python2.7
import pinject


class FoundationA(object):
    @pinject.inject()
    def __init__(self, arg):
        self.arg = arg


class FoundationB(object):
    @pinject.inject()
    def __init__(self, arg):
        self._arg = arg


class BindingSpec(pinject.BindingSpec):
    def configure(self, bind):
        bind('arg', to_instance=1)

object_graph = pinject.new_object_graph(
    binding_specs=[
        BindingSpec(),
    ],
    only_use_explicit_bindings=True
)

foundation_a = object_graph.provide(FoundationA)
print(foundation_a.arg)

foundation_b = object_graph.provide(FoundationB)
print(foundation_b.arg)

This should print

1
1

Instead it raises ConflictingExplicitBindingsError.

$ python ./t.py 
Traceback (most recent call last):
  File "./t.py", line 25, in <module>
    only_use_explicit_bindings=True
  File "/tmp/venv/lib/python2.7/site-packages/pinject/object_graph.py", line 159, in new_object_graph
    raise e
pinject.errors.ConflictingExplicitBindingsError: multiple explicit bindings for same binding name:
  the binding at ./t.py:5, from the binding name "foundation" (unannotated) to the class __main__.FoundationA at ./t.py:5, in "singleton scope" scope
  the binding at ./t.py:11, from the binding name "foundation" (unannotated) to the class __main__.FoundationB at ./t.py:11, in "singleton scope" scope

Some very weird magic is happening behind the scenes, even though I've set only_use_explicit_bindings=True!

Any idea what might be wrong?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant