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
5160da1a
Kaydet (Commit)
5160da1a
authored
Kas 19, 2013
tarafından
R David Murray
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge: #19449: Handle non-string keys when generating 'fieldnames' error.
üst
0e60f85c
fb099c9e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
1 deletion
+16
-1
csv.py
Lib/csv.py
+1
-1
test_csv.py
Lib/test/test_csv.py
+12
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/csv.py
Dosyayı görüntüle @
5160da1a
...
@@ -146,7 +146,7 @@ class DictWriter:
...
@@ -146,7 +146,7 @@ class DictWriter:
wrong_fields
=
[
k
for
k
in
rowdict
if
k
not
in
self
.
fieldnames
]
wrong_fields
=
[
k
for
k
in
rowdict
if
k
not
in
self
.
fieldnames
]
if
wrong_fields
:
if
wrong_fields
:
raise
ValueError
(
"dict contains fields not in fieldnames: "
raise
ValueError
(
"dict contains fields not in fieldnames: "
+
", "
.
join
(
wrong_fields
))
+
", "
.
join
(
[
repr
(
x
)
for
x
in
wrong_fields
]
))
return
[
rowdict
.
get
(
key
,
self
.
restval
)
for
key
in
self
.
fieldnames
]
return
[
rowdict
.
get
(
key
,
self
.
restval
)
for
key
in
self
.
fieldnames
]
def
writerow
(
self
,
rowdict
):
def
writerow
(
self
,
rowdict
):
...
...
Lib/test/test_csv.py
Dosyayı görüntüle @
5160da1a
...
@@ -579,6 +579,18 @@ class TestDictFields(unittest.TestCase):
...
@@ -579,6 +579,18 @@ class TestDictFields(unittest.TestCase):
fileobj
=
StringIO
()
fileobj
=
StringIO
()
self
.
assertRaises
(
TypeError
,
csv
.
DictWriter
,
fileobj
)
self
.
assertRaises
(
TypeError
,
csv
.
DictWriter
,
fileobj
)
def
test_write_fields_not_in_fieldnames
(
self
):
with
TemporaryFile
(
"w+"
,
newline
=
''
)
as
fileobj
:
writer
=
csv
.
DictWriter
(
fileobj
,
fieldnames
=
[
"f1"
,
"f2"
,
"f3"
])
# Of special note is the non-string key (issue 19449)
with
self
.
assertRaises
(
ValueError
)
as
cx
:
writer
.
writerow
({
"f4"
:
10
,
"f2"
:
"spam"
,
1
:
"abc"
})
exception
=
str
(
cx
.
exception
)
self
.
assertIn
(
"fieldnames"
,
exception
)
self
.
assertIn
(
"'f4'"
,
exception
)
self
.
assertNotIn
(
"'f2'"
,
exception
)
self
.
assertIn
(
"1"
,
exception
)
def
test_read_dict_fields
(
self
):
def
test_read_dict_fields
(
self
):
with
TemporaryFile
(
"w+"
)
as
fileobj
:
with
TemporaryFile
(
"w+"
)
as
fileobj
:
fileobj
.
write
(
"1,2,abc
\r\n
"
)
fileobj
.
write
(
"1,2,abc
\r\n
"
)
...
...
Misc/NEWS
Dosyayı görüntüle @
5160da1a
...
@@ -56,6 +56,9 @@ Core and Builtins
...
@@ -56,6 +56,9 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
19449
:
in
csv
's writerow, handle non-string keys when generating the
error message that certain keys are not in the '
fieldnames
' list.
- Issue #8402: Added the escape() function to the glob module.
- Issue #8402: Added the escape() function to the glob module.
- Issue #17618: Add Base85 and Ascii85 encoding/decoding to the base64 module.
- Issue #17618: Add Base85 and Ascii85 encoding/decoding to the base64 module.
...
...
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