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
eccf9c2e
Kaydet (Commit)
eccf9c2e
authored
Kas 19, 2013
tarafından
R David Murray
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#19449: Handle non-string keys when generating 'fieldnames' error.
Backport from 3.3 6e5afeada7ca.
üst
bab2415e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
2 deletions
+22
-2
csv.py
Lib/csv.py
+2
-2
test_csv.py
Lib/test/test_csv.py
+17
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/csv.py
Dosyayı görüntüle @
eccf9c2e
...
...
@@ -140,8 +140,8 @@ class DictWriter:
if
self
.
extrasaction
==
"raise"
:
wrong_fields
=
[
k
for
k
in
rowdict
if
k
not
in
self
.
fieldnames
]
if
wrong_fields
:
raise
ValueError
(
"dict contains fields not in fieldnames: "
+
", "
.
join
(
wrong_fields
))
raise
ValueError
(
"dict contains fields not in fieldnames: "
+
", "
.
join
([
repr
(
x
)
for
x
in
wrong_fields
]
))
return
[
rowdict
.
get
(
key
,
self
.
restval
)
for
key
in
self
.
fieldnames
]
def
writerow
(
self
,
rowdict
):
...
...
Lib/test/test_csv.py
Dosyayı görüntüle @
eccf9c2e
...
...
@@ -630,6 +630,23 @@ class TestDictFields(unittest.TestCase):
fileobj
=
StringIO
()
self
.
assertRaises
(
TypeError
,
csv
.
DictWriter
,
fileobj
)
def
test_write_fields_not_in_fieldnames
(
self
):
fd
,
name
=
tempfile
.
mkstemp
()
fileobj
=
os
.
fdopen
(
fd
,
"w+b"
)
try
:
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
)
finally
:
fileobj
.
close
()
os
.
unlink
(
name
)
def
test_read_dict_fields
(
self
):
fd
,
name
=
tempfile
.
mkstemp
()
fileobj
=
os
.
fdopen
(
fd
,
"w+b"
)
...
...
Misc/NEWS
Dosyayı görüntüle @
eccf9c2e
...
...
@@ -12,6 +12,9 @@ Core and Builtins
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
#
12853
:
Fix
NameError
in
distutils
.
command
.
upload
.
-
Issue
#
19523
:
Closed
FileHandler
leak
which
occurred
when
delay
was
set
.
...
...
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