mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-89828: Do not relay the __class__ attribute in GenericAlias (#93754)
list[int].__class__ returned type, and isinstance(list[int], type) returned True. It caused numerous problems in code that checks isinstance(x, type).
This commit is contained in:
parent
084023ccbe
commit
f9433fff47
7 changed files with 18 additions and 20 deletions
|
@ -843,12 +843,11 @@ def singledispatch(func):
|
|||
return get_origin(cls) in {Union, types.UnionType}
|
||||
|
||||
def _is_valid_dispatch_type(cls):
|
||||
if isinstance(cls, type) and not isinstance(cls, GenericAlias):
|
||||
if isinstance(cls, type):
|
||||
return True
|
||||
from typing import get_args
|
||||
return (_is_union_type(cls) and
|
||||
all(isinstance(arg, type) and not isinstance(arg, GenericAlias)
|
||||
for arg in get_args(cls)))
|
||||
all(isinstance(arg, type) for arg in get_args(cls)))
|
||||
|
||||
def register(cls, func=None):
|
||||
"""generic_func.register(cls, func) -> func
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue