Skip to content

Commit

Permalink
Check for empty format specs (#2574)
Browse files Browse the repository at this point in the history
(cherry picked from commit a679550)
  • Loading branch information
nickdrozd authored and jacobtylerwalls committed Sep 22, 2024
1 parent 875651b commit d0709b3
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 @@ -15,6 +15,11 @@ Release date: TBA



* 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 @@ -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
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 d0709b3

Please sign in to comment.