summaryrefslogtreecommitdiffstats
path: root/Lib/dataclasses.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-06-18 08:34:57 (GMT)
committerGitHub <noreply@github.com>2022-06-18 08:34:57 (GMT)
commitf9433fff476aa13af9cb314fcc6962055faa4085 (patch)
tree1e8510f86eda5b339ab35c30127d00d5bf6d57f4 /Lib/dataclasses.py
parent084023ccbeb3bf54a2e19873c6a4b0bec7b617f6 (diff)
downloadcpython-f9433fff476aa13af9cb314fcc6962055faa4085.zip
cpython-f9433fff476aa13af9cb314fcc6962055faa4085.tar.gz
cpython-f9433fff476aa13af9cb314fcc6962055faa4085.tar.bz2
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).
Diffstat (limited to 'Lib/dataclasses.py')
-rw-r--r--Lib/dataclasses.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 18ab690..69cab8c 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -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)