summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-11-22 15:46:26 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-11-23 09:53:04 +0100
commita80d00be4c8310ade70413dabddfda50822e81ba (patch)
treeff02bc656787c26263019d5cf15451113475bccd
parent2c687133e4fcdd73ae3afa2e79be2160b150bb82 (diff)
downloadpylint-git-a80d00be4c8310ade70413dabddfda50822e81ba.tar.gz
Add regression tests for if in fstring comprehension
-rw-r--r--pylint/extensions/check_elif.py5
-rw-r--r--tests/functional/ext/check_elif/check_elif.py14
-rw-r--r--tests/functional/ext/check_elif/check_elif.txt4
3 files changed, 19 insertions, 4 deletions
diff --git a/pylint/extensions/check_elif.py b/pylint/extensions/check_elif.py
index 8dcfb74b3..76837a8ef 100644
--- a/pylint/extensions/check_elif.py
+++ b/pylint/extensions/check_elif.py
@@ -66,7 +66,10 @@ class ElseifUsedChecker(BaseTokenChecker):
orelse = node.parent.orelse
# current if node must directly follow an "else"
if orelse and orelse == [node]:
- if not self._elifs[self._if_counter]:
+ if (
+ self._if_counter < len(self._elifs)
+ and not self._elifs[self._if_counter]
+ ):
self.add_message("else-if-used", node=node)
self._if_counter += 1
diff --git a/tests/functional/ext/check_elif/check_elif.py b/tests/functional/ext/check_elif/check_elif.py
index b9722f349..23207ae8a 100644
--- a/tests/functional/ext/check_elif/check_elif.py
+++ b/tests/functional/ext/check_elif/check_elif.py
@@ -1,3 +1,5 @@
+# pylint: disable=no-else-raise,unsupported-membership-test,using-constant-test
+
"""Checks use of "else if" triggers a refactor message"""
@@ -7,7 +9,7 @@ def my_function():
if myint > 5:
pass
else:
- if myint <= 5: # [else-if-used]
+ if myint <= 5: # [else-if-used]
pass
else:
myint = 3
@@ -25,3 +27,13 @@ def my_function():
if myint:
pass
myint = 4
+
+
+def _if_in_fstring_comprehension():
+ order = {}
+ if "z" not in "false":
+ raise TypeError(
+ f" {', '.join(sorted(i for i in order or () if i not in vars))}"
+ )
+ elif "i" in "true":
+ raise TypeError("d")
diff --git a/tests/functional/ext/check_elif/check_elif.txt b/tests/functional/ext/check_elif/check_elif.txt
index 43d1e3b1e..6c72f56f0 100644
--- a/tests/functional/ext/check_elif/check_elif.txt
+++ b/tests/functional/ext/check_elif/check_elif.txt
@@ -1,2 +1,2 @@
-else-if-used:10:8:my_function:"Consider using ""elif"" instead of ""else if""":HIGH
-else-if-used:22:20:my_function:"Consider using ""elif"" instead of ""else if""":HIGH
+else-if-used:12:8:my_function:"Consider using ""elif"" instead of ""else if""":HIGH
+else-if-used:24:20:my_function:"Consider using ""elif"" instead of ""else if""":HIGH