This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients gvanrossum, kj, levkivskyi, martinitus, miss-islington, rhettinger, serhiy.storchaka
Date 2021-10-28.08:44:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1635410675.06.0.386270634215.issue45438@roundup.psfhosted.org>
In-reply-to
Content
> issubclass(x, list[int]) rejects the second argument for reasons explained in the PEP.

1. One problem is that isinstance(x, type) != issubclass(type(x), type)
if x is list[int]. It is unprecedented, I cannot recall any other case
in which isinstance() and issubclas() are inconsistent. Ant it breaks
code because these two expressions are often considered equivalent and
interchangeable in refactoring.

2. Other problem is that isinstance(x, type) is used as a guard before
using x as a type. `isinstance(obj, type) and issubclass(obj,
SomeClass)` is a common idiom, because issubclass() raises an exception
if its first argument is not a type. It is now broken for list[int].


> What other places are there that are broken because of this?
$ find Lib -name '*.py' \! -path '*/test*' -exec egrep 'isinstance.*,
type\)' '{}' + | wc -l
55

In msg403826 I showed few examples from just two files, but there are
tens more potential examples. I'll show them all if I have enough of
spare time.
History
Date User Action Args
2021-10-28 08:44:35serhiy.storchakasetrecipients: + serhiy.storchaka, gvanrossum, rhettinger, levkivskyi, miss-islington, kj, martinitus
2021-10-28 08:44:35serhiy.storchakasetmessageid: <1635410675.06.0.386270634215.issue45438@roundup.psfhosted.org>
2021-10-28 08:44:35serhiy.storchakalinkissue45438 messages
2021-10-28 08:44:34serhiy.storchakacreate