[Python-ideas] `issubclass` shouldn't be raising exceptions for non-type inputs

Michael Foord fuzzyman at voidspace.org.uk
Sun Nov 28 23:43:51 CET 2010

On 28 November 2010 22:37, cool-RR <cool-rr at cool-rr.com> wrote:

> `issubclass(1, list)` raises an Exception, complaining that `1` is not a
> class. This is wrong in my opinion. It should just return False.
> Use case: I have an object which can be either a list, or a string, or a
> callable, or a type. And I want to check whether it's a sub-class of some
> base class.
> So I don't think I should be taking extra precautions before using
> `issubclass`: If my object is not a subclass of the given base class, I
> should just get `False`.
FWIW (which isn't much I guess) it annoys me that I have to protect calls to
issubclass with if isinstance(obj, type).

It isn't a subclass, so a False would be fine... The advantage of type
checking is earlier failures when you're doing something wrong. The
disadvantage is, well, all the disadvantages of type checking...

All the best,

Michael Foord

> Ram.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20101128/2dad8541/attachment.html>

More information about the Python-ideas mailing list