diff options
author | RĂ©mi Lapeyre <remi.lapeyre@henki.fr> | 2019-05-10 01:50:11 (GMT) |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2019-05-10 01:50:11 (GMT) |
commit | fce5ff1e18b522cf52379934a6560583d840e7f9 (patch) | |
tree | 89d1c624372e8840a1c843e4e78f16088e32df1a /Lib | |
parent | d237b3f0f61990c972b84c45eb4fe137db51a6a7 (diff) | |
download | cpython-fce5ff1e18b522cf52379934a6560583d840e7f9.zip cpython-fce5ff1e18b522cf52379934a6560583d840e7f9.tar.gz cpython-fce5ff1e18b522cf52379934a6560583d840e7f9.tar.bz2 |
bpo-27497: Add return value to csv.DictWriter.writeheader (GH-12306)
csv.DictWriter.writeheader() now returns the return value of the
underlying csv.Writer.writerow() method.
Patch contributed by Ashish Nitin Patil.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/csv.py | 2 | ||||
-rw-r--r-- | Lib/test/test_csv.py | 6 |
2 files changed, 7 insertions, 1 deletions
@@ -140,7 +140,7 @@ class DictWriter: def writeheader(self): header = dict(zip(self.fieldnames, self.fieldnames)) - self.writerow(header) + return self.writerow(header) def _dict_to_list(self, rowdict): if self.extrasaction == "raise": diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index 7a33313..a16d140 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -608,6 +608,12 @@ class TestQuotedEscapedExcel(TestCsvBase): class TestDictFields(unittest.TestCase): ### "long" means the row is longer than the number of fieldnames ### "short" means there are fewer elements in the row than fieldnames + def test_writeheader_return_value(self): + with TemporaryFile("w+", newline='') as fileobj: + writer = csv.DictWriter(fileobj, fieldnames = ["f1", "f2", "f3"]) + writeheader_return_value = writer.writeheader() + self.assertEqual(writeheader_return_value, 10) + def test_write_simple_dict(self): with TemporaryFile("w+", newline='') as fileobj: writer = csv.DictWriter(fileobj, fieldnames = ["f1", "f2", "f3"]) |