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

Steven D'Aprano steve at pearwood.info
Mon Nov 29 01:13:00 CET 2010

cool-RR wrote:

>> Unfortunately it would be a backwards incompatible change. Currently
>> catching the TypeError from issubclass is a way of detecting that an object
>> *isn't* a type.
> Who is doing that?! What's wrong with something like `isinstance(thing,
> (type, types.ClassType))`?

Is that a serious question? Trying something, and catching the exception 
if it fails, is a general Python idiom. In many case, it's often 
considered more "pythonic" to write:

     handle normal case (which might fail)
except SomeException:
     handle exceptional case


if operation will fail:
    handle exceptional case
    handle normal case (which hopefully won't fail)

since at least Python 1.5. It's been long considered "best practice" 
under many circumstances to catch exceptions rather than to try to 
preemptively guess what might go wrong.


More information about the Python-ideas mailing list