diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java index c58bd36a6ed0..3173371bc9c0 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java @@ -5,6 +5,7 @@ import com.intellij.idea.TestFor; import com.intellij.lang.FileASTNode; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.registry.Registry; import com.intellij.psi.PsiFile; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.testFramework.PsiTestUtil; @@ -615,6 +616,8 @@ public class Py3UnresolvedReferencesInspectionTest extends PyInspectionTestCase // PY-89245 public void testFlakyLoop() { + if (!Registry.is("python.use.better.control.flow.type.inference")) return; + doTestByText(""" class ListNode: def __init__(self, val=0, next=None): diff --git a/python/testSrc/com/jetbrains/python/types/PyInferenceMiscTypeTest.kt b/python/testSrc/com/jetbrains/python/types/PyInferenceMiscTypeTest.kt index 2096dd42d863..f708ab41b071 100644 --- a/python/testSrc/com/jetbrains/python/types/PyInferenceMiscTypeTest.kt +++ b/python/testSrc/com/jetbrains/python/types/PyInferenceMiscTypeTest.kt @@ -2,6 +2,7 @@ package com.jetbrains.python.types import com.intellij.idea.TestFor +import com.intellij.openapi.util.registry.Registry import com.jetbrains.python.fixtures.PyCodeInsightTestCase import com.jetbrains.python.psi.LanguageLevel import org.junit.jupiter.api.Disabled @@ -273,49 +274,57 @@ class PyInferenceMiscTypeTest : PyCodeInsightTestCase() { @Test @TestFor(issues = ["PY-76659"]) - fun `class chain fixed point in while loop`() = test(""" - class A: - def bar() -> "B": - return B() - class B: - def bar() -> "C": - return C() - class C: - def bar() -> "D": - return D() - class D: - def bar() -> A: - return A() + fun `class chain fixed point in while loop`() { + if (!Registry.`is`("python.use.better.control.flow.type.inference")) return - def foo(b): - x = A() - while b: - x = x.bar() + test(""" + class A: + def bar() -> "B": + return B() + class B: + def bar() -> "C": + return C() + class C: + def bar() -> "D": + return D() + class D: + def bar() -> A: + return A() - expr = x - # └ TYPE A | B | C | D - """) + def foo(b): + x = A() + while b: + x = x.bar() + + expr = x + # └ TYPE A | B | C | D + """) + } @Test @TestFor(issues = ["PY-76659"]) - fun `types in loop compute fast`() = test(""" - def is_empty(x: int, y: int) -> bool: - ... + fun `types in loop compute fast`() { + if (!Registry.`is`("python.use.better.control.flow.type.inference")) return - def drop_grain() -> None: - x, y = 500, 0 + test(""" + def is_empty(x: int, y: int) -> bool: + ... - while True: - if is_empty(x, y): - x, y = x + 1, y - elif is_empty(x, y): - x, y = x, y - elif is_empty((expr := x), y): - # └ TYPE Literal[500] | int - x, y = x, y - elif not is_empty(x, y): - break - """) + def drop_grain() -> None: + x, y = 500, 0 + + while True: + if is_empty(x, y): + x, y = x + 1, y + elif is_empty(x, y): + x, y = x, y + elif is_empty((expr := x), y): + # └ TYPE Literal[500] | int + x, y = x, y + elif not is_empty(x, y): + break + """) + } // TODO investigate the inference flakyness // The test is disabled because it's flaky: sometimes different types are inferred in the code analysis and user-initiated contexts. diff --git a/python/testSrc/com/jetbrains/python/types/PyTypeAliasAndFormsTest.kt b/python/testSrc/com/jetbrains/python/types/PyTypeAliasAndFormsTest.kt index 7a746930e49e..8f8f7c756343 100644 --- a/python/testSrc/com/jetbrains/python/types/PyTypeAliasAndFormsTest.kt +++ b/python/testSrc/com/jetbrains/python/types/PyTypeAliasAndFormsTest.kt @@ -2,6 +2,7 @@ package com.jetbrains.python.types import com.intellij.idea.TestFor +import com.intellij.openapi.util.registry.Registry import com.jetbrains.python.fixtures.PyCodeInsightTestCase import com.jetbrains.python.psi.LanguageLevel import org.junit.jupiter.api.Nested @@ -44,13 +45,18 @@ class PyTypeAliasAndFormsTest : PyCodeInsightTestCase() { @Test @TestFor(issues = ["PY-7058"]) - fun `type of an unknown value is Unknown`() = test( - """ - def f(x): - expr = type(x) - # └ TYPE Unknown - """, - ) + fun `type of an unknown value is Unknown`() { + test( + defaultTestOptions.copy( + assertRecursionPrevention = Registry.`is`("python.use.better.control.flow.type.inference"), + ), + """ + def f(x): + expr = type(x) + # └ TYPE Unknown + """, + ) + } @Test fun `Type of union of class objects`() = test("""