diff --git a/ChangeLog b/ChangeLog index 6d7911cd1d..1f6ee6d560 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,11 @@ Release date: TBA Refs https://github.com/pylint-dev/pylint/pull/9932#issuecomment-2364985551 +* Fix a crash from inferring empty format specs. + + Closes pylint-dev/pylint#9945 + + What's New in astroid 3.3.3? ============================ Release date: 2024-09-20 diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py index 5ce00e3d6e..48326e2194 100644 --- a/astroid/nodes/node_classes.py +++ b/astroid/nodes/node_classes.py @@ -4779,6 +4779,9 @@ def _infer( def _infer_from_values( cls, nodes: list[NodeNG], context: InferenceContext | None = None, **kwargs: Any ) -> Generator[InferenceResult, None, InferenceErrorInfo | None]: + if not nodes: + yield + return if len(nodes) == 1: yield from nodes[0]._infer(context, **kwargs) return diff --git a/tests/test_inference.py b/tests/test_inference.py index 185ee0f650..daa5613565 100644 --- a/tests/test_inference.py +++ b/tests/test_inference.py @@ -7380,3 +7380,11 @@ def test_sys_argv_uninferable() -> None: sys_argv_value = list(a._infer()) assert len(sys_argv_value) == 1 assert sys_argv_value[0] is Uninferable + + +def test_empty_format_spec() -> None: + """Regression test for https://github.com/pylint-dev/pylint/issues/9945.""" + node = extract_node('f"{x:}"') + assert isinstance(node, nodes.JoinedStr) + + assert list(node.infer()) == [util.Uninferable]