summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2022-07-09 17:50:21 -0400
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2022-07-10 08:26:53 +0200
commita13285a4c74c5a6f9a653b22d964035b094bc144 (patch)
treefb3d375ff691face23c4ff733204d51900743cf1
parent588f3e8d44653fc00fb1650cbb40bb7939ac0998 (diff)
downloadastroid-git-a13285a4c74c5a6f9a653b22d964035b094bc144.tar.gz
Fix a crash when inferring old-style string formatting (`%`) using tuples (#1697)
-rw-r--r--ChangeLog2
-rw-r--r--astroid/inference.py2
-rw-r--r--tests/unittest_inference.py3
3 files changed, 7 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 23bd762d..7fd42e25 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,8 @@ What's New in astroid 2.12.1?
=============================
Release date: TBA
+* Fix a crash when inferring old-style string formatting (``%``) using tuples.
+
* Fix a crash when ``None`` (or a value inferred as ``None``) participates in a
``**`` expression.
diff --git a/astroid/inference.py b/astroid/inference.py
index d9b7ac0e..b7ea5863 100644
--- a/astroid/inference.py
+++ b/astroid/inference.py
@@ -626,6 +626,8 @@ def _infer_old_style_string_formatting(
"""
values = None
if isinstance(other, nodes.Tuple):
+ if util.Uninferable in other.elts:
+ return (util.Uninferable,)
inferred_positional = [helpers.safe_infer(i, context) for i in other.elts]
if all(isinstance(i, nodes.Const) for i in inferred_positional):
values = tuple(i.value for i in inferred_positional)
diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py
index c43deade..b82ee8d8 100644
--- a/tests/unittest_inference.py
+++ b/tests/unittest_inference.py
@@ -6945,6 +6945,9 @@ class TestOldStyleStringFormatting:
age = 12
"My name is %0s, I'm %(age)s" % (fname, age)
""",
+ """
+ "My name is %s, I'm %s" % ((fname,)*2)
+ """,
],
)
def test_old_style_string_formatting_uninferable(self, format_string: str) -> None: