Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,11 @@ def __init__(self, defaults=None, dict_type=_default_dict,
self._interpolation = self._DEFAULT_INTERPOLATION
if self._interpolation is None:
self._interpolation = Interpolation()
if not isinstance(self._interpolation, Interpolation):
raise TypeError(
f"interpolation= must be None or an instance of Interpolation;"
f" got an object of type {type(self._interpolation)}"
)
if converters is not _UNSET:
self._converters.update(converters)
if defaults:
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,14 @@ def test_set_malformatted_interpolation(self):
self.assertEqual(cf.get("sect", "option2"), "foo%%bar")


class ConfigParserTestCaseInvalidInterpolationType(unittest.TestCase):
def test_error_on_wrong_type_for_interpolation(self):
for value in [configparser.ExtendedInterpolation, 42, "a string"]:
with self.subTest(value=value):
with self.assertRaises(TypeError):
configparser.ConfigParser(interpolation=value)


class ConfigParserTestCaseNonStandardDelimiters(ConfigParserTestCase):
delimiters = (':=', '$')
comment_prefixes = ('//', '"')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make the :class:`configparser.ConfigParser` constructor raise :exc:`TypeError` if the ``interpolation`` parameter is not of type :class:`configparser.Interpolation`