"except" and "subclasscheck" changed between CPython2 and 3

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Mar 5 20:11:38 EST 2018


On Sat, 03 Mar 2018 04:28:24 +0000, 高岡陽太 wrote:

> Hello,
> 
> I found a difference of behavior about `except` statement between
> CPython 2.7 and 3.x .
> `except EXC_CLASS:` calls `__subclasscheck__` in 2.7, but does not in
> 3.x .


Python 3 does not accept virtual subclasses for exception handling. They 
have to be concrete subclasses of BaseException.

There is a feature-request to support that (as Python 2.7 does):

https://bugs.python.org/issue12029

but it is stalled.



-- 
Steve




More information about the Python-list mailing list