Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
TypeError for unbound method
-
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 partclass 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 -
-
At first look not really as when I instantiate I have passed
self
as the first paramater and use python2.x new objects ieclass 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.
-
Is it poseible you forgot the self when defining LookObject.init?
Are you able to instantiate a LookObject? -
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 inLightsCameras.py
(New file yet to add it to repo) it works fine but when I use it frommain.py
then the above issue is raised -
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 frommain.py
an TypeError is raised. Is this a bug in python/pythonista or have I missed something. I will upload it to the repo. -
Will it ever be run from
main.py
in the module, or just fromLightsCameras.py
? -
It will be used in
main.py
however I always try to make it so that classes can be tested from their own file... -
Right. Makes sense. (Btw typing this through SlideOver on my iPad and NodeBB does a great job adapting to the weird size.
-
I have seen this type of error before. It is caused by the
reload()
statements in yourmain.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 oldLookObject
class object.You could try replace
LookObject.__init__(...)
withsuper(PhysicsCamera, self).__init__(*args, **kwargs)
. Thesuper()
function should get the correct parent class. But it also means any changes to the parent class via reload are not honored. -
@ywangd that has resolved the issue, thank you for the infomation about it