Discussion:
[Maya-Python] # Error: TypeError: super(type, obj): obj must be an instance or subtype of type #
Rudi Hammad
2018-08-13 17:58:00 UTC
Permalink
Hi,

I was working on an inheritance "tree" when I found that problem.
I have classA that is the base class of classB, and the classB is the base
class of both classC1 and classC1.
classA
|
classB
/ \
classC1 classC2

Each class is in a diferent module so, something like

moduleA.py
class ClassA(object):
def __init__(self, name):
print name

moduleB.py
import moduleA; reload(moduleA)

class ClassB(moduleA.ClassA):
def __init__(self,name):
super(ClassB, self).__init__(name)

moduleC1.py
import moduleB; reload(moduleB)

class ClassC1(moduleB.ClassB):
def __init__(self,name):
super(ClassC1, self).__init__(name)

moduleC2.py
Introducir código aquí...import moduleB; reload(moduleB)

class ClassC2(moduleB.ClassB):
def __init__(self,name):
super(ClassC2, self).__init__(name)


And this is when I get the # Error: TypeError: super(type, obj): obj must
be an instance or subtype of type #
import moduleA;
classA = moduleA.ClassA("foo")
import moduleB;
classB = moduleB.ClassB("foo")
import moduleC1; reload(moduleC1)
classC1 = moduleC1.ClassC1("foo") # workd Ok at this point
import moduleC2;
classC2 = moduleC2.ClassC2("foo")

# this time if I do this, I get the error
classC1 = moduleC1.ClassC1("foo")
# Error: TypeError: super(type, obj): obj must be an instance or subtype of
type #


I have been reading all day about it. I have read that you should never
user super(), then that you always should use super(), then that you should
never reload a module but I need to reload my module while I am
developing... So I thought to ask here.

I guess my real question, besides the error which I can read more about it,
is what is wrong with the design of that code.In this simple example to
create this tree where class C1 and class C2 inherite from the same classB,
what am I doing wrong?

Thank you

R
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/004e7a43-f363-4407-adee-4aca3dfe518a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Rudi Hammad
2018-08-13 18:00:55 UTC
Permalink
(uppss... sorry about the "Introducir código aquí..." in moduleC2.py
example)
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c59b01cb-834a-4488-b2d0-2e5a91d35ce4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Rudi Hammad
2018-08-13 19:02:59 UTC
Permalink
By the way, I have printed out the adress of moduleB.ClassB in moduleC1.py
and moduleC2.py.
Because I have added reload(moduleB) in each module, that reload is
changing the adress of the class moduleB.ClassB, so when I do the second
time classC1 = moduleC1.ClassC1("foo")
there is nothing there because the adress changed. So I get that error. Is
that correct?

Still, I am not sure of to design the code to keep that class "tree"
mentioned before. I need the reload to update my progress to the
subclasses, but by doing so,
the memory address changes.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ee76aacf-2e05-471a-9029-56bb3f292194%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2018-08-13 20:03:50 UTC
Permalink
Super is a problem when a class is using multiple inheritance. But you
aren't using multiple inheritance here.

I would recommend to stop using reload() here. When you reload one module
it will leave other interdependent modules in conflicting states. As you
have identified, the memory address is changing because the reload creates
another copy of all the contents in the module. This means the other
modules can have old references. The C class may end up having a bad
reference if the B class gets redefined. If you really need this reload
functionality (which should not be left in place for a production deploy)
then you could search for a "deep reload" solution online. This would at
least reload everything related to what you are reloading. Or, you could
remove the reloads from the modules and just manually reload in the right
order as needed:

reload(A)
reload(B)
reload(C)
Post by Rudi Hammad
By the way, I have printed out the adress of moduleB.ClassB in
moduleC1.py and moduleC2.py.
Because I have added reload(moduleB) in each module, that reload is
changing the adress of the class moduleB.ClassB, so when I do the second
time classC1 = moduleC1.ClassC1("foo")
there is nothing there because the adress changed. So I get that error. Is
that correct?
Still, I am not sure of to design the code to keep that class "tree"
mentioned before. I need the reload to update my progress to the
subclasses, but by doing so,
the memory address changes.
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/ee76aacf-2e05-471a-9029-56bb3f292194%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/ee76aacf-2e05-471a-9029-56bb3f292194%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2orO8nwdkQ88G4V4BqGAswQFe_mKqoEjrD1%3D9v5gP%3D0g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Rudi Hammad
2018-08-13 21:08:51 UTC
Permalink
Cool, thanks for clarifying this. I spent all day thinking what was wrong.
I'll just reload thinks manually during dev.

Cheers
Post by Justin Israel
Super is a problem when a class is using multiple inheritance. But you
aren't using multiple inheritance here.
I would recommend to stop using reload() here. When you reload one module
it will leave other interdependent modules in conflicting states. As you
have identified, the memory address is changing because the reload creates
another copy of all the contents in the module. This means the other
modules can have old references. The C class may end up having a bad
reference if the B class gets redefined. If you really need this reload
functionality (which should not be left in place for a production deploy)
then you could search for a "deep reload" solution online. This would at
least reload everything related to what you are reloading. Or, you could
remove the reloads from the modules and just manually reload in the right
reload(A)
reload(B)
reload(C)
Post by Rudi Hammad
By the way, I have printed out the adress of moduleB.ClassB in
moduleC1.py and moduleC2.py.
Because I have added reload(moduleB) in each module, that reload is
changing the adress of the class moduleB.ClassB, so when I do the second
time classC1 = moduleC1.ClassC1("foo")
there is nothing there because the adress changed. So I get that error.
Is that correct?
Still, I am not sure of to design the code to keep that class "tree"
mentioned before. I need the reload to update my progress to the
subclasses, but by doing so,
the memory address changes.
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/ee76aacf-2e05-471a-9029-56bb3f292194%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/ee76aacf-2e05-471a-9029-56bb3f292194%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/05a08776-c179-4a7a-bf5a-fded55fffafb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...