Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

isinstance(x, type) returns True for instances of types.GenericAlias (like 
list[int]). While it may help in some cases related to typing, in many 
unrelated cases it causes problems if the value which is not a type passes 
checks for types.

Also, isinstance(x, type) been not equal to issubclass(type(x), type) can cause 
other problems. No matter what the result should be, it should be consistent.

There are many occurrences of isinstance(..., type) in the code.

$ find Lib -name '*.py' \! -path '*/test*' -exec egrep 'isinstance.*,
type\)' '{}' + | wc -l
55

And all of them can potentially be broken if pass a types.GenericAlias 
instance. Many of them are safe, but every case should be analyzed.

----------
dependencies: +Incorrect repr of InitVar of a type alias, help(list[int]) 
fails, inspect not capturing type annotations created by __class_getitem__, 
is_dataclass() does not work for dataclasses which are subclasses of 
types.GenericAlias, resolve_bases() and new_class() do not work with type alias 
of a built-in type
nosy: +gvanrossum, kj

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45665>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to