[Python-ideas] `issubclass` shouldn't be raising exceptions for non-type inputs
solipsis at pitrou.net
Mon Nov 29 00:44:18 CET 2010
On Mon, 29 Nov 2010 00:37:12 +0200
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.
It raises an exception for the same reason that
1 in 'a'
raises an exception. Because there's no way that an int can belong in a
string, or an int can be a subclass of anything; and so passing an int
there is very likely to be a programming error.
Python is dynamically typed, it doesn't mean it is untyped (contrast
with PHP). If you want arbitrary polymorphism, you have to write the
supporting code yourself.
More information about the Python-ideas