mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-38431: Fix __repr__ method of InitVar to work with typing objects. (GH-16702)
This commit is contained in:
parent
140a7d1f35
commit
793cb85437
3 changed files with 9 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue