Python: Object identity assertions thrown by differences in import statement notations
<p>When checking an object's identity, I am getting assertion errors because the object creation code imports the object-defining module under one notation (<code>base.other_stuff.BarCode</code>) and the identity-checking code imports that same module under a different notation (<code>other_stuff.BarCode</code>).  (Please see below for gory details.)</p>

<p>It seems that the isinstance() call is sticky about the references to the object definition module, and wants it imported under the exact same notation.  (I'm using version 2.5.)</p>

<p>I suppose could fix this by changing the import notation in the code checking the identity, but I'm worried that I'll just propagate the same problem to other code that depends on it.  And I'm sure there is some more elegant solution that I probably should be using in the first place.</p>

<p>So how do I fix this?</p>

<p>DETAILS</p>

<p>PythonPath: '/', '/base/'</p>

<p>Files: </p>

<pre><code>/__init__.py
base/__init__.py
base/other_stuff/__init__.py
base/other_stuff/BarCode.py
base/stuff/__init__.py
camp/__init__.py
</code></pre>

<p>Text of base/stuff/FooCode.py:</p>

<pre><code>import other_stuff.BarCode as bc

class Foo:
    def __init__(self, barThing):
        assert isinstance(barThing, bc.Bar)
</code></pre>

<p>Text of camp/new_code.py:</p>

<pre><code>import base.stuff.FooCode as fc
import base.other_stuff.BarCode as bc

thisBar = bc.Bar()
assert isinstance(thisBar, bc.Bar)
thisFoo = fc.Foo(barThing=thisBar)
</code></pre>

<p>This fails.  It survives its assertion test, but blows up on the assertion in the initial code.</p>

<p>However, it works when I modify new_code to import BarCode.py with:</p>

<pre><code>import other_stuff.BarCode as bc
</code></pre>

<p>. . . because both base/ and base/other_stuff are on the PythonPath.</p>
