How to pass an instance's reference in a method?
<p>I have the following Bird definition:</p>

<pre><code>class Bird:
    def __init__(self, swarm, position = None):
        if (swarm == None):
            raise ValueError("swarm variable should not be None!")

        if (not(type(swarm)).__name__ == 'ParticleSwarmOptimization'):
            raise TypeError("swarm variable must be of type ParticleSwarmOptimization!")
</code></pre>

<p>It is raising error in the last line. In the interpreter it prints:</p>

<pre><code>(type(swarm)).__name__
'instance'
</code></pre>

<p>I'd expect it to print "ParticleSwarmOptimization".
I'm calling Bird's constructor the following way:</p>

<pre><code>def AddBird(self, position = None):
    self.birds += Bird(self, position)
</code></pre>

<p>With this I want that every bird has a reference to the main ParticleSwarmOptimization class, and I want to ensure that every time a Bird is created I have in fact a ParticleSwarmOptimization instance reference and not anything else.</p>

<p>Thanks!</p>
