Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone explain what exactly this error means,TypeError: issubclass() arg 1 must be a class

Tags:

python

I have zero idea as to why I'm getting this error.

like image 861
gizgok Avatar asked Mar 17 '10 17:03

gizgok


2 Answers

as people said, the 2 arguments of issubclass() should be classes, not instances of an object.

consider this sample:

>>> issubclass( 1, int )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: issubclass() arg 1 must be a class
>>> issubclass( type(1), int )
True    
>>> isinstance( 1, int )
True

the key is the use of the type() function to get the type of an instance for use with the issubclass() function, which, as noted in another comment, is equivalent to calling isinstance()

like image 193
Adrien Plisson Avatar answered Oct 13 '22 00:10

Adrien Plisson


It means that you don't provide a class as argument for issubclass(). Both arguments have to be classes. Second argument can also be a tuple of classes.

If you show the code that throws this error, we can help further.


From the documentation:

issubclass(class, classinfo)
Return true if class is a subclass (direct or indirect) of classinfo. A class is considered a subclass of itself. classinfo may be a tuple of class objects, in which case every entry in classinfo will be checked. In any other case, a TypeError exception is raised.

like image 22
Felix Kling Avatar answered Oct 13 '22 00:10

Felix Kling