summaryrefslogtreecommitdiffstats
path: root/Lib/dataclasses.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-10-13 12:04:05 (GMT)
committerGitHub <noreply@github.com>2019-10-13 12:04:05 (GMT)
commit6da52ac411947d1a7958bbad831fcf8dfc8c95fe (patch)
treed72f830cb7de4d7b089a3061f1cebd7301b95862 /Lib/dataclasses.py
parentba44ea6ff8be2b7874c4358f89d5b6f4a558f711 (diff)
downloadcpython-6da52ac411947d1a7958bbad831fcf8dfc8c95fe.zip
cpython-6da52ac411947d1a7958bbad831fcf8dfc8c95fe.tar.gz
cpython-6da52ac411947d1a7958bbad831fcf8dfc8c95fe.tar.bz2
bpo-38431: Fix __repr__ method of InitVar to work with typing objects. (GH-16702)
(cherry picked from commit 793cb85437299a3da3d74fe65480d720af330cbb) Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Diffstat (limited to 'Lib/dataclasses.py')
-rw-r--r--Lib/dataclasses.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 2f0e5ff..391f32e 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -210,7 +210,12 @@ class InitVar(metaclass=_InitVarMeta):
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}]'
# Instances of Field are only ever created from within this module,