diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py index 68445e731c..00253f243b 100644 --- a/astroid/brain/brain_builtin_inference.py +++ b/astroid/brain/brain_builtin_inference.py @@ -946,7 +946,7 @@ def _infer_str_format_call( try: formatted_string = format_template.format(*pos_values, **keyword_values) - except IndexError: + except (IndexError, KeyError): # If there is an IndexError there are too few arguments to interpolate return iter([util.Uninferable]) diff --git a/tests/unittest_brain_builtin.py b/tests/unittest_brain_builtin.py index a659c4fdf2..54e7d2190d 100644 --- a/tests/unittest_brain_builtin.py +++ b/tests/unittest_brain_builtin.py @@ -93,6 +93,9 @@ def test_string_format(self, format_string: str) -> None: "My name is {}, I'm {}".format(Unknown, 12) """, """"I am {}".format()""", + """ + "My name is {fname}, I'm {age}".format(fsname = "Daniel", age = 12) + """, ], ) def test_string_format_uninferable(self, format_string: str) -> None: