Skip to content

Commit 7dda588

Browse files
Add a test case that make the hot fix fail
We do not remove the hotfix in order to have a false positive instead of a crash is something else is still buggy.
1 parent 31113e9 commit 7dda588

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

pylint/extensions/check_elif.py

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def visit_ifexp(self, node: nodes.IfExp) -> None:
5959

6060
def visit_comprehension(self, node: nodes.Comprehension) -> None:
6161
self._if_counter += len(node.ifs)
62+
self._elifs.insert(self._if_counter, True)
6263

6364
@check_messages("else-if-used")
6465
def visit_if(self, node: nodes.If) -> None:
@@ -67,6 +68,8 @@ def visit_if(self, node: nodes.If) -> None:
6768
# current if node must directly follow an "else"
6869
if orelse and orelse == [node]:
6970
if (
71+
# Safeguard if we missed an if in self._elifs
72+
# See https://github.com/PyCQA/pylint/pull/5369
7073
self._if_counter < len(self._elifs)
7174
and not self._elifs[self._if_counter]
7275
):

tests/functional/e/elif_checker.py

+14
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,17 @@ def _if_in_fstring_comprehension():
3737
)
3838
elif "i" in "true":
3939
raise TypeError("d")
40+
41+
def _if_in_fstring_comprehension_with_elif():
42+
order = {}
43+
if "z" not in "false":
44+
raise TypeError(
45+
f" {', '.join(sorted(i for i in order or () if i not in vars))}"
46+
)
47+
elif "z" not in "true":
48+
pass
49+
else:
50+
if "t" not in "false": # [else-if-used]
51+
raise TypeError("d")
52+
else:
53+
print("e")

tests/functional/e/elif_checker.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
else-if-used:12:8:my_function:"Consider using ""elif"" instead of ""else if""":HIGH
22
else-if-used:24:20:my_function:"Consider using ""elif"" instead of ""else if""":HIGH
3+
else-if-used:50:8:_if_in_fstring_comprehension_with_elif:"Consider using ""elif"" instead of ""else if""":HIGH

0 commit comments

Comments
 (0)