[issue40180] isinstance(cls_with_metaclass, non_type) raises KeyError

Serhiy Storchaka report at bugs.python.org
Sat Apr 4 18:54:24 EDT 2020


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

> Sorry, I should have quoted the doc.  " If object is not an object of the given type, the function always returns False."  Raising instead is a bug -- even of the object itself is somewhat buggy.

You take it too literally. It does not mean that the function always returns a value. It can also raise an exception. If you press Ctrl-C it may raise an exception. If there is no memory to create some temporary objects, it may raise an exception. If you turn of the computer, it may neither return a value nor raise an exception.

You created a class whose __class__ attribute always raises an exception. What do you expect to get when you use this attribute? {}.__getitem__ always raise a KeyError, because an empty dict does not contain any key.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40180>
_______________________________________


More information about the Python-bugs-list mailing list