From f247cfde524e13425430184e376b0bd6163eee14 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Fri, 5 Mar 2021 00:22:16 +0300 Subject: [PATCH] Drop explicit language level specification in tests that use python-latest project descriptor GitOrigin-RevId: 6f31bbf0cf26ccca4ffb1a5bd10677cb1d7a9352 --- .../InitializingNewType.py | 4 +- .../jetbrains/python/Py3CompletionTest.java | 107 +- .../jetbrains/python/Py3DeprecationTest.java | 12 +- .../jetbrains/python/Py3HighlightingTest.java | 3 +- .../Py3MethodOverridingInspectionTest.java | 3 +- .../com/jetbrains/python/Py3QuickFixTest.java | 41 +- .../com/jetbrains/python/Py3ResolveTest.java | 303 ++--- .../com/jetbrains/python/Py3TypeTest.java | 1010 ++++++++--------- .../com/jetbrains/python/PyTypingTest.java | 140 +-- .../Py3AbstractClassInspectionTest.java | 3 +- .../Py3StringFormatInspectionTest.java | 27 +- .../Py3TypeCheckerInspectionTest.java | 70 +- ...Py3UnresolvedReferencesInspectionTest.java | 43 +- .../PyAsyncCallInspectionTest.java | 17 +- .../PyTypeHintsInspectionTest.java | 230 ++-- .../com/jetbrains/python/pyi/PyiTypeTest.java | 24 +- .../quickFixes/PyAsyncCallQuickFixTest.java | 5 +- 17 files changed, 863 insertions(+), 1179 deletions(-) diff --git a/python/testData/inspections/PyTypeCheckerInspection/InitializingNewType.py b/python/testData/inspections/PyTypeCheckerInspection/InitializingNewType.py index 77502eccc458..0bb081f75684 100644 --- a/python/testData/inspections/PyTypeCheckerInspection/InitializingNewType.py +++ b/python/testData/inspections/PyTypeCheckerInspection/InitializingNewType.py @@ -8,5 +8,5 @@ b = UserId("John"42) -KeyValue({"key1": "key2"}) +KeyValue(42) +KeyValue({"key1": "key2"}) diff --git a/python/testSrc/com/jetbrains/python/Py3CompletionTest.java b/python/testSrc/com/jetbrains/python/Py3CompletionTest.java index 3572442e2bc3..8d32bb6b963c 100644 --- a/python/testSrc/com/jetbrains/python/Py3CompletionTest.java +++ b/python/testSrc/com/jetbrains/python/Py3CompletionTest.java @@ -86,23 +86,21 @@ public class Py3CompletionTest extends PyTestCase { protected void doMultiFileTest(@NotNull List sourceRoots) { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> { - myFixture.copyDirectoryToProject(getTestName(true), ""); - final Module module = myFixture.getModule(); + myFixture.copyDirectoryToProject(getTestName(true), ""); + final Module module = myFixture.getModule(); + for (String root : sourceRoots) { + PsiTestUtil.addSourceRoot(module, myFixture.findFileInTempDir(root)); + } + try { + myFixture.configureByFile("a.py"); + myFixture.completeBasic(); + myFixture.checkResultByFile(getTestName(true) + "/a.after.py"); + } + finally { for (String root : sourceRoots) { - PsiTestUtil.addSourceRoot(module, myFixture.findFileInTempDir(root)); + PsiTestUtil.removeSourceRoot(module, myFixture.findFileInTempDir(root)); } - try { - myFixture.configureByFile("a.py"); - myFixture.completeBasic(); - myFixture.checkResultByFile(getTestName(true) + "/a.after.py"); - } - finally { - for (String root : sourceRoots) { - PsiTestUtil.removeSourceRoot(module, myFixture.findFileInTempDir(root)); - } - } - }); + } } @Nullable @@ -114,20 +112,15 @@ public class Py3CompletionTest extends PyTestCase { // PY-4073 public void testSpecialFunctionAttributesPy3() { - runWithLanguageLevel( - LanguageLevel.PYTHON34, - () -> { - List suggested = doTestByText("def func(): pass; func.func_"); - assertNotNull(suggested); - assertEmpty(suggested); + List suggested = doTestByText("def func(): pass; func.func_"); + assertNotNull(suggested); + assertEmpty(suggested); - suggested = doTestByText("def func(): pass; func.__"); - assertNotNull(suggested); - assertContainsElements(suggested, "__defaults__", "__globals__", "__closure__", - "__code__", "__name__", "__doc__", "__dict__", "__module__"); - assertContainsElements(suggested, "__annotations__", "__kwdefaults__"); - } - ); + suggested = doTestByText("def func(): pass; func.__"); + assertNotNull(suggested); + assertContainsElements(suggested, "__defaults__", "__globals__", "__closure__", + "__code__", "__name__", "__doc__", "__dict__", "__module__"); + assertContainsElements(suggested, "__annotations__", "__kwdefaults__"); } // PY-7375 @@ -173,7 +166,7 @@ public class Py3CompletionTest extends PyTestCase { // PY-15390 public void testMatMul() { - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + doTest(); } // PY-11214 @@ -183,41 +176,31 @@ public class Py3CompletionTest extends PyTestCase { public void testAsync() { PyModuleNameCompletionContributor.ENABLED = false; - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + doTest(); } public void testAwait() { - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + doTest(); } // PY-17828 public void testDunderPrepare() { - runWithLanguageLevel( - LanguageLevel.PYTHON34, - () -> { - final String testName = getTestName(true); - myFixture.configureByFile(testName + ".py"); - myFixture.completeBasicAllCarets(null); - myFixture.checkResultByFile(testName + ".after.py"); - } - ); + final String testName = getTestName(true); + myFixture.configureByFile(testName + ".py"); + myFixture.completeBasicAllCarets(null); + myFixture.checkResultByFile(testName + ".after.py"); } // PY-17828 // TODO: do we need this? @Ignore public void ignore_testDunderPrepareHonourInspectionSettings() { - runWithLanguageLevel( - LanguageLevel.PYTHON34, - () -> { - myFixture.enableInspections(PyMethodParametersInspection.class); + myFixture.enableInspections(PyMethodParametersInspection.class); - final String testName = getTestName(true); - myFixture.configureByFile(testName + ".py"); - myFixture.completeBasicAllCarets(null); - myFixture.checkResultByFile(testName + ".after.py"); - } - ); + final String testName = getTestName(true); + myFixture.configureByFile(testName + ".py"); + myFixture.completeBasicAllCarets(null); + myFixture.checkResultByFile(testName + ".after.py"); } // PY-20279 @@ -279,7 +262,7 @@ public class Py3CompletionTest extends PyTestCase { // PY-21060 public void testGenericTypeInheritor() { - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + doTest(); } // PY-19702 @@ -336,17 +319,17 @@ public class Py3CompletionTest extends PyTestCase { // PY-27398 public void testDataclassPostInit() { - runWithLanguageLevel(LanguageLevel.PYTHON37, this::doMultiFileTest); + doMultiFileTest(); } // PY-27398 public void testDataclassWithInitVarPostInit() { - runWithLanguageLevel(LanguageLevel.PYTHON37, this::doMultiFileTest); + doMultiFileTest(); } // PY-27398 public void testDataclassPostInitNoInit() { - runWithLanguageLevel(LanguageLevel.PYTHON37, this::doMultiFileTest); + doMultiFileTest(); } // PY-26354 @@ -511,15 +494,13 @@ public class Py3CompletionTest extends PyTestCase { } private void doTestVariantTailText(@NotNull String entryFilePath, @NotNull String variantName, @Nullable String tailText) { - runWithLanguageLevel(LanguageLevel.getLatest(), () -> { - myFixture.copyDirectoryToProject(getTestName(true), ""); - myFixture.configureByFile(entryFilePath); - LookupElement[] variants = myFixture.completeBasic(); - assertNotNull(variants); - LookupElement lookupElement = ContainerUtil.find(variants, v -> v.getLookupString().equals(variantName)); - assertNotNull(lookupElement); - assertEquals(tailText, TestLookupElementPresentation.renderElement(lookupElement).getTailText()); - }); + myFixture.copyDirectoryToProject(getTestName(true), ""); + myFixture.configureByFile(entryFilePath); + LookupElement[] variants = myFixture.completeBasic(); + assertNotNull(variants); + LookupElement lookupElement = ContainerUtil.find(variants, v -> v.getLookupString().equals(variantName)); + assertNotNull(lookupElement); + assertEquals(tailText, TestLookupElementPresentation.renderElement(lookupElement).getTailText()); } // PY-46054 diff --git a/python/testSrc/com/jetbrains/python/Py3DeprecationTest.java b/python/testSrc/com/jetbrains/python/Py3DeprecationTest.java index 48b7dbed5baf..fdc8eea7dbf4 100644 --- a/python/testSrc/com/jetbrains/python/Py3DeprecationTest.java +++ b/python/testSrc/com/jetbrains/python/Py3DeprecationTest.java @@ -4,20 +4,14 @@ package com.jetbrains.python; import com.intellij.testFramework.LightProjectDescriptor; import com.jetbrains.python.fixtures.PyTestCase; import com.jetbrains.python.inspections.PyDeprecationInspection; -import com.jetbrains.python.psi.LanguageLevel; import org.jetbrains.annotations.Nullable; public class Py3DeprecationTest extends PyTestCase { public void testAbcDeprecatedAbstracts() { - runWithLanguageLevel( - LanguageLevel.PYTHON34, - () -> { - myFixture.enableInspections(PyDeprecationInspection.class); - myFixture.configureByFile("deprecation/abcDeprecatedAbstracts.py"); - myFixture.checkHighlighting(true, false, false); - } - ); + myFixture.enableInspections(PyDeprecationInspection.class); + myFixture.configureByFile("deprecation/abcDeprecatedAbstracts.py"); + myFixture.checkHighlighting(true, false, false); } @Nullable diff --git a/python/testSrc/com/jetbrains/python/Py3HighlightingTest.java b/python/testSrc/com/jetbrains/python/Py3HighlightingTest.java index e190b1e95b2d..3fa5506d30f9 100644 --- a/python/testSrc/com/jetbrains/python/Py3HighlightingTest.java +++ b/python/testSrc/com/jetbrains/python/Py3HighlightingTest.java @@ -17,7 +17,6 @@ package com.jetbrains.python; import com.intellij.testFramework.LightProjectDescriptor; import com.jetbrains.python.fixtures.PyTestCase; -import com.jetbrains.python.psi.LanguageLevel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,7 +33,7 @@ public class Py3HighlightingTest extends PyTestCase { // PY-20770 public void testNonEmptyReturnInsideAsyncDef() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> doTest(true, false)); + doTest(true, false); } private void doTest(boolean checkWarnings, boolean checkInfos) { diff --git a/python/testSrc/com/jetbrains/python/Py3MethodOverridingInspectionTest.java b/python/testSrc/com/jetbrains/python/Py3MethodOverridingInspectionTest.java index 24e4ebe1be15..5adccd467720 100644 --- a/python/testSrc/com/jetbrains/python/Py3MethodOverridingInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/Py3MethodOverridingInspectionTest.java @@ -19,7 +19,6 @@ import com.intellij.testFramework.LightProjectDescriptor; import com.jetbrains.python.fixtures.PyInspectionTestCase; import com.jetbrains.python.inspections.PyInspection; import com.jetbrains.python.inspections.PyMethodOverridingInspection; -import com.jetbrains.python.psi.LanguageLevel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -32,7 +31,7 @@ public class Py3MethodOverridingInspectionTest extends PyInspectionTestCase { // PY-17828 public void testDunderPrepare() { - runWithLanguageLevel(LanguageLevel.PYTHON34, this::doTest); + doTest(); } @NotNull diff --git a/python/testSrc/com/jetbrains/python/Py3QuickFixTest.java b/python/testSrc/com/jetbrains/python/Py3QuickFixTest.java index db3dd03eb80c..dc3ae87adb35 100644 --- a/python/testSrc/com/jetbrains/python/Py3QuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/Py3QuickFixTest.java @@ -34,55 +34,47 @@ import java.util.List; public class Py3QuickFixTest extends PyTestCase { @Override protected LightProjectDescriptor getProjectDescriptor() { - return PyTestCase.ourPyLatestDescriptor; + return ourPyLatestDescriptor; } // PY-13685 public void testReplacePrintEnd() { - runWithLanguageLevel(LanguageLevel.PYTHON34, - () -> doInspectionTest(PyStatementEffectInspection.class, PyPsiBundle.message("QFIX.statement.effect"), true, true)); + doInspectionTest(PyStatementEffectInspection.class, PyPsiBundle.message("QFIX.statement.effect"), true, true); } // PY-13685 public void testReplacePrintComment() { - runWithLanguageLevel(LanguageLevel.PYTHON34, - () -> doInspectionTest(PyStatementEffectInspection.class, PyPsiBundle.message("QFIX.statement.effect"), true, true)); + doInspectionTest(PyStatementEffectInspection.class, PyPsiBundle.message("QFIX.statement.effect"), true, true); } // PY-13685 public void testReplaceExecComment() { - runWithLanguageLevel(LanguageLevel.PYTHON34, - () -> doInspectionTest(PyStatementEffectInspection.class, PyPsiBundle.message("QFIX.statement.effect"), true, true)); + doInspectionTest(PyStatementEffectInspection.class, PyPsiBundle.message("QFIX.statement.effect"), true, true); } // PY-15867 public void testAddCallSuperKeywordOnlyParamInSuperInit() { - runWithLanguageLevel(LanguageLevel.PYTHON34, - () -> doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true)); + doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true); } // PY-15867 public void testAddCallSuperKeywordOnlyParamInInit() { - runWithLanguageLevel(LanguageLevel.PYTHON34, - () -> doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true)); + doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true); } // PY-15867 public void testAddCallSuperSingleStarParamInSuperInit() { - runWithLanguageLevel(LanguageLevel.PYTHON34, - () -> doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true)); + doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true); } // PY-15867 public void testAddCallSuperSingleStarParamInSuperInitAndVarargInInit() { - runWithLanguageLevel(LanguageLevel.PYTHON34, - () -> doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true)); + doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true); } // PY-11561 public void testAddCallSuperTypeAnnotationsPreserved() { - runWithLanguageLevel(LanguageLevel.PYTHON34, - () -> doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true)); + doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true); } // PY-16036, PY-11561 @@ -92,26 +84,23 @@ public class Py3QuickFixTest extends PyTestCase { // PY-15867 public void testAddCallSuperNoRequiredKeywordOnlyParamAfterSingleStarInSuperInit() { - runWithLanguageLevel(LanguageLevel.PYTHON34, - () -> doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true)); + doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true); } // PY-16421 public void testAddCallSuperSingleStarParamPreserved() { - runWithLanguageLevel(LanguageLevel.PYTHON34, - () -> doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true)); + doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true); } - // PY-15867 + // PY-15867 public void testAddCallSuperRequiredKeywordOnlyParamAfterSingleStarInSuperInitIsMerged() { - runWithLanguageLevel(LanguageLevel.PYTHON34, - () -> doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true)); + doInspectionTest(PyMissingConstructorInspection.class, PyPsiBundle.message("QFIX.add.super"), true, true); } // PY-16428 public void testAddParameterNotAvailableInsideAnnotation() { - runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doInspectionTest(PyUnresolvedReferencesInspection.class, - PyPsiBundle.message("QFIX.unresolved.reference.add.param", "unresolved"), false, false)); + doInspectionTest(PyUnresolvedReferencesInspection.class, + PyPsiBundle.message("QFIX.unresolved.reference.add.param", "unresolved"), false, false); } // PY-8991 diff --git a/python/testSrc/com/jetbrains/python/Py3ResolveTest.java b/python/testSrc/com/jetbrains/python/Py3ResolveTest.java index a2d88c5ec5cd..45e75c61f8f7 100644 --- a/python/testSrc/com/jetbrains/python/Py3ResolveTest.java +++ b/python/testSrc/com/jetbrains/python/Py3ResolveTest.java @@ -19,11 +19,9 @@ import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.testFramework.LightProjectDescriptor; import com.jetbrains.python.fixtures.PyResolveTestCase; -import com.jetbrains.python.fixtures.PyTestCase; import com.jetbrains.python.psi.*; import com.jetbrains.python.psi.impl.PyBuiltinCache; import com.jetbrains.python.psi.impl.PyPsiUtils; -import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher; import com.jetbrains.python.psi.types.TypeEvalContext; import com.jetbrains.python.pyi.PyiUtil; @@ -33,7 +31,7 @@ import com.jetbrains.python.pyi.PyiUtil; public class Py3ResolveTest extends PyResolveTestCase { @Override protected LightProjectDescriptor getProjectDescriptor() { - return PyTestCase.ourPyLatestDescriptor; + return ourPyLatestDescriptor; } @Override @@ -43,25 +41,6 @@ public class Py3ResolveTest extends PyResolveTestCase { return ref.resolve(); } - @Override - protected void setUp() throws Exception { - super.setUp(); - PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), LanguageLevel.PYTHON34); - } - - @Override - protected void tearDown() throws Exception { - try { - PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), null); - } - catch (Throwable e) { - addSuppressedException(e); - } - finally { - super.tearDown(); - } - } - public void testObjectMethods() { // PY-1494 assertResolvesTo(PyFunction.class, "__repr__"); } @@ -366,238 +345,184 @@ public class Py3ResolveTest extends PyResolveTestCase { // PY-20864 public void testTopLevelVariableAnnotationFromTyping() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> assertResolvesTo(PyElement.class, "List")); + assertResolvesTo(PyElement.class, "List"); } // PY-20864 public void testLocalVariableAnnotationWithInnerClass() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> assertResolvesTo(PyClass.class, "MyType")); + assertResolvesTo(PyClass.class, "MyType"); } // PY-22971 public void testOverloadsAndNoImplementationInClass() { // resolve to the first overload - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> { - final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); - final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); + final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); + final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); - PyiUtil - .getOverloads(foo, context) - .forEach( - overload -> { - if (overload != foo) assertTrue(PyPsiUtils.isBefore(foo, overload)); - } - ); - } - ); + PyiUtil + .getOverloads(foo, context) + .forEach( + overload -> { + if (overload != foo) assertTrue(PyPsiUtils.isBefore(foo, overload)); + } + ); } // PY-22971 public void testOverloadsAndImplementationInClass() { // resolve to the implementation - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> { - final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); - final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); - assertFalse(PyiUtil.isOverload(foo, context)); - } - ); + final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); + final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); + assertFalse(PyiUtil.isOverload(foo, context)); } // PY-22971 public void testOverloadsAndImplementationsInClass() { // resolve to the first implementation - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> { - final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); - final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); - assertFalse(PyiUtil.isOverload(foo, context)); + final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); + final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); + assertFalse(PyiUtil.isOverload(foo, context)); - final PyClass pyClass = foo.getContainingClass(); - assertNotNull(pyClass); + final PyClass pyClass = foo.getContainingClass(); + assertNotNull(pyClass); - pyClass.visitMethods( - function -> { - assertTrue(PyiUtil.isOverload(function, context) || function == foo || PyPsiUtils.isBefore(foo, function)); - return true; - }, - false, - context - ); - } + pyClass.visitMethods( + function -> { + assertTrue(PyiUtil.isOverload(function, context) || function == foo || PyPsiUtils.isBefore(foo, function)); + return true; + }, + false, + context ); } // PY-22971 public void testTopLevelOverloadsAndNoImplementation() { // resolve to the last overload - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> { - final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); - final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); + final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); + final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); - PyiUtil - .getOverloads(foo, context) - .forEach( - overload -> { - if (overload != foo) assertTrue(PyPsiUtils.isBefore(overload, foo)); - } - ); - } - ); + PyiUtil + .getOverloads(foo, context) + .forEach( + overload -> { + if (overload != foo) assertTrue(PyPsiUtils.isBefore(overload, foo)); + } + ); } // PY-22971 public void testTopLevelOverloadsAndImplementation() { // resolve to the implementation - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> { - final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); - final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); - assertFalse(PyiUtil.isOverload(foo, context)); - } - ); + final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); + final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); + assertFalse(PyiUtil.isOverload(foo, context)); } // PY-22971 public void testTopLevelOverloadsAndImplementations() { // resolve to the last overload - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> { - final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); - final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); - assertTrue(PyiUtil.isOverload(foo, context)); + final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); + final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); + assertTrue(PyiUtil.isOverload(foo, context)); - ((PyFile)foo.getContainingFile()) - .getTopLevelFunctions() - .forEach( - function -> assertTrue(function == foo || PyPsiUtils.isBefore(function, foo)) - ); - } - ); + ((PyFile)foo.getContainingFile()) + .getTopLevelFunctions() + .forEach( + function -> assertTrue(function == foo || PyPsiUtils.isBefore(function, foo)) + ); } // PY-22971 public void testOverloadsAndNoImplementationInImportedClass() { // resolve to the first overload - myFixture.copyDirectoryToProject("resolve/OverloadsAndNoImplementationInImportedClassDep", "OverloadsAndNoImplementationInImportedClassDep"); - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> { - final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); - final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); + myFixture + .copyDirectoryToProject("resolve/OverloadsAndNoImplementationInImportedClassDep", "OverloadsAndNoImplementationInImportedClassDep"); + final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); + final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); - PyiUtil - .getOverloads(foo, context) - .forEach( - overload -> { - if (overload != foo) assertTrue(PyPsiUtils.isBefore(foo, overload)); - } - ); - } - ); + PyiUtil + .getOverloads(foo, context) + .forEach( + overload -> { + if (overload != foo) assertTrue(PyPsiUtils.isBefore(foo, overload)); + } + ); } // PY-22971 public void testOverloadsAndImplementationInImportedClass() { // resolve to the implementation - myFixture.copyDirectoryToProject("resolve/OverloadsAndImplementationInImportedClassDep", "OverloadsAndImplementationInImportedClassDep"); - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> { - final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); - final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); - assertFalse(PyiUtil.isOverload(foo, context)); - } - ); + myFixture + .copyDirectoryToProject("resolve/OverloadsAndImplementationInImportedClassDep", "OverloadsAndImplementationInImportedClassDep"); + final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); + final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); + assertFalse(PyiUtil.isOverload(foo, context)); } // PY-22971 public void testOverloadsAndImplementationsInImportedClass() { // resolve to the first implementation - myFixture.copyDirectoryToProject("resolve/OverloadsAndImplementationsInImportedClassDep", "OverloadsAndImplementationsInImportedClassDep"); - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> { - final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); - final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); - assertFalse(PyiUtil.isOverload(foo, context)); + myFixture + .copyDirectoryToProject("resolve/OverloadsAndImplementationsInImportedClassDep", "OverloadsAndImplementationsInImportedClassDep"); + final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); + final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); + assertFalse(PyiUtil.isOverload(foo, context)); - final PyClass pyClass = foo.getContainingClass(); - assertNotNull(pyClass); + final PyClass pyClass = foo.getContainingClass(); + assertNotNull(pyClass); - pyClass.visitMethods( - function -> { - assertTrue(PyiUtil.isOverload(function, context) || function == foo || PyPsiUtils.isBefore(foo, function)); - return true; - }, - false, - context - ); - } + pyClass.visitMethods( + function -> { + assertTrue(PyiUtil.isOverload(function, context) || function == foo || PyPsiUtils.isBefore(foo, function)); + return true; + }, + false, + context ); } // PY-22971 public void testOverloadsAndNoImplementationInImportedModule() { // resolve to the last overload - myFixture.copyDirectoryToProject("resolve/OverloadsAndNoImplementationInImportedModuleDep", "OverloadsAndNoImplementationInImportedModuleDep"); - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> { - final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); - final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); + myFixture + .copyDirectoryToProject("resolve/OverloadsAndNoImplementationInImportedModuleDep", "OverloadsAndNoImplementationInImportedModuleDep"); + final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); + final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); - PyiUtil - .getOverloads(foo, context) - .forEach( - overload -> { - if (overload != foo) assertTrue(PyPsiUtils.isBefore(overload, foo)); - } - ); - } - ); + PyiUtil + .getOverloads(foo, context) + .forEach( + overload -> { + if (overload != foo) assertTrue(PyPsiUtils.isBefore(overload, foo)); + } + ); } // PY-22971 public void testOverloadsAndImplementationInImportedModule() { // resolve to the implementation - myFixture.copyDirectoryToProject("resolve/OverloadsAndImplementationInImportedModuleDep", "OverloadsAndImplementationInImportedModuleDep"); - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> { - final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); - final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); - assertFalse(PyiUtil.isOverload(foo, context)); - } - ); + myFixture + .copyDirectoryToProject("resolve/OverloadsAndImplementationInImportedModuleDep", "OverloadsAndImplementationInImportedModuleDep"); + final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); + final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); + assertFalse(PyiUtil.isOverload(foo, context)); } // PY-22971 public void testOverloadsAndImplementationsInImportedModule() { // resolve to the last implementation - myFixture.copyDirectoryToProject("resolve/OverloadsAndImplementationsInImportedModuleDep", "OverloadsAndImplementationsInImportedModuleDep"); - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> { - final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); - final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); - assertFalse(PyiUtil.isOverload(foo, context)); + myFixture + .copyDirectoryToProject("resolve/OverloadsAndImplementationsInImportedModuleDep", "OverloadsAndImplementationsInImportedModuleDep"); + final PyFunction foo = assertResolvesTo(PyFunction.class, "foo"); + final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()); + assertFalse(PyiUtil.isOverload(foo, context)); - ((PyFile)foo.getContainingFile()) - .getTopLevelFunctions() - .forEach( - function -> assertTrue(PyiUtil.isOverload(function, context) || function == foo || PyPsiUtils.isBefore(function, foo)) - ); - } - ); + ((PyFile)foo.getContainingFile()) + .getTopLevelFunctions() + .forEach( + function -> assertTrue(PyiUtil.isOverload(function, context) || function == foo || PyPsiUtils.isBefore(function, foo)) + ); } // PY-30512 @@ -608,57 +533,57 @@ public class Py3ResolveTest extends PyResolveTestCase { // PY-20783 public void testFStringFunctionParameter() { - assertResolvesTo(LanguageLevel.PYTHON36, PyParameter.class, "param"); + assertResolvesTo(PyParameter.class, "param"); } // PY-20783 public void testFStringLocalVariable() { - assertResolvesTo(LanguageLevel.PYTHON36, PyTargetExpression.class, "foo"); + assertResolvesTo(PyTargetExpression.class, "foo"); } // PY-20783 public void testFStringLocalVariableUnresolved() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> assertNull(doResolve())); + assertNull(doResolve()); } // PY-20783 public void testFStringNestedScopes() { - assertResolvesTo(LanguageLevel.PYTHON36, PyTargetExpression.class, "foo"); + assertResolvesTo(PyTargetExpression.class, "foo"); } // PY-21479 public void testFStringComprehensionTarget() { - assertResolvesTo(LanguageLevel.PYTHON36, PyTargetExpression.class, "foo"); + assertResolvesTo(PyTargetExpression.class, "foo"); } // PY-21479 public void testFStringComprehensionSourcePart() { - assertResolvesTo(LanguageLevel.PYTHON36, PyTargetExpression.class, "foo"); + assertResolvesTo(PyTargetExpression.class, "foo"); } // PY-21479 public void testFStringNestedInResultComprehensionSourcePart() { - assertResolvesTo(LanguageLevel.PYTHON36, PyTargetExpression.class, "foo"); + assertResolvesTo(PyTargetExpression.class, "foo"); } // PY-21479 public void testFStringComprehensionConditionPart() { - assertResolvesTo(LanguageLevel.PYTHON36, PyTargetExpression.class, "foo"); + assertResolvesTo(PyTargetExpression.class, "foo"); } // PY-21479 public void testFStringNestedComprehensionSourcePart() { - assertResolvesTo(LanguageLevel.PYTHON36, PyTargetExpression.class, "foo"); + assertResolvesTo(PyTargetExpression.class, "foo"); } // PY-22094 public void testFStringInsideAssertStatement() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> assertResolvesTo(PyParameter.class, "name")); + assertResolvesTo(PyParameter.class, "name"); } // PY-21493 public void testRegexpAndFStringCombined() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> assertResolvesTo(PyTargetExpression.class, "foo")); + assertResolvesTo(PyTargetExpression.class, "foo"); } // PY-30942 diff --git a/python/testSrc/com/jetbrains/python/Py3TypeTest.java b/python/testSrc/com/jetbrains/python/Py3TypeTest.java index f351f33393c8..6119acec896f 100644 --- a/python/testSrc/com/jetbrains/python/Py3TypeTest.java +++ b/python/testSrc/com/jetbrains/python/Py3TypeTest.java @@ -5,7 +5,6 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; import com.intellij.testFramework.LightProjectDescriptor; import com.jetbrains.python.fixtures.PyTestCase; -import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.psi.PyExpression; import com.jetbrains.python.psi.types.TypeEvalContext; import org.jetbrains.annotations.NotNull; @@ -23,7 +22,7 @@ public class Py3TypeTest extends PyTestCase { // PY-6702 public void testYieldFromType() { - runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("Union[str, int, float]", + doTest("Union[str, int, float]", "def subgen():\n" + " for i in [1, 2, 3]:\n" + " yield i\n" + @@ -34,12 +33,12 @@ public class Py3TypeTest extends PyTestCase { " yield 3.14\n" + "\n" + "for expr in gen():\n" + - " pass\n")); + " pass\n"); } // PY-12944 public void testYieldFromReturnType() { - runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("None", + doTest("None", "def a():\n" + " yield 1\n" + " return 'a'\n" + @@ -48,16 +47,16 @@ public class Py3TypeTest extends PyTestCase { "\n" + "def b():\n" + " expr = yield from y\n" + - " return expr\n")); - runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("str", + " return expr\n"); + doTest("str", "def a():\n" + " yield 1\n" + " return 'a'\n" + "\n" + "def b():\n" + " expr = yield from a()\n" + - " return expr\n")); - runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("int", + " return expr\n"); + doTest("int", "def g():\n" + " yield 1\n" + " return 'abc'\n" + @@ -66,12 +65,12 @@ public class Py3TypeTest extends PyTestCase { " x = yield from g()\n" + "\n" + "for expr in f():\n" + - " pass")); + " pass"); } public void testYieldFromHomogeneousTuple() { doTest("str", - "import typing\n"+ + "import typing\n" + "def get_tuple() -> typing.Tuple[str, ...]:\n" + " pass\n" + "def gen()\n" + @@ -132,7 +131,7 @@ public class Py3TypeTest extends PyTestCase { } public void testAwaitAwaitable() { - runWithLanguageLevel(LanguageLevel.PYTHON35, () -> doTest("int", + doTest("int", "class C:\n" + " def __await__(self):\n" + " yield 'foo'\n" + @@ -140,88 +139,88 @@ public class Py3TypeTest extends PyTestCase { "\n" + "async def foo():\n" + " c = C()\n" + - " expr = await c\n")); + " expr = await c\n"); } public void testAsyncDefReturnType() { - runWithLanguageLevel(LanguageLevel.PYTHON35, () -> doTest("Coroutine[Any, Any, int]", + doTest("Coroutine[Any, Any, int]", "async def foo(x):\n" + " await x\n" + " return 0\n" + "\n" + "def bar(y):\n" + - " expr = foo(y)\n")); + " expr = foo(y)\n"); } public void testAwaitCoroutine() { - runWithLanguageLevel(LanguageLevel.PYTHON35, () -> doTest("int", + doTest("int", "async def foo(x):\n" + " await x\n" + " return 0\n" + "\n" + "async def bar(y):\n" + - " expr = await foo(y)\n")); + " expr = await foo(y)\n"); } // Not in PEP 484 as for now, see https://github.com/ambv/typehinting/issues/119 public void testCoroutineReturnTypeAnnotation() { - runWithLanguageLevel(LanguageLevel.PYTHON35, () -> doTest("int", + doTest("int", "async def foo() -> int: ...\n" + "\n" + "async def bar():\n" + - " expr = await foo()\n")); + " expr = await foo()\n"); } // PY-16987 public void testNoTypeInGoogleDocstringParamAnnotation() { - runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("int", "def f(x: int):\n" + - " \"\"\"\n" + - " Args:\n" + - " x: foo\n" + - " \"\"\" \n" + - " expr = x")); + doTest("int", "def f(x: int):\n" + + " \"\"\"\n" + + " Args:\n" + + " x: foo\n" + + " \"\"\" \n" + + " expr = x"); } // PY-16987 public void testUnfilledTypeInGoogleDocstringParamAnnotation() { - runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("int", "def f(x: int):\n" + - " \"\"\"\n" + - " Args:\n" + - " x (): foo\n" + - " \"\"\" \n" + - " expr = x")); + doTest("int", "def f(x: int):\n" + + " \"\"\"\n" + + " Args:\n" + + " x (): foo\n" + + " \"\"\" \n" + + " expr = x"); } // PY-16987 public void testNoTypeInNumpyDocstringParamAnnotation() { - runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("int", "def f(x: int):\n" + - " \"\"\"\n" + - " Parameters\n" + - " ----------\n" + - " x\n" + - " foo\n" + - " \"\"\"\n" + - " expr = x")); + doTest("int", "def f(x: int):\n" + + " \"\"\"\n" + + " Parameters\n" + + " ----------\n" + + " x\n" + + " foo\n" + + " \"\"\"\n" + + " expr = x"); } // PY-17010 public void testAnnotatedReturnTypePrecedesDocstring() { - runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("int", "def func() -> int:\n" + - " \"\"\"\n" + - " Returns:\n" + - " str\n" + - " \"\"\"\n" + - "expr = func()")); + doTest("int", "def func() -> int:\n" + + " \"\"\"\n" + + " Returns:\n" + + " str\n" + + " \"\"\"\n" + + "expr = func()"); } // PY-17010 public void testAnnotatedParamTypePrecedesDocstring() { - runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("int", "def func(x: int):\n" + - " \"\"\"\n" + - " Args:\n" + - " x (str):\n" + - " \"\"\"\n" + - " expr = x")); + doTest("int", "def func(x: int):\n" + + " \"\"\"\n" + + " Args:\n" + + " x (str):\n" + + " \"\"\"\n" + + " expr = x"); } public void testOpenDefault() { @@ -259,141 +258,136 @@ public class Py3TypeTest extends PyTestCase { // PY-1427 public void testBytesLiteral() { - runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("bytes", "expr = b'foo'")); + doTest("bytes", "expr = b'foo'"); } // PY-20770 public void testAsyncGenerator() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> doTest("AsyncGenerator[int, Any]", - "async def asyncgen():\n" + - " yield 42\n" + - "expr = asyncgen()")); + doTest("AsyncGenerator[int, Any]", + "async def asyncgen():\n" + + " yield 42\n" + + "expr = asyncgen()"); } // PY-20770 public void testAsyncGeneratorDunderAiter() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> doTest("AsyncGenerator[int, Any]", - "async def asyncgen():\n" + - " yield 42\n" + - "expr = asyncgen().__aiter__()")); + doTest("AsyncGenerator[int, Any]", + "async def asyncgen():\n" + + " yield 42\n" + + "expr = asyncgen().__aiter__()"); } // PY-20770 public void testAsyncGeneratorDunderAnext() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> doTest("Awaitable[int]", - "async def asyncgen():\n" + - " yield 42\n" + - "expr = asyncgen().__anext__()")); + doTest("Awaitable[int]", + "async def asyncgen():\n" + + " yield 42\n" + + "expr = asyncgen().__anext__()"); } // PY-20770 public void testAsyncGeneratorAwaitOnDunderAnext() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> doTest("int", - "async def asyncgen():\n" + - " yield 42\n" + - "async def asyncusage()\n" + - " expr = await asyncgen().__anext__()")); + doTest("int", + "async def asyncgen():\n" + + " yield 42\n" + + "async def asyncusage()\n" + + " expr = await asyncgen().__anext__()"); } // PY-20770 public void testAsyncGeneratorAsend() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> doTest("Awaitable[int]", - "async def asyncgen():\n" + - " yield 42\n" + - "expr = asyncgen().asend(\"hello\")")); + doTest("Awaitable[int]", + "async def asyncgen():\n" + + " yield 42\n" + + "expr = asyncgen().asend(\"hello\")"); } // PY-20770 public void testAsyncGeneratorAwaitOnAsend() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> doTest("int", - "async def asyncgen():\n" + - " yield 42\n" + - "async def asyncusage():\n" + - " expr = await asyncgen().asend(\"hello\")")); + doTest("int", + "async def asyncgen():\n" + + " yield 42\n" + + "async def asyncusage():\n" + + " expr = await asyncgen().asend(\"hello\")"); } // PY-20770 public void testIteratedAsyncGeneratorElement() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> doTest("int", - "async def asyncgen():\n" + - " yield 10\n" + - "async def run():\n" + - " async for i in asyncgen():\n" + - " expr = i")); + doTest("int", + "async def asyncgen():\n" + + " yield 10\n" + + "async def run():\n" + + " async for i in asyncgen():\n" + + " expr = i"); } // PY-20770 public void testElementInAsyncComprehensions() { - runWithLanguageLevel( - LanguageLevel.PYTHON36, - () -> { - doTest("int", - "async def asyncgen():\n" + - " yield 10\n" + - "async def run():\n" + - " {expr async for expr in asyncgen()}\n"); + doTest("int", + "async def asyncgen():\n" + + " yield 10\n" + + "async def run():\n" + + " {expr async for expr in asyncgen()}\n"); - doTest("int", - "async def asyncgen():\n" + - " yield 10\n" + - "async def run():\n" + - " [expr async for expr in asyncgen()]\n"); + doTest("int", + "async def asyncgen():\n" + + " yield 10\n" + + "async def run():\n" + + " [expr async for expr in asyncgen()]\n"); - doTest("int", - "async def asyncgen():\n" + - " yield 10\n" + - "async def run():\n" + - " {expr: expr ** 2 async for expr in asyncgen()}\n"); + doTest("int", + "async def asyncgen():\n" + + " yield 10\n" + + "async def run():\n" + + " {expr: expr ** 2 async for expr in asyncgen()}\n"); - doTest("int", - "async def asyncgen():\n" + - " yield 10\n" + - "async def run():\n" + - " (expr async for expr in asyncgen())\n"); + doTest("int", + "async def asyncgen():\n" + + " yield 10\n" + + "async def run():\n" + + " (expr async for expr in asyncgen())\n"); - doTest("int", - "async def asyncgen():\n" + - " yield 10\n" + - "async def run():\n" + - " list(expr async for expr in asyncgen())\n"); + doTest("int", + "async def asyncgen():\n" + + " yield 10\n" + + "async def run():\n" + + " list(expr async for expr in asyncgen())\n"); - doTest("int", - "async def asyncgen():\n" + - " yield 10\n" + - "async def run():\n" + - " dataset = {data async for expr in asyncgen()\n" + - " async for data in asyncgen()\n" + - " if check(data)}\n"); + doTest("int", + "async def asyncgen():\n" + + " yield 10\n" + + "async def run():\n" + + " dataset = {data async for expr in asyncgen()\n" + + " async for data in asyncgen()\n" + + " if check(data)}\n"); - doTest("int", - "async def asyncgen():\n" + - " yield 10\n" + - "async def run():\n" + - " dataset = {expr async for line in asyncgen()\n" + - " async for expr in asyncgen()\n" + - " if check(expr)}\n"); - } - ); + doTest("int", + "async def asyncgen():\n" + + " yield 10\n" + + "async def run():\n" + + " dataset = {expr async for line in asyncgen()\n" + + " async for expr in asyncgen()\n" + + " if check(expr)}\n"); } // PY-20770 public void testAwaitInComprehensions() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> doTest("List[int]", - "async def asyncgen():\n" + - " yield 10\n" + - "async def run():\n" + - " expr = [await z for z in [asyncgen().__anext__()]]\n")); + doTest("list[int]", + "async def asyncgen():\n" + + " yield 10\n" + + "async def run():\n" + + " expr = [await z for z in [asyncgen().__anext__()]]\n"); } // PY-20770 public void testAwaitInAsyncComprehensions() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> doTest("List[int]", - "async def asyncgen():\n" + - " yield 10\n" + - "async def asyncgen2():\n" + - " yield asyncgen().__anext__()\n" + - "async def run():\n" + - " expr = [await z async for z in asyncgen2()]\n")); + doTest("list[int]", + "async def asyncgen():\n" + + " yield 10\n" + + "async def asyncgen2():\n" + + " yield asyncgen().__anext__()\n" + + "async def run():\n" + + " expr = [await z async for z in asyncgen2()]\n"); } public void testIsNotNone() { @@ -523,30 +517,30 @@ public class Py3TypeTest extends PyTestCase { // PY-21655 public void testUsageOfFunctionDecoratedWithAsyncioCoroutine() { myFixture.copyDirectoryToProject(TEST_DIRECTORY + getTestName(false), ""); - runWithLanguageLevel(LanguageLevel.PYTHON35, () -> doTest("int", - "import asyncio\n" + - "@asyncio.coroutine\n" + - "def foo():\n" + - " yield from asyncio.sleep(1)\n" + - " return 3\n" + - "async def bar():\n" + - " expr = await foo()\n" + - " return expr")); + doTest("int", + "import asyncio\n" + + "@asyncio.coroutine\n" + + "def foo():\n" + + " yield from asyncio.sleep(1)\n" + + " return 3\n" + + "async def bar():\n" + + " expr = await foo()\n" + + " return expr"); } // PY-21655 public void testUsageOfFunctionDecoratedWithTypesCoroutine() { myFixture.copyDirectoryToProject(TEST_DIRECTORY + getTestName(false), ""); - runWithLanguageLevel(LanguageLevel.PYTHON35, () -> doTest("int", - "import asyncio\n" + - "import types\n" + - "@types.coroutine\n" + - "def foo():\n" + - " yield from asyncio.sleep(1)\n" + - " return 3\n" + - "async def bar():\n" + - " expr = await foo()\n" + - " return expr")); + doTest("int", + "import asyncio\n" + + "import types\n" + + "@types.coroutine\n" + + "def foo():\n" + + " yield from asyncio.sleep(1)\n" + + " return 3\n" + + "async def bar():\n" + + " expr = await foo()\n" + + " return expr"); } // PY-22513 @@ -564,36 +558,27 @@ public class Py3TypeTest extends PyTestCase { // PY-19323 public void testReturnedTypingCallable() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("(...) -> Any", - "from typing import Callable\n" + - "def f() -> Callable:\n" + - " pass\n" + - "expr = f()") - ); + doTest("(...) -> Any", + "from typing import Callable\n" + + "def f() -> Callable:\n" + + " pass\n" + + "expr = f()"); } public void testReturnedTypingCallableWithUnknownParameters() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("(...) -> int", - "from typing import Callable\n" + - "def f() -> Callable[..., int]:\n" + - " pass\n" + - "expr = f()") - ); + doTest("(...) -> int", + "from typing import Callable\n" + + "def f() -> Callable[..., int]:\n" + + " pass\n" + + "expr = f()"); } public void testReturnedTypingCallableWithKnownParameters() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("(int, str) -> int", - "from typing import Callable\n" + - "def f() -> Callable[[int, str], int]:\n" + - " pass\n" + - "expr = f()") - ); + doTest("(int, str) -> int", + "from typing import Callable\n" + + "def f() -> Callable[[int, str], int]:\n" + + " pass\n" + + "expr = f()"); } // PY-24445 @@ -611,159 +596,129 @@ public class Py3TypeTest extends PyTestCase { // PY-24405 public void testAsyncWithType() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("str", - "class AContext:\n" + - " async def __aenter__(self) -> str:\n" + - " pass\n" + - "async def foo():\n" + - " async with AContext() as c:\n" + - " expr = c") - ); + doTest("str", + "class AContext:\n" + + " async def __aenter__(self) -> str:\n" + + " pass\n" + + "async def foo():\n" + + " async with AContext() as c:\n" + + " expr = c"); } // PY-24067 public void testAsyncFunctionReturnTypeInDocstring() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("Coroutine[Any, Any, int]", - "async def f():\n" + - " \"\"\"\n" + - " :rtype: int\n" + - " \"\"\"\n" + - " pass\n" + - "expr = f()") - ); + doTest("Coroutine[Any, Any, int]", + "async def f():\n" + + " \"\"\"\n" + + " :rtype: int\n" + + " \"\"\"\n" + + " pass\n" + + "expr = f()"); } // PY-27518 public void testAsyncFunctionReturnTypeInNumpyDocstring() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("Coroutine[Any, Any, int]", - "async def f():\n" + - " \"\"\"\n" + - " An integer.\n" + - "\n" + - " Returns\n" + - " -------\n" + - " int\n" + - " A number\n" + - " \"\"\"\n" + - " pass\n" + - "expr = f()") - ); + doTest("Coroutine[Any, Any, int]", + "async def f():\n" + + " \"\"\"\n" + + " An integer.\n" + + "\n" + + " Returns\n" + + " -------\n" + + " int\n" + + " A number\n" + + " \"\"\"\n" + + " pass\n" + + "expr = f()"); } // PY-26847 public void testAwaitOnImportedCoroutine() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doMultiFileTest("Any", - "from mycoroutines import mycoroutine\n" + - "\n" + - "async def main():\n" + - " expr = await mycoroutine()") - ); + doMultiFileTest("Any", + "from mycoroutines import mycoroutine\n" + + "\n" + + "async def main():\n" + + " expr = await mycoroutine()"); } // PY-26643 public void testReplaceSelfInCoroutine() { - runWithLanguageLevel( - LanguageLevel.PYTHON36, - () -> doTest("Coroutine[Any, Any, B]", - "class A:\n" + - " async def foo(self):\n" + - " return self\n" + - "class B(A):\n" + - " pass\n" + - "expr = B().foo()") - ); + doTest("Coroutine[Any, Any, B]", + "class A:\n" + + " async def foo(self):\n" + + " return self\n" + + "class B(A):\n" + + " pass\n" + + "expr = B().foo()"); } // PY-4813 public void testParameterTypeInferenceInSubclassFromDocstring() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("int", - "class Base:\n" + - " def test(self, param):\n" + - " \"\"\"\n" + - " :param param:\n" + - " :type param: int\n" + - " \"\"\"\n" + - " pass\n" + - "\n" + - "class Subclass(Base):\n" + - " def test(self, param):\n" + - " expr = param") - ); + doTest("int", + "class Base:\n" + + " def test(self, param):\n" + + " \"\"\"\n" + + " :param param:\n" + + " :type param: int\n" + + " \"\"\"\n" + + " pass\n" + + "\n" + + "class Subclass(Base):\n" + + " def test(self, param):\n" + + " expr = param"); } public void testParameterTypeInferenceInSubclassFromAnnotation() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("int", - "class Base:\n" + - " def test(self, param: int) -> int: pass\n" + - "\n" + - "class Subclass(Base):\n" + - " def test(self, param):\n" + - " expr = param") - ); + doTest("int", + "class Base:\n" + + " def test(self, param: int) -> int: pass\n" + + "\n" + + "class Subclass(Base):\n" + + " def test(self, param):\n" + + " expr = param"); } public void testParameterTypeInferenceInSubclassHierarchyFromAnnotation1() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("int", - "class Base:\n" + - " def test(self, param: int) -> int: pass\n" + - "\n" + - "class Base1(Base):\n" + - " pass\n" + - "\n" + - "class Subclass(Base1):\n" + - " def test(self, param):\n" + - " expr = param") - ); + doTest("int", + "class Base:\n" + + " def test(self, param: int) -> int: pass\n" + + "\n" + + "class Base1(Base):\n" + + " pass\n" + + "\n" + + "class Subclass(Base1):\n" + + " def test(self, param):\n" + + " expr = param"); } public void testParameterTypeInferenceInSubclassHierarchyFromAnnotation2() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("int", - "class Base1:\n" + - " def test(self, param: int) -> int: pass\n" + - "\n" + - "class Base2:\n" + - " def test(self, param: str) -> str: pass\n" + - "\n" + - "class Subclass(Base1, Base2):\n" + - " def test(self, param):\n" + - " expr = param") - ); + doTest("int", + "class Base1:\n" + + " def test(self, param: int) -> int: pass\n" + + "\n" + + "class Base2:\n" + + " def test(self, param: str) -> str: pass\n" + + "\n" + + "class Subclass(Base1, Base2):\n" + + " def test(self, param):\n" + + " expr = param"); } public void testParameterTypeInferenceInSubclassHierarchyFromAnnotation3() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("int", - "class Base1:\n" + - " def test(self, param: int) -> int: pass\n" + - "\n" + - "class Base2:\n" + - " def test(self, param: str) -> str: pass\n" + - "\n" + - "class Base3(Base1):\n" + - " pass\n" + - "\n" + - "class Subclass(Base3, Base2):\n" + - " def test(self, param):\n" + - " expr = param") - ); - } + doTest("int", + "class Base1:\n" + + " def test(self, param: int) -> int: pass\n" + + "\n" + + "class Base2:\n" + + " def test(self, param: str) -> str: pass\n" + + "\n" + + "class Base3(Base1):\n" + + " pass\n" + + "\n" + + "class Subclass(Base3, Base2):\n" + + " def test(self, param):\n" + + " expr = param"); + } public void testParameterTypeInferenceInSubclassHierarchyFromAnnotation4() { /* @@ -772,104 +727,86 @@ public class Py3TypeTest extends PyTestCase { Since annotations are supported in Python 3.5 and above, *classic classes* should not be tested here, but it's NOT the case for docstrings */ - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("int", - "class Base1:\n" + - " def test(self, param: str) -> str: pass\n" + - "\n" + - "class Base2(Base1):\n" + - " def test(self, param: int) -> int: pass\n" + - "\n" + - "class Base3(Base1):\n" + - " pass\n" + - "\n" + - "class Subclass(Base3, Base2):\n" + - " def test(self, param):\n" + - " expr = param") - ); + doTest("int", + "class Base1:\n" + + " def test(self, param: str) -> str: pass\n" + + "\n" + + "class Base2(Base1):\n" + + " def test(self, param: int) -> int: pass\n" + + "\n" + + "class Base3(Base1):\n" + + " pass\n" + + "\n" + + "class Subclass(Base3, Base2):\n" + + " def test(self, param):\n" + + " expr = param"); } public void testParameterTypeInferenceInSubclassHierarchyFromAnnotation5() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("int", - "class Base1:\n" + - " def test(self, param: int) -> int: pass\n" + - "\n" + - "class Base2(Base1):\n" + - " def test(self, param): pass\n" + - "\n" + - "class Subclass(Base2):\n" + - " def test(self, param):\n" + - " expr = param") - ); + doTest("int", + "class Base1:\n" + + " def test(self, param: int) -> int: pass\n" + + "\n" + + "class Base2(Base1):\n" + + " def test(self, param): pass\n" + + "\n" + + "class Subclass(Base2):\n" + + " def test(self, param):\n" + + " expr = param"); } public void testParameterTypeInferenceInOverloadedMethods() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("Any", - "from typing import overload\n" + - "\n" + - "class Base:\n" + - " @overload\n" + - " def test(self, param: int) -> int: pass\n" + - "\n" + - " @overload\n" + - " def test(self, param: str) -> str: pass\n" + - "\n" + - "class Subclass(Base):\n" + - " def test(self, param):\n" + - " expr = param") - ); + doTest("Any", + "from typing import overload\n" + + "\n" + + "class Base:\n" + + " @overload\n" + + " def test(self, param: int) -> int: pass\n" + + "\n" + + " @overload\n" + + " def test(self, param: str) -> str: pass\n" + + "\n" + + "class Subclass(Base):\n" + + " def test(self, param):\n" + + " expr = param"); } public void testParameterTypeInferenceInSubclassHierarchyInStaticMethods() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("int", - "class Base:\n" + - " @staticmethod\n" + - " def test(param: int, param1: int) -> int: pass\n" + - "\n" + - "class Subclass(Base):\n" + - " @staticmethod\n" + - " def test(param, param1):\n" + - " expr = param\n" + - "\n") - ); + doTest("int", + "class Base:\n" + + " @staticmethod\n" + + " def test(param: int, param1: int) -> int: pass\n" + + "\n" + + "class Subclass(Base):\n" + + " @staticmethod\n" + + " def test(param, param1):\n" + + " expr = param\n" + + "\n"); } public void testReturnTypeInferenceInSubclassFromAnnotation() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("int", - "class Base:\n" + - " def test(self) -> int: pass\n" + - "\n" + - "class Subclass(Base):\n" + - " def test(self): pass\n" + - "\n" + - "expr = Subclass().test()") - ); + doTest("int", + "class Base:\n" + + " def test(self) -> int: pass\n" + + "\n" + + "class Subclass(Base):\n" + + " def test(self): pass\n" + + "\n" + + "expr = Subclass().test()"); } public void testReturnTypeInferenceInSubclassHierarchyFromAnnotation() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("int", - "class Base:\n" + - " def test(self) -> int: pass\n" + - "\n" + - "class Base1(Base):\n" + - " pass\n" + - "\n" + - "class Subclass(Base1):\n" + - " def test(self): pass\n" + - "\n" + - "expr = Subclass().test()") - ); + doTest("int", + "class Base:\n" + + " def test(self) -> int: pass\n" + + "\n" + + "class Base1(Base):\n" + + " pass\n" + + "\n" + + "class Subclass(Base1):\n" + + " def test(self): pass\n" + + "\n" + + "expr = Subclass().test()"); } /** @@ -878,21 +815,18 @@ public class Py3TypeTest extends PyTestCase { * See {@code {@link com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider#getReturnTypeFromSupertype}} javadoc. */ public void ignoreTestReturnTypeInferenceInSubclassFromDocstring() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("int", - "class Base:\n" + - " def test(self):" + - " \"\"\"\n" + - " :rtype: int\n" + - " \"\"\"\n" + - " pass\n" + - "\n" + - "class Subclass(Base):\n" + - " def test(self): pass\n" + - "\n" + - "expr = Subclass().test()") - ); + doTest("int", + "class Base:\n" + + " def test(self):" + + " \"\"\"\n" + + " :rtype: int\n" + + " \"\"\"\n" + + " pass\n" + + "\n" + + "class Subclass(Base):\n" + + " def test(self): pass\n" + + "\n" + + "expr = Subclass().test()"); } /** @@ -901,192 +835,158 @@ public class Py3TypeTest extends PyTestCase { * See {@code {@link com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider#getReturnTypeFromSupertype}} javadoc. */ public void ignoreTestReturnTypeInferenceInSubclassHierarchyFromDocstring() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTest("int", - "class Base:\n" + - " def test(self):" + - " \"\"\"\n" + - " :rtype: int\n" + - " \"\"\"\n" + - " pass\n" + - "\n" + - "class Base1(Base):\n" + - " pass\n" + - "\n" + - "class Subclass(Base1):\n" + - " def test(self): pass\n" + - "\n" + - "expr = Subclass().test()") - ); + doTest("int", + "class Base:\n" + + " def test(self):" + + " \"\"\"\n" + + " :rtype: int\n" + + " \"\"\"\n" + + " pass\n" + + "\n" + + "class Base1(Base):\n" + + " pass\n" + + "\n" + + "class Subclass(Base1):\n" + + " def test(self): pass\n" + + "\n" + + "expr = Subclass().test()"); } // PY-27398 public void testDataclassPostInitParameter() { - runWithLanguageLevel( - LanguageLevel.PYTHON37, - () -> doMultiFileTest("int", - "from dataclasses import dataclass, InitVar\n" + - "@dataclass\n" + - "class Foo:\n" + - " i: int\n" + - " j: int\n" + - " d: InitVar[int]\n" + - " def __post_init__(self, d):\n" + - " expr = d") - ); + doMultiFileTest("int", + "from dataclasses import dataclass, InitVar\n" + + "@dataclass\n" + + "class Foo:\n" + + " i: int\n" + + " j: int\n" + + " d: InitVar[int]\n" + + " def __post_init__(self, d):\n" + + " expr = d"); } // PY-27398 public void testDataclassPostInitParameterNoInit() { - runWithLanguageLevel( - LanguageLevel.PYTHON37, - () -> doMultiFileTest("Any", - "from dataclasses import dataclass, InitVar\n" + - "@dataclass(init=False)\n" + - "class Foo:\n" + - " i: int\n" + - " j: int\n" + - " d: InitVar[int]\n" + - " def __post_init__(self, d):\n" + - " expr = d") - ); + doMultiFileTest("Any", + "from dataclasses import dataclass, InitVar\n" + + "@dataclass(init=False)\n" + + "class Foo:\n" + + " i: int\n" + + " j: int\n" + + " d: InitVar[int]\n" + + " def __post_init__(self, d):\n" + + " expr = d"); } // PY-28506 public void testDataclassPostInitInheritedParameter() { - runWithLanguageLevel( - LanguageLevel.PYTHON37, - () -> { - myFixture.copyDirectoryToProject(TEST_DIRECTORY + "DataclassPostInitParameter", ""); + myFixture.copyDirectoryToProject(TEST_DIRECTORY + "DataclassPostInitParameter", ""); - // both are dataclasses with enabled `init` - doTest("int", - "from dataclasses import dataclass, InitVar\n" + - "\n" + - "@dataclass\n" + - "class A:\n" + - " a: InitVar[int]\n" + - "\n" + - "@dataclass\n" + - "class B(A):\n" + - " b: InitVar[str]\n" + - "\n" + - " def __post_init__(self, a, b):\n" + - " expr = a"); - } - ); + // both are dataclasses with enabled `init` + doTest("int", + "from dataclasses import dataclass, InitVar\n" + + "\n" + + "@dataclass\n" + + "class A:\n" + + " a: InitVar[int]\n" + + "\n" + + "@dataclass\n" + + "class B(A):\n" + + " b: InitVar[str]\n" + + "\n" + + " def __post_init__(self, a, b):\n" + + " expr = a"); } // PY-28506 public void testDataclassPostInitInheritedParameter2() { - runWithLanguageLevel( - LanguageLevel.PYTHON37, - () -> { - myFixture.copyDirectoryToProject(TEST_DIRECTORY + "DataclassPostInitParameter", ""); + myFixture.copyDirectoryToProject(TEST_DIRECTORY + "DataclassPostInitParameter", ""); - // both are dataclasses, base with enabled `init` - doTest("Any", - "from dataclasses import dataclass, InitVar\n" + - "\n" + - "@dataclass\n" + - "class A:\n" + - " a: InitVar[int]\n" + - "\n" + - "@dataclass(init=False)\n" + - "class B(A):\n" + - " b: InitVar[str]\n" + - "\n" + - " def __post_init__(self, a, b):\n" + - " expr = a"); - } - ); + // both are dataclasses, base with enabled `init` + doTest("Any", + "from dataclasses import dataclass, InitVar\n" + + "\n" + + "@dataclass\n" + + "class A:\n" + + " a: InitVar[int]\n" + + "\n" + + "@dataclass(init=False)\n" + + "class B(A):\n" + + " b: InitVar[str]\n" + + "\n" + + " def __post_init__(self, a, b):\n" + + " expr = a"); } // PY-28506 public void testDataclassPostInitInheritedParameter3() { - runWithLanguageLevel( - LanguageLevel.PYTHON37, - () -> { - myFixture.copyDirectoryToProject(TEST_DIRECTORY + "DataclassPostInitParameter", ""); + myFixture.copyDirectoryToProject(TEST_DIRECTORY + "DataclassPostInitParameter", ""); - // both are dataclasses, derived with enabled `init` - doTest("int", - "from dataclasses import dataclass, InitVar\n" + - "\n" + - "@dataclass(init=False)\n" + - "class A:\n" + - " a: InitVar[int]\n" + - "\n" + - "@dataclass\n" + - "class B(A):\n" + - " b: InitVar[str]\n" + - "\n" + - " def __post_init__(self, a, b):\n" + - " expr = a"); - } - ); + // both are dataclasses, derived with enabled `init` + doTest("int", + "from dataclasses import dataclass, InitVar\n" + + "\n" + + "@dataclass(init=False)\n" + + "class A:\n" + + " a: InitVar[int]\n" + + "\n" + + "@dataclass\n" + + "class B(A):\n" + + " b: InitVar[str]\n" + + "\n" + + " def __post_init__(self, a, b):\n" + + " expr = a"); } // PY-28506 public void testDataclassPostInitInheritedParameter4() { - runWithLanguageLevel( - LanguageLevel.PYTHON37, - () -> { - myFixture.copyDirectoryToProject(TEST_DIRECTORY + "DataclassPostInitParameter", ""); + myFixture.copyDirectoryToProject(TEST_DIRECTORY + "DataclassPostInitParameter", ""); - // both are dataclasses with disabled `init` - doTest("Any", - "from dataclasses import dataclass, InitVar\n" + - "\n" + - "@dataclass(init=False)\n" + - "class A:\n" + - " a: InitVar[int]\n" + - "\n" + - "@dataclass(init=False)\n" + - "class B(A):\n" + - " b: InitVar[str]\n" + - "\n" + - " def __post_init__(self, a, b):\n" + - " expr = a"); - } - ); + // both are dataclasses with disabled `init` + doTest("Any", + "from dataclasses import dataclass, InitVar\n" + + "\n" + + "@dataclass(init=False)\n" + + "class A:\n" + + " a: InitVar[int]\n" + + "\n" + + "@dataclass(init=False)\n" + + "class B(A):\n" + + " b: InitVar[str]\n" + + "\n" + + " def __post_init__(self, a, b):\n" + + " expr = a"); } // PY-28506 public void testMixedDataclassPostInitInheritedParameter() { - runWithLanguageLevel( - LanguageLevel.PYTHON37, - () -> { - myFixture.copyDirectoryToProject(TEST_DIRECTORY + "DataclassPostInitParameter", ""); + myFixture.copyDirectoryToProject(TEST_DIRECTORY + "DataclassPostInitParameter", ""); - doTest("Any", - "from dataclasses import dataclass, InitVar\n" + - "\n" + - "class A:\n" + - " a: InitVar[int]\n" + - "\n" + - "@dataclass\n" + - "class B(A):\n" + - " b: InitVar[str]\n" + - "\n" + - " def __post_init__(self, a, b):\n" + - " expr = a"); + doTest("Any", + "from dataclasses import dataclass, InitVar\n" + + "\n" + + "class A:\n" + + " a: InitVar[int]\n" + + "\n" + + "@dataclass\n" + + "class B(A):\n" + + " b: InitVar[str]\n" + + "\n" + + " def __post_init__(self, a, b):\n" + + " expr = a"); - doTest("Any", - "from dataclasses import dataclass, InitVar\n" + - "\n" + - "@dataclass\n" + - "class A:\n" + - " a: InitVar[int]\n" + - "\n" + - "class B(A):\n" + - " b: InitVar[str]\n" + - "\n" + - " def __post_init__(self, a, b):\n" + - " expr = a"); - } - ); + doTest("Any", + "from dataclasses import dataclass, InitVar\n" + + "\n" + + "@dataclass\n" + + "class A:\n" + + " a: InitVar[int]\n" + + "\n" + + "class B(A):\n" + + " b: InitVar[str]\n" + + "\n" + + " def __post_init__(self, a, b):\n" + + " expr = a"); } // PY-27783 @@ -1139,8 +1039,8 @@ public class Py3TypeTest extends PyTestCase { // PY-29665 public void testRawBytesLiteral() { - doTest("bytes", "expr = rb'raw bytes'"); - doTest("bytes", "expr = br'raw bytes'"); + doTest("bytes", "expr = rb'raw bytes'"); + doTest("bytes", "expr = br'raw bytes'"); } public void testFStringLiteralType() { diff --git a/python/testSrc/com/jetbrains/python/PyTypingTest.java b/python/testSrc/com/jetbrains/python/PyTypingTest.java index fc59e3c51fe4..d1fc344f50bd 100644 --- a/python/testSrc/com/jetbrains/python/PyTypingTest.java +++ b/python/testSrc/com/jetbrains/python/PyTypingTest.java @@ -23,7 +23,6 @@ import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.testFramework.LightProjectDescriptor; import com.jetbrains.python.fixtures.PyTestCase; -import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.psi.PyExpression; import com.jetbrains.python.psi.types.TypeEvalContext; import org.jetbrains.annotations.NotNull; @@ -43,25 +42,6 @@ public class PyTypingTest extends PyTestCase { return ourPyLatestDescriptor; } - @Override - public void setUp() throws Exception { - super.setUp(); - setLanguageLevel(LanguageLevel.PYTHON34); - } - - @Override - public void tearDown() throws Exception { - try { - setLanguageLevel(null); - } - catch (Throwable e) { - addSuppressedException(e); - } - finally { - super.tearDown(); - } - } - public void testClassType() { doTest("Foo", "class Foo:" + @@ -80,7 +60,6 @@ public class PyTypingTest extends PyTestCase { " pass\n" + "\n" + "expr = f()\n"); - } public void testNoneType() { @@ -113,7 +92,7 @@ public class PyTypingTest extends PyTestCase { } public void testBuiltinListWithParameter() { - doTest("List[int]", + doTest("list[int]", "from typing import List\n" + "\n" + "def f(expr: List[int]):\n" + @@ -121,7 +100,7 @@ public class PyTypingTest extends PyTestCase { } public void testBuiltinDictWithParameters() { - doTest("Dict[str, int]", + doTest("dict[str, int]", "from typing import Dict\n" + "\n" + "def f(expr: Dict[str, int]):\n" + @@ -137,7 +116,7 @@ public class PyTypingTest extends PyTestCase { } public void testBuiltinTupleWithParameters() { - doTest("Tuple[int, str]", + doTest("tuple[int, str]", "from typing import Tuple\n" + "\n" + "def f(expr: Tuple[int, str]):\n" + @@ -321,7 +300,7 @@ public class PyTypingTest extends PyTestCase { } public void testMultiAssignmentComment() { - doTest("Tuple[int, str]", + doTest("tuple[int, str]", "def foo(x):\n" + " c1, c2 = x # type: int, str\n" + " expr = c1, c2\n"); @@ -329,7 +308,7 @@ public class PyTypingTest extends PyTestCase { // PY-19220 public void testMultiLineAssignmentComment() { - doTest("List[str]", + doTest("list[str]", "from typing import List\n" + "\n" + "expr = [\n" + @@ -530,17 +509,17 @@ public class PyTypingTest extends PyTestCase { public void testGenericField() { doTest("str", "from typing import TypeVar, Generic\n" + - "\n" + - "T = TypeVar('T', covariant=True)\n" + - "\n" + - "class C(Generic[T]):\n" + - " def __init__(self, foo: T):\n" + - " self.foo = foo\n" + - "\n" + - "def f() -> C[str]:\n" + - " return C('test')\n" + - "\n" + - "x = f()\n" + + "\n" + + "T = TypeVar('T', covariant=True)\n" + + "\n" + + "class C(Generic[T]):\n" + + " def __init__(self, foo: T):\n" + + " self.foo = foo\n" + + "\n" + + "def f() -> C[str]:\n" + + " return C('test')\n" + + "\n" + + "x = f()\n" + "expr = x.foo\n"); } @@ -558,7 +537,7 @@ public class PyTypingTest extends PyTestCase { // PY-18254 public void testFunctionTypeComment() { - doTest("(x: int, args: Tuple[float, ...], kwargs: Dict[str, str]) -> List[bool]", + doTest("(x: int, args: tuple[float, ...], kwargs: dict[str, str]) -> list[bool]", "from typing import List\n" + "\n" + "def f(x, *args, **kwargs):\n" + @@ -576,7 +555,6 @@ public class PyTypingTest extends PyTestCase { " def m(some_int, some_bool, some_str):\n" + " # type: (int, bool, str) -> bool\n" + " expr = some_int"); - } // PY-18726 @@ -615,7 +593,6 @@ public class PyTypingTest extends PyTestCase { "def f(cb):\n" + " # type: (Callable[Tuple[bool, str], int]) -> None\n" + " expr = cb"); - } // PY-18726 @@ -626,22 +603,21 @@ public class PyTypingTest extends PyTestCase { "def f(cb):\n" + " # type: (Callable[[bool, int], [int]]) -> None\n" + " expr = cb"); - } // PY-18598 public void testFunctionTypeCommentEllipsisParameters() { - doTest("(x: Any, y: Any, z: Any) -> int", - "def f(x, y=42, z='foo'):\n" + - " # type: (...) -> int \n" + - " pass\n" + - "\n" + - "expr = f"); + doTest("(x: Any, y: Any, z: Any) -> int", + "def f(x, y=42, z='foo'):\n" + + " # type: (...) -> int \n" + + " pass\n" + + "\n" + + "expr = f"); } // PY-20421 public void testFunctionTypeCommentSingleElementTuple() { - doTest("Tuple[int]", + doTest("tuple[int]", "from typing import Tuple\n" + "\n" + "def f():\n" + @@ -653,7 +629,7 @@ public class PyTypingTest extends PyTestCase { // PY-18762 public void testHomogeneousTuple() { - doTest("Tuple[int, ...]", + doTest("tuple[int, ...]", "from typing import Tuple\n" + "\n" + "def f(xs: Tuple[int, ...]):\n" + @@ -682,7 +658,7 @@ public class PyTypingTest extends PyTestCase { // PY-18762 public void testHomogeneousTupleMultiplication() { - doTest("Tuple[int, ...]", + doTest("tuple[int, ...]", "from typing import Tuple\n" + "\n" + "xs = unknown() # type: Tuple[int, ...]\n" + @@ -691,7 +667,7 @@ public class PyTypingTest extends PyTestCase { // PY-18762 public void testFunctionTypeCommentHomogeneousTuple() { - doTest("Tuple[int, ...]", + doTest("tuple[int, ...]", "from typing import Tuple\n" + "\n" + "def f(xs):\n" + @@ -732,7 +708,7 @@ public class PyTypingTest extends PyTestCase { // PY-18386 public void testRecursiveType2() { - doTest("Dict[str, Union[Union[str, int, float], Any]]", + doTest("dict[str, Union[Union[str, int, float], Any]]", "from typing import Dict, Union\n" + "\n" + "JsonDict = Dict[str, Union[str, int, float, 'JsonDict']]\n" + @@ -773,7 +749,7 @@ public class PyTypingTest extends PyTestCase { // PY-19858 public void testGetSublistBySlice() { - doTest("List[list]", + doTest("list[list]", "from typing import List\n" + "\n" + "def foo(x: List[List]):\n" + @@ -782,7 +758,7 @@ public class PyTypingTest extends PyTestCase { // PY-19858 public void testGetSublistByIndirectSlice() { - doTest("List[list]", + doTest("list[list]", "from typing import List\n" + "\n" + "def foo(x: List[List]):\n" + @@ -792,7 +768,7 @@ public class PyTypingTest extends PyTestCase { // PY-19858 public void testGetListItemByUnknown() { - doTest("Union[list, List[list]]", + doTest("Union[list, list[list]]", "from typing import List\n" + "\n" + "def foo(x: List[List]):\n" + @@ -913,7 +889,7 @@ public class PyTypingTest extends PyTestCase { } public void testIllegalAnnotationTargets() { - doTest("Tuple[Any, int, Any, Any]", + doTest("tuple[Any, int, Any, Any]", "(w, _): Tuple[int, Any]\n" + "((x)): int\n" + "y: bool = z = undefined()\n" + @@ -922,28 +898,28 @@ public class PyTypingTest extends PyTestCase { // PY-19723 public void testAnnotatedPositionalArgs() { - doTest("Tuple[str, ...]", + doTest("tuple[str, ...]", "def foo(*args: str):\n" + " expr = args\n"); } // PY-19723 public void testAnnotatedKeywordArgs() { - doTest("Dict[str, int]", + doTest("dict[str, int]", "def foo(**kwargs: int):\n" + " expr = kwargs\n"); } // PY-19723 public void testTypeCommentedPositionalArgs() { - doTest("Tuple[str, ...]", + doTest("tuple[str, ...]", "def foo(*args # type: str\n):\n" + " expr = args\n"); } // PY-19723 public void testTypeCommentedKeywordArgs() { - doTest("Dict[str, int]", + doTest("dict[str, int]", "def foo(**kwargs # type: int\n):\n" + " expr = kwargs\n"); } @@ -965,32 +941,26 @@ public class PyTypingTest extends PyTestCase { } public void testAsyncGeneratorAnnotation() { - runWithLanguageLevel( - LanguageLevel.PYTHON36, - () -> doTest("AsyncGenerator[int, str]", - "from typing import AsyncGenerator\n" + - "\n" + - "async def g() -> AsyncGenerator[int, str]:\n" + - " s = (yield 42)\n" + - " \n" + - "expr = g()") - ); + doTest("AsyncGenerator[int, str]", + "from typing import AsyncGenerator\n" + + "\n" + + "async def g() -> AsyncGenerator[int, str]:\n" + + " s = (yield 42)\n" + + " \n" + + "expr = g()"); } public void testCoroutineReturnsGenerator() { - runWithLanguageLevel( - LanguageLevel.PYTHON36, - () -> doTest("Coroutine[Any, Any, Generator[int, Any, Any]]", - "from typing import Generator\n" + - "\n" + - "async def coroutine() -> Generator[int, Any, Any]:\n" + - " def gen():\n" + - " yield 42\n" + - " \n" + - " return gen()\n" + - " \n" + - "expr = coroutine()") - ); + doTest("Coroutine[Any, Any, Generator[int, Any, Any]]", + "from typing import Generator\n" + + "\n" + + "async def coroutine() -> Generator[int, Any, Any]:\n" + + " def gen():\n" + + " yield 42\n" + + " \n" + + " return gen()\n" + + " \n" + + "expr = coroutine()"); } public void testGenericRenamedParameter() { @@ -1080,7 +1050,7 @@ public class PyTypingTest extends PyTestCase { // PY-20057 public void testIllegalTypingTypeFormat() { - doTest("Tuple[Any, Any, Any]", + doTest("tuple[Any, Any, Any]", "from typing import Type, Tuple\n" + "\n" + "def f(x: Tuple[Type[42], Type[], Type[unresolved]]):\n" + @@ -1121,7 +1091,7 @@ public class PyTypingTest extends PyTestCase { } public void testGenericUserFunctionWithManyParamsAndNestedCall() { - doTest("Tuple[bool, int, str]", + doTest("tuple[bool, int, str]", "from typing import TypeVar\n" + "\n" + "T = TypeVar('T')\n" + diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3AbstractClassInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3AbstractClassInspectionTest.java index 07a8b92c3c42..7b2e61c90fea 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3AbstractClassInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3AbstractClassInspectionTest.java @@ -3,7 +3,6 @@ package com.jetbrains.python.inspections; import com.intellij.testFramework.LightProjectDescriptor; import com.jetbrains.python.fixtures.PyInspectionTestCase; -import com.jetbrains.python.psi.LanguageLevel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,7 +10,7 @@ public class Py3AbstractClassInspectionTest extends PyInspectionTestCase { // PY-30789 public void testHiddenForAbstractSubclassWithABCSuperclass() { - runWithLanguageLevel(LanguageLevel.PYTHON34, this::doMultiFileTest); + doMultiFileTest(); } @Nullable diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3StringFormatInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3StringFormatInspectionTest.java index ad93b7046fe4..27269dba80e2 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3StringFormatInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3StringFormatInspectionTest.java @@ -17,7 +17,6 @@ package com.jetbrains.python.inspections; import com.intellij.testFramework.LightProjectDescriptor; import com.jetbrains.python.fixtures.PyInspectionTestCase; -import com.jetbrains.python.psi.LanguageLevel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -35,48 +34,48 @@ public class Py3StringFormatInspectionTest extends PyInspectionTestCase { // PY-16938 public void testByteString() { - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + doTest(); } public void testIndexElementWithPackedReferenceExpr() { - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + doTest(); } public void testPackedDictLiteralInsideDictLiteral() { - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + doTest(); } public void testPackedDictCallInsideDictLiteral() { - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + doTest(); } public void testPackedListInsideList() { - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + doTest(); } public void testPackedTupleInsideList() { - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + doTest(); } public void testPackedTupleInsideTuple() { - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + doTest(); } public void testPackedListInsideTuple() { - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + doTest(); } - public void testPackedRefInsideList() { - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + public void testPackedRefInsideList() { + doTest(); } - public void testPackedRefInsideTuple() { - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + public void testPackedRefInsideTuple() { + doTest(); } // PY-20599 public void testPy3kAsciiFormatSpecifier() { - runWithLanguageLevel(LanguageLevel.PYTHON35, () -> doTest()); + doTest(); } @NotNull diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3TypeCheckerInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3TypeCheckerInspectionTest.java index 31c29953634a..cd3aa5d826d0 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3TypeCheckerInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3TypeCheckerInspectionTest.java @@ -3,7 +3,6 @@ package com.jetbrains.python.inspections; import com.intellij.testFramework.LightProjectDescriptor; import com.jetbrains.python.fixtures.PyInspectionTestCase; -import com.jetbrains.python.psi.LanguageLevel; import org.jetbrains.annotations.NotNull; /** @@ -238,17 +237,17 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase { // PY-21302 public void testInitializingNewType() { - runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest); + doTest(); } // PY-21302 public void testNewTypeAsParameter() { - runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest); + doTest(); } // PY-21302 public void testNewTypeInheritance() { - runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest); + doTest(); } // PY-24287 @@ -266,12 +265,12 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase { // PY-24194 // PY-24789 public void testTypingSupports() { - runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); + doTest(); } // PY-25994 public void testUnresolvedReceiverGeneric() { - runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest); + doTest(); } public void testMatchingOpenFunctionCallTypesPy3() { @@ -279,17 +278,17 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase { } public void testChainedComparisonsGenericMatching() { - runWithLanguageLevel(LanguageLevel.PYTHON36, this::doTest); + doTest(); } // PY-27398 public void testInitializingDataclass() { - runWithLanguageLevel(LanguageLevel.PYTHON37, () -> super.doMultiFileTest()); + doMultiFileTest(); } // PY-28442 public void testDataclassClsCallType() { - runWithLanguageLevel(LanguageLevel.PYTHON37, () -> super.doMultiFileTest()); + doMultiFileTest(); } // PY-26354 @@ -328,7 +327,7 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase { // PY-28957 public void testDataclassesReplace() { - runWithLanguageLevel(LanguageLevel.PYTHON37, () -> super.doMultiFileTest()); + doMultiFileTest(); } // PY-28127 PY-31424 @@ -368,33 +367,30 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase { // PY-35235 public void testTypingLiteralStrings() { - runWithLanguageLevel( - LanguageLevel.PYTHON36, - () -> doTestByText("from typing_extensions import Literal\n" + - "\n" + - "a: Literal[\"abc\"] = undefined\n" + - "b: Literal[b\"abc\"] = undefined\n" + - "\n" + - "def foo1(p1: Literal[\"abc\"]):\n" + - " pass\n" + - "foo1(a)\n" + - "foo1(b)\n" + - "\n" + - "def foo2(p1: Literal[b\"abc\"]):\n" + - " pass\n" + - "foo2(a)\n" + - "foo2(b)\n" + - "\n" + - "def foo3(p1: str):\n" + - " pass\n" + - "foo3(a)\n" + - "foo3(b)\n" + - "\n" + - "def foo4(p1: bytes):\n" + - " pass\n" + - "foo4(a)\n" + - "foo4(b)\n") - ); + doTestByText("from typing_extensions import Literal\n" + + "\n" + + "a: Literal[\"abc\"] = undefined\n" + + "b: Literal[b\"abc\"] = undefined\n" + + "\n" + + "def foo1(p1: Literal[\"abc\"]):\n" + + " pass\n" + + "foo1(a)\n" + + "foo1(b)\n" + + "\n" + + "def foo2(p1: Literal[b\"abc\"]):\n" + + " pass\n" + + "foo2(a)\n" + + "foo2(b)\n" + + "\n" + + "def foo3(p1: str):\n" + + " pass\n" + + "foo3(a)\n" + + "foo3(b)\n" + + "\n" + + "def foo4(p1: bytes):\n" + + " pass\n" + + "foo4(a)\n" + + "foo4(b)\n"); } // PY-42418 diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java index 05f793672bb5..920eaf49fd02 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java @@ -23,7 +23,6 @@ import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.PsiTestUtil; import com.jetbrains.python.fixtures.PyInspectionTestCase; import com.jetbrains.python.inspections.unresolvedReference.PyUnresolvedReferencesInspection; -import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.psi.PyClass; import com.jetbrains.python.psi.PyFile; import com.jetbrains.python.psi.stubs.PyClassNameIndex; @@ -56,36 +55,24 @@ public class Py3UnresolvedReferencesInspectionTest extends PyInspectionTestCase return TEST_DIRECTORY; } - @Override - protected void doTest() { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> super.doTest()); - } - - @Override - protected void doMultiFileTest(@NotNull final String filename) { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> super.doMultiFileTest(filename)); - } - protected void doMultiFileTest(@NotNull String filename, @NotNull List sourceRoots) { - runWithLanguageLevel(LanguageLevel.PYTHON36, () -> { - myFixture.copyDirectoryToProject(getTestDirectoryPath(), ""); - final Module module = myFixture.getModule(); + myFixture.copyDirectoryToProject(getTestDirectoryPath(), ""); + final Module module = myFixture.getModule(); + for (String root : sourceRoots) { + PsiTestUtil.addSourceRoot(module, myFixture.findFileInTempDir(root)); + } + try { + final PsiFile currentFile = myFixture.configureFromTempProjectFile(filename); + myFixture.enableInspections(getInspectionClass()); + myFixture.checkHighlighting(isWarning(), isInfo(), isWeakWarning()); + assertProjectFilesNotParsed(currentFile); + assertSdkRootsNotParsed(currentFile); + } + finally { for (String root : sourceRoots) { - PsiTestUtil.addSourceRoot(module, myFixture.findFileInTempDir(root)); + PsiTestUtil.removeSourceRoot(module, myFixture.findFileInTempDir(root)); } - try { - final PsiFile currentFile = myFixture.configureFromTempProjectFile(filename); - myFixture.enableInspections(getInspectionClass()); - myFixture.checkHighlighting(isWarning(), isInfo(), isWeakWarning()); - assertProjectFilesNotParsed(currentFile); - assertSdkRootsNotParsed(currentFile); - } - finally { - for (String root : sourceRoots) { - PsiTestUtil.removeSourceRoot(module, myFixture.findFileInTempDir(root)); - } - } - }); + } } public void testNamedTuple() { diff --git a/python/testSrc/com/jetbrains/python/inspections/PyAsyncCallInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyAsyncCallInspectionTest.java index ace137a4d7b6..aeea96c5e886 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyAsyncCallInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyAsyncCallInspectionTest.java @@ -3,7 +3,6 @@ package com.jetbrains.python.inspections; import com.intellij.testFramework.LightProjectDescriptor; import com.jetbrains.python.fixtures.PyInspectionTestCase; -import com.jetbrains.python.psi.LanguageLevel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -47,21 +46,7 @@ public class PyAsyncCallInspectionTest extends PyInspectionTestCase { // PY-31598 public void testScheduleTask37() { - doMultiFileTest37("a.py"); - } - - @Override - protected void doMultiFileTest(@NotNull String filename) { - runWithLanguageLevel(LanguageLevel.PYTHON35, () -> super.doMultiFileTest(filename)); - } - - protected void doMultiFileTest37(@NotNull String filename) { - runWithLanguageLevel(LanguageLevel.PYTHON37, () -> super.doMultiFileTest(filename)); - } - - @Override - protected void doTest() { - runWithLanguageLevel(LanguageLevel.PYTHON35, () -> super.doTest()); + doMultiFileTest("a.py"); } @NotNull diff --git a/python/testSrc/com/jetbrains/python/inspections/PyTypeHintsInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyTypeHintsInspectionTest.java index cc26c94f2e6a..96c9e6c0b0e2 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyTypeHintsInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyTypeHintsInspectionTest.java @@ -18,14 +18,11 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase { // PY-28243 public void testTypeVarPlacement() { - runWithLanguageLevel( - LanguageLevel.PYTHON36, - () -> doTestByText("from typing import List, TypeVar\n" + - "\n" + - "T0 = TypeVar('T0')\n" + - "a: List[T0]\n" + - "b: List[TypeVar('T1')]") - ); + doTestByText("from typing import List, TypeVar\n" + + "\n" + + "T0 = TypeVar('T0')\n" + + "a: List[T0]\n" + + "b: List[TypeVar('T1')]"); } // PY-28243 @@ -524,25 +521,22 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase { // PY-31788 public void testInstanceAndClassChecksOnGenericParameter() { - runWithLanguageLevel( - LanguageLevel.PYTHON35, - () -> doTestByText("from typing import List, Type, TypeVar\n" + - "\n" + - "T = TypeVar(\"T\")\n" + - "\n" + - "class A:\n" + - " pass\n" + - "\n" + - "def foo(p1: T, p2: Type[T], p3: List[T]):\n" + - " assert isinstance(A(), p1)\n" + - " assert issubclass(A, p1)\n" + - "\n" + - " assert isinstance(A(), p2)\n" + - " assert issubclass(A, p2)\n" + - "\n" + - " assert isinstance(A(), p3)\n" + - " assert issubclass(A, p3)") - ); + doTestByText("from typing import List, Type, TypeVar\n" + + "\n" + + "T = TypeVar(\"T\")\n" + + "\n" + + "class A:\n" + + " pass\n" + + "\n" + + "def foo(p1: T, p2: Type[T], p3: List[T]):\n" + + " assert isinstance(A(), p1)\n" + + " assert issubclass(A, p1)\n" + + "\n" + + " assert isinstance(A(), p2)\n" + + " assert issubclass(A, p2)\n" + + "\n" + + " assert isinstance(A(), p3)\n" + + " assert issubclass(A, p3)"); } // PY-16853 @@ -646,22 +640,19 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase { // PY-20530 public void testSelf() { - runWithLanguageLevel( - LanguageLevel.PYTHON36, - () -> doTestByText("class A:\n" + - " def method(self, i: int):\n" + - " v1: self.B\n" + - " v2 = None # type: self.B\n" + - " print(self.B)\n" + - "\n" + - " class B:\n" + - " pass\n" + - "\n" + - "class self:\n" + - " pass\n" + - "\n" + - "v: self") - ); + doTestByText("class A:\n" + + " def method(self, i: int):\n" + + " v1: self.B\n" + + " v2 = None # type: self.B\n" + + " print(self.B)\n" + + "\n" + + " class B:\n" + + " pass\n" + + "\n" + + "class self:\n" + + " pass\n" + + "\n" + + "v: self"); } // PY-20530 @@ -677,27 +668,24 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase { // PY-20530 public void testAnnotationAndTypeComment() { - runWithLanguageLevel( - LanguageLevel.PYTHON36, - () -> doTestByText( - "a: int = None # type: int\n" + - "\n" + - "def foo(a: int # type: int\n" + - " ,):\n" + - " pass\n" + - "\n" + - "def bar(a: int) -> int:\n" + - " # type: (int) -> int\n" + - " pass\n" + - " \n" + - "def baz1(a: int):\n" + - " # type: (int) -> int\n" + - " pass\n" + - " \n" + - "def baz2(a) -> int:\n" + - " # type: (int) -> int\n" + - " pass" - ) + doTestByText( + "a: int = None # type: int\n" + + "\n" + + "def foo(a: int # type: int\n" + + " ,):\n" + + " pass\n" + + "\n" + + "def bar(a: int) -> int:\n" + + " # type: (int) -> int\n" + + " pass\n" + + " \n" + + "def baz1(a: int):\n" + + " # type: (int) -> int\n" + + " pass\n" + + " \n" + + "def baz2(a) -> int:\n" + + " # type: (int) -> int\n" + + " pass" ); } @@ -856,92 +844,74 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase { // PY-20530 public void testTypingMemberParameters() { - runWithLanguageLevel( - LanguageLevel.PYTHON36, - () -> doTestByText( - "from typing import Callable, List\n" + - "\n" + - "foo1: Callable[[int], [int]] = None\n" + - "foo2: Callable[[int], [int, str]] = None\n" + - "foo3: List[[int]]\n" + - "foo4: List[[int, str]]\n" + - "\n" + - "l1 = [int]\n" + - "l2 = [int, str]\n" + - "\n" + - "foo5: Callable[[int], l1] = None\n" + - "foo6: Callable[[int], l2] = None\n" + - "foo7: List[l1]\n" + - "foo8: List[l2]" - ) + doTestByText( + "from typing import Callable, List\n" + + "\n" + + "foo1: Callable[[int], [int]] = None\n" + + "foo2: Callable[[int], [int, str]] = None\n" + + "foo3: List[[int]]\n" + + "foo4: List[[int, str]]\n" + + "\n" + + "l1 = [int]\n" + + "l2 = [int, str]\n" + + "\n" + + "foo5: Callable[[int], l1] = None\n" + + "foo6: Callable[[int], l2] = None\n" + + "foo7: List[l1]\n" + + "foo8: List[l2]" ); } // PY-32530 public void testAnnotationAndIgnoreComment() { - runWithLanguageLevel( - LanguageLevel.PYTHON36, - () -> doTestByText("def foo(a: str): # type: ignore\n" + - " pass\n" + - "def bar(a: Unknown): # type: ignore[no-untyped-def, name-defined]\n" + - " pass") - ); + doTestByText("def foo(a: str): # type: ignore\n" + + " pass\n" + + "def bar(a: Unknown): # type: ignore[no-untyped-def, name-defined]\n" + + " pass"); } public void testAnnotatingNonSelfAttribute() { - runWithLanguageLevel( - LanguageLevel.PYTHON36, - () -> doTestByText("class A:\n" + - " def method(self, b):\n" + - " b.a: int = 1\n" + - "\n" + - "class B:\n" + - " pass\n" + - "\n" + - "B.a: str = \"2\"\n" + - "\n" + - "def func(a):\n" + - " a.xxx: str = \"2\"") - ); + doTestByText("class A:\n" + + " def method(self, b):\n" + + " b.a: int = 1\n" + + "\n" + + "class B:\n" + + " pass\n" + + "\n" + + "B.a: str = \"2\"\n" + + "\n" + + "def func(a):\n" + + " a.xxx: str = \"2\""); } // PY-35235 public void testLiteral() { - runWithLanguageLevel( - LanguageLevel.PYTHON36, - () -> doTestByText("from typing_extensions import Literal\n" + - "\n" + - "a: Literal[1 + 2]\n" + - "b: Literal[4j]\n" + - "c: Literal[3.14]\n" + - "d: Literal[...]\n" + - "\n" + - "class A:\n" + - " pass\n" + - "\n" + - "e: Literal[Literal[A]]\n" + - "f = Literal[A]\n" + - "g: Literal[f]") - ); + doTestByText("from typing_extensions import Literal\n" + + "\n" + + "a: Literal[1 + 2]\n" + + "b: Literal[4j]\n" + + "c: Literal[3.14]\n" + + "d: Literal[...]\n" + + "\n" + + "class A:\n" + + " pass\n" + + "\n" + + "e: Literal[Literal[A]]\n" + + "f = Literal[A]\n" + + "g: Literal[f]"); } // PY-35235 public void testLiteralWithoutArguments() { - runWithLanguageLevel( - LanguageLevel.PYTHON36, - () -> doTestByText("from typing import Literal\n" + - "a: Literal = 1\n" + - "b = 2 # type: Literal") - ); + doTestByText("from typing import Literal\n" + + "a: Literal = 1\n" + + "b = 2 # type: Literal"); } // PY-35235 public void testNonPlainStringAsTypingLiteralIndex() { - runWithLanguageLevel( - LanguageLevel.PYTHON36, - () -> doTestByText("from typing import Literal\n" + - "a: Literal[f\"1\"] = \"1\"") - ); + doTestByText("from typing import Literal\n" + + "a: Literal[f\"1\"] = \"1\""); } public void testParameterizedBuiltinCollectionsBefore39() { diff --git a/python/testSrc/com/jetbrains/python/pyi/PyiTypeTest.java b/python/testSrc/com/jetbrains/python/pyi/PyiTypeTest.java index 4438fc390bf4..47b46471acd2 100644 --- a/python/testSrc/com/jetbrains/python/pyi/PyiTypeTest.java +++ b/python/testSrc/com/jetbrains/python/pyi/PyiTypeTest.java @@ -27,7 +27,6 @@ import com.intellij.psi.PsiElement; import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.fixtures.CodeInsightTestFixture; import com.jetbrains.python.fixtures.PyTestCase; -import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.psi.PyTypedElement; import com.jetbrains.python.psi.types.TypeEvalContext; import org.jetbrains.annotations.NotNull; @@ -47,13 +46,13 @@ public class PyiTypeTest extends PyTestCase { assertNotNull(file); file.refresh(false, true); ModuleRootModificationUtil.addContentRoot(fixture.getModule(), path); - return ()->ModuleRootModificationUtil.updateModel(fixture.getModule(), model -> { - for (ContentEntry entry : model.getContentEntries()) { - if (file.equals(entry.getFile())) { - model.removeContentEntry(entry); - } - } - }); + return () -> ModuleRootModificationUtil.updateModel(fixture.getModule(), model -> { + for (ContentEntry entry : model.getContentEntries()) { + if (file.equals(entry.getFile())) { + model.removeContentEntry(entry); + } + } + }); } @Nullable @@ -62,12 +61,6 @@ public class PyiTypeTest extends PyTestCase { return ourPyLatestDescriptor; } - @Override - public void setUp() throws Exception { - super.setUp(); - setLanguageLevel(LanguageLevel.PYTHON35); - } - @Override public void tearDown() throws Exception { try { @@ -75,7 +68,6 @@ public class PyiTypeTest extends PyTestCase { Disposer.dispose(myDisposable); myDisposable = null; } - setLanguageLevel(null); } catch (Throwable e) { addSuppressedException(e); @@ -135,7 +127,7 @@ public class PyiTypeTest extends PyTestCase { // PY-22808 public void testOverloadedNotMatchedGenericType() { - doTest("Union[Dict[str, Any], list]"); + doTest("Union[dict[str, Any], list]"); } public void testGenericClassDefinitionInOtherFile() { diff --git a/python/testSrc/com/jetbrains/python/quickFixes/PyAsyncCallQuickFixTest.java b/python/testSrc/com/jetbrains/python/quickFixes/PyAsyncCallQuickFixTest.java index 2058cf9d361f..74a7bc5db49f 100644 --- a/python/testSrc/com/jetbrains/python/quickFixes/PyAsyncCallQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/quickFixes/PyAsyncCallQuickFixTest.java @@ -17,9 +17,8 @@ public class PyAsyncCallQuickFixTest extends PyQuickFixTestCase { // PY-17292 public void testAddYieldFromBeforeCall() { - runWithLanguageLevel(LanguageLevel.PYTHON35, - () -> doMultifilesTest(PyAsyncCallInspection.class, PyPsiBundle.message("QFIX.coroutine.is.not.awaited"), - new String[]{"addYieldFromBeforeCall.py", "asyncio/__init__.py", "asyncio/coroutines.py"})); + doMultifilesTest(PyAsyncCallInspection.class, PyPsiBundle.message("QFIX.coroutine.is.not.awaited"), + new String[]{"addYieldFromBeforeCall.py", "asyncio/__init__.py", "asyncio/coroutines.py"}); } @Nullable