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
4e81296b
Unverified
Kaydet (Commit)
4e81296b
authored
May 16, 2018
tarafından
Eric V. Smith
Kaydeden (comit)
GitHub
May 16, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-33536: Validate make_dataclass() field names. (GH-6906)
üst
5db5c066
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
0 deletions
+17
-0
dataclasses.py
Lib/dataclasses.py
+15
-0
test_dataclasses.py
Lib/test/test_dataclasses.py
+0
-0
2018-05-16-10-07-40.bpo-33536._s0TE8.rst
...S.d/next/Library/2018-05-16-10-07-40.bpo-33536._s0TE8.rst
+2
-0
No files found.
Lib/dataclasses.py
Dosyayı görüntüle @
4e81296b
...
...
@@ -3,6 +3,7 @@ import sys
import
copy
import
types
import
inspect
import
keyword
__all__
=
[
'dataclass'
,
'field'
,
...
...
@@ -1100,6 +1101,9 @@ def make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True,
# Copy namespace since we're going to mutate it.
namespace
=
namespace
.
copy
()
# While we're looking through the field names, validate that they
# are identifiers, are not keywords, and not duplicates.
seen
=
set
()
anns
=
{}
for
item
in
fields
:
if
isinstance
(
item
,
str
):
...
...
@@ -1110,6 +1114,17 @@ def make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True,
elif
len
(
item
)
==
3
:
name
,
tp
,
spec
=
item
namespace
[
name
]
=
spec
else
:
raise
TypeError
(
f
'Invalid field: {item!r}'
)
if
not
isinstance
(
name
,
str
)
or
not
name
.
isidentifier
():
raise
TypeError
(
f
'Field names must be valid identifers: {name!r}'
)
if
keyword
.
iskeyword
(
name
):
raise
TypeError
(
f
'Field names must not be keywords: {name!r}'
)
if
name
in
seen
:
raise
TypeError
(
f
'Field name duplicated: {name!r}'
)
seen
.
add
(
name
)
anns
[
name
]
=
tp
namespace
[
'__annotations__'
]
=
anns
...
...
Lib/test/test_dataclasses.py
Dosyayı görüntüle @
4e81296b
This diff is collapsed.
Click to expand it.
Misc/NEWS.d/next/Library/2018-05-16-10-07-40.bpo-33536._s0TE8.rst
0 → 100644
Dosyayı görüntüle @
4e81296b
dataclasses.make_dataclass now checks for invalid field names and duplicate
fields. Also, added a check for invalid field specifications.
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