mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-24445 Fixed: False positive: PyCharm ignores issubclass check inside list comprehension
Update PyControlFlowBuilder to use PyTypeAssertionEvaluator while visiting if-components inside comprehensions.
This commit is contained in:
@@ -730,7 +730,10 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
|
||||
else {
|
||||
myBuilder.startNode(condition);
|
||||
}
|
||||
final PyTypeAssertionEvaluator assertionEvaluator = new PyTypeAssertionEvaluator();
|
||||
condition.accept(this);
|
||||
condition.accept(assertionEvaluator);
|
||||
InstructionBuilder.addAssertInstructions(myBuilder, assertionEvaluator);
|
||||
|
||||
// Condition is true for nested "for" and "if" constructs, next startNode() should create a conditional node
|
||||
prevCondition = condition;
|
||||
|
||||
@@ -595,6 +595,19 @@ public class Py3TypeTest extends PyTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
// PY-24445
|
||||
public void testIsSubclassInsideListComprehension() {
|
||||
doTest("List[Type[A]]",
|
||||
"class A: pass\n" +
|
||||
"expr = [e for e in [] if issubclass(e, A)]");
|
||||
}
|
||||
|
||||
public void testIsInstanceInsideListComprehension() {
|
||||
doTest("List[A]",
|
||||
"class A: pass\n" +
|
||||
"expr = [e for e in [] if isinstance(e, A)]");
|
||||
}
|
||||
|
||||
private void doTest(final String expectedType, final String text) {
|
||||
myFixture.configureByText(PythonFileType.INSTANCE, text);
|
||||
final PyExpression expr = myFixture.findElementByText("expr", PyExpression.class);
|
||||
|
||||
Reference in New Issue
Block a user