Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
793cb854
Commit
793cb854
authored
Oct 13, 2019
by
Samuel Colvin
Committed by
Serhiy Storchaka
Oct 13, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-38431: Fix __repr__ method of InitVar to work with typing objects. (GH-16702)
parent
140a7d1f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
1 deletion
+9
-1
Lib/dataclasses.py
Lib/dataclasses.py
+6
-1
Lib/test/test_dataclasses.py
Lib/test/test_dataclasses.py
+2
-0
Misc/NEWS.d/next/Library/2019-10-10-16-53-00.bpo-38431.d5wzNp.rst
...S.d/next/Library/2019-10-10-16-53-00.bpo-38431.d5wzNp.rst
+1
-0
No files found.
Lib/dataclasses.py
View file @
793cb854
...
...
@@ -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
)
...
...
Lib/test/test_dataclasses.py
View file @
793cb854
...
...
@@ -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
...
...
Misc/NEWS.d/next/Library/2019-10-10-16-53-00.bpo-38431.d5wzNp.rst
0 → 100644
View file @
793cb854
Fix ``__repr__`` method for :class:`dataclasses.InitVar` to support typing objects, patch by Samuel Colvin.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment