Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
d80b443f
Unverified
Kaydet (Commit)
d80b443f
authored
Ock 06, 2018
tarafından
Eric V. Smith
Kaydeden (comit)
GitHub
Ock 06, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-32279: Add additional params to make_dataclass(), pass through to dataclass(). (gh-5117)
üst
ed7d429e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
3 deletions
+26
-3
dataclasses.py
Lib/dataclasses.py
+7
-3
test_dataclasses.py
Lib/test/test_dataclasses.py
+17
-0
2018-01-06-16-50-11.bpo-32279.1xOpU8.rst
...S.d/next/Library/2018-01-06-16-50-11.bpo-32279.1xOpU8.rst
+2
-0
No files found.
Lib/dataclasses.py
Dosyayı görüntüle @
d80b443f
...
@@ -705,7 +705,8 @@ def _astuple_inner(obj, tuple_factory):
...
@@ -705,7 +705,8 @@ def _astuple_inner(obj, tuple_factory):
return
deepcopy
(
obj
)
return
deepcopy
(
obj
)
def
make_dataclass
(
cls_name
,
fields
,
*
,
bases
=
(),
namespace
=
None
):
def
make_dataclass
(
cls_name
,
fields
,
*
,
bases
=
(),
namespace
=
None
,
init
=
True
,
repr
=
True
,
eq
=
True
,
order
=
False
,
hash
=
None
,
frozen
=
False
):
"""Return a new dynamically created dataclass.
"""Return a new dynamically created dataclass.
The dataclass name will be 'cls_name'. 'fields' is an iterable
The dataclass name will be 'cls_name'. 'fields' is an iterable
...
@@ -723,6 +724,9 @@ def make_dataclass(cls_name, fields, *, bases=(), namespace=None):
...
@@ -723,6 +724,9 @@ def make_dataclass(cls_name, fields, *, bases=(), namespace=None):
b: int = field(init=False)
b: int = field(init=False)
For the bases and namespace paremeters, see the builtin type() function.
For the bases and namespace paremeters, see the builtin type() function.
The parameters init, repr, eq, order, hash, and frozen are passed to
dataclass().
"""
"""
if
namespace
is
None
:
if
namespace
is
None
:
...
@@ -745,8 +749,8 @@ def make_dataclass(cls_name, fields, *, bases=(), namespace=None):
...
@@ -745,8 +749,8 @@ def make_dataclass(cls_name, fields, *, bases=(), namespace=None):
namespace
[
'__annotations__'
]
=
anns
namespace
[
'__annotations__'
]
=
anns
cls
=
type
(
cls_name
,
bases
,
namespace
)
cls
=
type
(
cls_name
,
bases
,
namespace
)
return
dataclass
(
cls
)
return
dataclass
(
cls
,
init
=
init
,
repr
=
repr
,
eq
=
eq
,
order
=
order
,
hash
=
hash
,
frozen
=
frozen
)
def
replace
(
obj
,
**
changes
):
def
replace
(
obj
,
**
changes
):
"""Return a new object replacing specified fields with new values.
"""Return a new object replacing specified fields with new values.
...
...
Lib/test/test_dataclasses.py
Dosyayı görüntüle @
d80b443f
...
@@ -2033,6 +2033,23 @@ class TestCase(unittest.TestCase):
...
@@ -2033,6 +2033,23 @@ class TestCase(unittest.TestCase):
self
.
assertEqual
(
C
.
y
,
10
)
self
.
assertEqual
(
C
.
y
,
10
)
self
.
assertEqual
(
C
.
z
,
20
)
self
.
assertEqual
(
C
.
z
,
20
)
def
test_helper_make_dataclass_other_params
(
self
):
C
=
make_dataclass
(
'C'
,
[(
'x'
,
int
),
(
'y'
,
ClassVar
[
int
],
10
),
(
'z'
,
ClassVar
[
int
],
field
(
default
=
20
)),
],
init
=
False
)
# Make sure we have a repr, but no init.
self
.
assertNotIn
(
'__init__'
,
vars
(
C
))
self
.
assertIn
(
'__repr__'
,
vars
(
C
))
# Make sure random other params don't work.
with
self
.
assertRaisesRegex
(
TypeError
,
'unexpected keyword argument'
):
C
=
make_dataclass
(
'C'
,
[],
xxinit
=
False
)
def
test_helper_make_dataclass_no_types
(
self
):
def
test_helper_make_dataclass_no_types
(
self
):
C
=
make_dataclass
(
'Point'
,
[
'x'
,
'y'
,
'z'
])
C
=
make_dataclass
(
'Point'
,
[
'x'
,
'y'
,
'z'
])
c
=
C
(
1
,
2
,
3
)
c
=
C
(
1
,
2
,
3
)
...
...
Misc/NEWS.d/next/Library/2018-01-06-16-50-11.bpo-32279.1xOpU8.rst
0 → 100644
Dosyayı görüntüle @
d80b443f
Add params to dataclasses.make_dataclasses(): init, repr, eq, order, hash,
and frozen. Pass them through to dataclass().
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