mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
gh-89828: Do not relay the __class__ attribute in GenericAlias (GH-93754)
list[int].__class__ returned type, and isinstance(list[int], type)
returned True. It caused numerous problems in code that checks
isinstance(x, type).
(cherry picked from commit f9433fff47)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
2eff55cd46
commit
579e985e75
7 changed files with 18 additions and 20 deletions
|
|
@ -230,7 +230,7 @@ class InitVar:
|
|||
self.type = type
|
||||
|
||||
def __repr__(self):
|
||||
if isinstance(self.type, type) and not isinstance(self.type, GenericAlias):
|
||||
if isinstance(self.type, type):
|
||||
type_name = self.type.__name__
|
||||
else:
|
||||
# typing objects, e.g. List[int]
|
||||
|
|
@ -1248,7 +1248,7 @@ def _is_dataclass_instance(obj):
|
|||
def is_dataclass(obj):
|
||||
"""Returns True if obj is a dataclass or an instance of a
|
||||
dataclass."""
|
||||
cls = obj if isinstance(obj, type) and not isinstance(obj, GenericAlias) else type(obj)
|
||||
cls = obj if isinstance(obj, type) else type(obj)
|
||||
return hasattr(cls, _FIELDS)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue