diff options
| author | Samuel Colvin <samcolvin@gmail.com> | 2019-10-13 12:45:36 +0100 |
|---|---|---|
| committer | Serhiy Storchaka <storchaka@gmail.com> | 2019-10-13 14:45:36 +0300 |
| commit | 793cb85437299a3da3d74fe65480d720af330cbb (patch) | |
| tree | af1f297dba6baeb54bdb6838e840f79604d39b6d /Lib/dataclasses.py | |
| parent | 140a7d1f3579e778656a6b6bfad72489e9870a4d (diff) | |
| download | cpython-git-793cb85437299a3da3d74fe65480d720af330cbb.tar.gz | |
bpo-38431: Fix __repr__ method of InitVar to work with typing objects. (GH-16702)
Diffstat (limited to 'Lib/dataclasses.py')
| -rw-r--r-- | Lib/dataclasses.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py index 9135b07c9f..91c1f6f80f 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) |
