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
b4d0b39a
Commit
b4d0b39a
authored
Sep 22, 2019
by
Serhiy Storchaka
Committed by
GitHub
Sep 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-38209: Simplify dataclasses.InitVar by using __class_getitem__(). (GH-16255)
parent
1d094af7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
5 deletions
+4
-5
Lib/dataclasses.py
Lib/dataclasses.py
+4
-5
No files found.
Lib/dataclasses.py
View file @
b4d0b39a
...
...
@@ -199,11 +199,7 @@ _POST_INIT_NAME = '__post_init__'
# https://bugs.python.org/issue33453 for details.
_MODULE_IDENTIFIER_RE
=
re
.
compile
(
r'^(?:\
s*(
\w+)\
s*
\.)?\
s*(
\w+)'
)
class
_InitVarMeta
(
type
):
def
__getitem__
(
self
,
params
):
return
InitVar
(
params
)
class
InitVar
(
metaclass
=
_InitVarMeta
):
class
InitVar
:
__slots__
=
(
'type'
,
)
def
__init__
(
self
,
type
):
...
...
@@ -212,6 +208,9 @@ class InitVar(metaclass=_InitVarMeta):
def
__repr__
(
self
):
return
f'dataclasses.InitVar[
{
self
.
type
.
__name__
}
]'
def
__class_getitem__
(
cls
,
type
):
return
InitVar
(
type
)
# Instances of Field are only ever created from within this module,
# and only from the field() function, although Field instances are
...
...
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