8000 Convert key to string when accessing ConfigParser · remilapeyre/cpython@c8fff23 · GitHub
[go: up one dir, main page]

Skip to content

Commit c8fff23

Browse files
author
Rémi Lapeyre
committed
Convert key to string when accessing ConfigParser
1 parent ac28147 commit c8fff23

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Lib/configparser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,8 @@ def remove_section(self, section):
956956
return existed
957957

958958
def __getitem__(self, key):
959-
if key != self.default_section and not self.has_section(key):
959+
key = str(key)
960+
if not key in self:
960961
raise KeyError(key)
961962
return self._proxies[key]
962963

Lib/test/test_configparser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ def test_basic_from_dict(self):
428428
},
429429
})
430430

431+
def test_string_conversion(self):
432+
cf = self.newconfig()
433+
cf[123] = {}
434+
self.assertEqual(cf[123], {})
435+
431436
def test_case_sensitivity(self):
432437
cf = self.newconfig()
433438
cf.add_section("A")

0 commit comments

Comments
 (0)
0