Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1112275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:41:00+00:00 2026-05-17T02:41:00+00:00

The Python documentation for except says: For an except clause with an expression, that

  • 0

The Python documentation for except says:

For an except clause with an
expression, that expression is
evaluated, and the clause matches the
exception if the resulting object is
“compatible” with the exception. An
object is compatible with an exception
if it is the class or a base class of the exception object, […]

Why doesn’t except use isinstance instead of comparing base classes? This is preventing the use of __instancecheck__ to override the instance check.

EDIT:

I can understand that one of the reasons this doesn’t exist is that no one considered it. But are there any reasons why this should not be implemented?

EDIT:

Shell session from Python 3.2a showing that trying to use __subclasscheck__ for this doesn’t work:

>>> class MyType(type): __subclasscheck__ = lambda cls, other_cls: True
>>> class O(Exception, metaclass=MyType): pass
>>> issubclass(3, O)
0: True
>>> issubclass(int, O)
1: True
>>> try:
...     1/0
... except O:
...     print('Success')
Traceback (most recent call last):
  File "<pyshell#4>", line 2, in <module>
    1/0
ZeroDivisionError: division by zero
>>> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:41:01+00:00Added an answer on May 17, 2026 at 2:41 am

    The simple answer is probably that nobody considered it. A more complex answer would be that nobody considered it because it’s hard to get this right, because it would mean executing potentially arbitrary Python code while handling an exception, and that it is of dubious value. Exception classes in Python are typically very simple classes, and overloading them with functionality is often a mistake. It’s hard to imagine a case for having it consult __instancecheck__. If you have such a case (with or without a patch), file a bug and someone might pick it up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Python documentation says that the __init__ method of each class is responsible for
Python documentation says that os.rename(src, dst) ... On Windows, if dst already exists, OSError
I am trying to do python documentation generation with Sphinx. The problem is that
The Python 2 documentation says: Built-in Functions: map(function, iterable, ...) Apply function to every
The Python documentation specifies that is is legal to omit the parentheses if a
How is this implemented at a python level? I've got an object that pretends
I have a joystick class written in python with gobject, it works great except
The python documentation implies that duplicate items can exist within a list, and this
The Python documentation about the is operator says: The operators is and is not
The python documentation on array clearly states that the array conforms to the buffer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.