def addError(self, e):
if not isinstance(e, Error):
raise ValueError('{0} is not type {0}'.format(e, Error))
self.__errors.append(e)
Message:
ValueError: <class 'api.utils.Error'>
is not type <class 'api.utils.Error'>
Return Type of isinstance() in Python This function returns a boolean value, i.e., True or False. It will return True if the object class matches the classinfo class; otherwise, False.
isinstance() checks whether or not the object is an instance or subclass of the classinfo.
What Are Differences Between type() and isinstance()? and isinstance() is that type(object) returns the type of an object and isinstance(object, class ) returns True if the object argument is an instance of the class argument or in a direct or indirect subclass relationship.
The isinstance() function returns True if the specified object is of the specified type, otherwise False . If the type parameter is a tuple, this function will return True if the object is one of the types in the tuple.
You're passing the class itself, not an instance of the class. That explains your problem.
>>> class A:
pass
>>> isinstance(A, A)
False
What you probably want is to check an instance:
>>> isinstance(A(), A)
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With