Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport maintenance/3.3.x] Check for empty format specs #2576

Merged
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 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 @@ -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]
Loading