Skip to content

Commit

Permalink
Merge branch 'improve-consistency-of-joinedstr-inference' of github.c…
Browse files Browse the repository at this point in the history
…om:ericvergnaud/astroid into improve-consistency-of-joinedstr-inference
  • Loading branch information
Eric Vergnaud committed Oct 22, 2024
2 parents 86d0cce + 94fdc4e commit 5c6f158
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4719,7 +4719,6 @@ def _infer(


class JoinedStr(NodeNG):

"""Represents a list of string expressions to be joined.
>>> import astroid
Expand Down Expand Up @@ -4790,7 +4789,11 @@ def _infer(
return

Check warning on line 4789 in astroid/nodes/node_classes.py

View check run for this annotation

Codecov / codecov/patch

astroid/nodes/node_classes.py#L4789

Added line #L4789 was not covered by tests
uninferable_already_generated = False
for inferred in self._infer_from_values(self.values, context):
failed = inferred is util.Uninferable or isinstance(inferred, Const) and MISSING_VALUE in inferred.value
failed = (
inferred is util.Uninferable
or isinstance(inferred, Const)
and MISSING_VALUE in inferred.value
)
if failed and self.FAIL_ON_UNINFERABLE:
if not uninferable_already_generated:
uninferable_already_generated = True
Expand Down Expand Up @@ -4822,7 +4825,9 @@ def _infer_from_values(
yield Const(result)

@classmethod
def _safe_infer_from_node(cls, node: NodeNG, context: InferenceContext | None = None, **kwargs: Any) -> Generator[InferenceResult, None, InferenceErrorInfo | None]:
def _safe_infer_from_node(
cls, node: NodeNG, context: InferenceContext | None = None, **kwargs: Any
) -> Generator[InferenceResult, None, InferenceErrorInfo | None]:
try:
yield from node._infer(context, **kwargs)
except InferenceError:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -7402,13 +7402,13 @@ class Cls:
s1 = f'{c_obj!r}' #@
""",
"<__main__.Cls",
False
False,
),
("s1 = f'{5}' #@", "5", False),
("s1 = f'{missing}'", None, True),
("s1 = f'{missing}'", "{MISSING_VALUE}", False),
("s1 = f'a/{missing}/b'", None, True),
("s1 = f'a/{missing}/b'", "a/{MISSING_VALUE}/b", False)
("s1 = f'a/{missing}/b'", "a/{MISSING_VALUE}/b", False),
],
)
def test_joined_str_returns_string(source, expected, fail) -> None:
Expand Down

0 comments on commit 5c6f158

Please sign in to comment.