bpo-45662: Fix the repr of InitVar with a type alias to the built-in class (GH-29291)
For example, InitVar[list[int]].
(cherry picked from commit 1fd4de5bddbbf2a97cdbac4d298c89e1156bdc6c)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index b3a9194..fe4094b 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -229,7 +229,7 @@ def __init__(self, type):
self.type = type
def __repr__(self):
- if isinstance(self.type, type):
+ if isinstance(self.type, type) and not isinstance(self.type, GenericAlias):
type_name = self.type.__name__
else:
# typing objects, e.g. List[int]