Skip to content

Commit

Permalink
Check for empty format specs (#2574)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd authored Sep 22, 2024
1 parent 58286a1 commit a679550
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4788,6 +4788,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
Expand Down
8 changes: 8 additions & 0 deletions tests/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit a679550

Please sign in to comment.