diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/dataclasses.py | 7 | ||||
-rw-r--r-- | Lib/test/test_dataclasses.py | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py index 9135b07..91c1f6f 100644 --- a/Lib/dataclasses.py +++ b/Lib/dataclasses.py @@ -206,7 +206,12 @@ class InitVar: self.type = type def __repr__(self): - return f'dataclasses.InitVar[{self.type.__name__}]' + if isinstance(self.type, type): + type_name = self.type.__name__ + else: + # typing objects, e.g. List[int] + type_name = repr(self.type) + return f'dataclasses.InitVar[{type_name}]' def __class_getitem__(cls, type): return InitVar(type) diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py index 037bf4c..238335e 100644 --- a/Lib/test/test_dataclasses.py +++ b/Lib/test/test_dataclasses.py @@ -1102,6 +1102,8 @@ class TestCase(unittest.TestCase): # Make sure the repr is correct. self.assertEqual(repr(InitVar[int]), 'dataclasses.InitVar[int]') + self.assertEqual(repr(InitVar[List[int]]), + 'dataclasses.InitVar[typing.List[int]]') def test_init_var_inheritance(self): # Note that this deliberately tests that a dataclass need not |