gh-129678: ConfigParser: do not write an empty unnamed section (GH-12… · python/cpython@ef8eeca · GitHub
Skip to content

Commit ef8eeca

Browse files
gh-129678: ConfigParser: do not write an empty unnamed section (GH-129679)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent b9d2ee6 commit ef8eeca

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

Lib/configparser.py

Lines changed: 1 addition & 1 deletion

Lib/test/test_configparser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,6 +2161,14 @@ def test_no_section(self):
21612161
self.assertEqual('1', cfg2[configparser.UNNAMED_SECTION]['a'])
21622162
self.assertEqual('2', cfg2[configparser.UNNAMED_SECTION]['b'])
21632163

2164+
def test_empty_unnamed_section(self):
2165+
cfg = configparser.ConfigParser(allow_unnamed_section=True)
2166+
cfg.add_section(configparser.UNNAMED_SECTION)
2167+
cfg.add_section('section')
2168+
output = io.StringIO()
2169+
cfg.write(output)
2170+
self.assertEqual(output.getvalue(), '[section]\n\n')
2171+
21642172
def test_add_section(self):
21652173
cfg = configparser.ConfigParser(allow_unnamed_section=True)
21662174
cfg.add_section(configparser.UNNAMED_SECTION)
Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)