Forum Archive

TypeError for unbound method

Cethric

With the following call

PhysicsCamera(euclid.Vector3(-10, 10, -10), yaw=30, pitch=-30)

I am recieving a TypeError: unbound method of __init__() must be called with LookObject as first instance.
And this is the physics camera part

class PhysicsCamera(LookObject):
    def __init__(self, *args, **kwargs):
        LookObject.__init__(self, *args, **kwargs)
        self.camera_id = PhysicsWorld.add_camera(self)
        print "Camera ID:", self.camera_id

This is a new class that I am creating for my OpenGLES package.
Can someone please explain why this could be happening as this is exactly the same as how I normally subclass an object

Webmaster4o

Is this useful?

Cethric

At first look not really as when I instantiate I have passed self as the first paramater and use python2.x new objects ie

class x(object):
    pass

However thankyou for the response. For now I have do the long way around of just copying the class instead of instantiation.

JonB

Is it poseible you forgot the self when defining LookObject.init?
Are you able to instantiate a LookObject?

Cethric

This is how I instantiate the LookObject

class PhysicsCamera(LookObject):
    def __init__(self, *args, **kwargs):
        LookObject.__init__(self, *args, **kwargs)

But this raises TypeError unbound method __init__() must be called with LookObject as first argument (got PhysicsCamera instead).
I also noticed that when I run this from the python file it was created in LightsCameras.py (New file yet to add it to repo) it works fine but when I use it from main.py then the above issue is raised

Cethric

Further test show that it is just that file as I just tried to use a XMLModel object in it. When testing from LightsCameras.py it works fine but as soon as I test it from main.py an TypeError is raised. Is this a bug in python/pythonista or have I missed something. I will upload it to the repo.

Webmaster4o

Will it ever be run from main.py in the module, or just from LightsCameras.py?

Cethric

It will be used in main.py however I always try to make it so that classes can be tested from their own file...

Webmaster4o

Right. Makes sense. (Btw typing this through SlideOver on my iPad and NodeBB does a great job adapting to the weird size.

ywangd

I have seen this type of error before. It is caused by the reload() statements in your main.py file.

Reload will define a new class object for the same class. To Python interpreter, this new class object is considered as a different class from the old class object. If you have a subclass instance of the old class object, it will not be compatible with the new class object. In your case, it is most likely that the PhysicsCamera is still a subclass of the old LookObject class object.

You could try replace LookObject.__init__(...) with super(PhysicsCamera, self).__init__(*args, **kwargs). The super() function should get the correct parent class. But it also means any changes to the parent class via reload are not honored.

More info http://stackoverflow.com/questions/9394282/unbound-method-init-must-be-called-with-localeregexprovider-instance-as-fi

Cethric

@ywangd that has resolved the issue, thank you for the infomation about it