mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Drop explicit language level specification in tests that use python-latest project descriptor
GitOrigin-RevId: 6f31bbf0cf26ccca4ffb1a5bd10677cb1d7a9352
This commit is contained in:
committed by
intellij-monorepo-bot
parent
358cd00482
commit
f247cfde52
@@ -8,5 +8,5 @@ b = UserId(<warning descr="Expected type 'int', got 'str' instead">"John"</warni
|
||||
KeyValue = NewType("KeyValue", Dict[str, int])
|
||||
|
||||
KeyValue({"key": 13})
|
||||
KeyValue(<warning descr="Expected type 'Dict[str, int]', got 'int' instead">42</warning>)
|
||||
KeyValue(<warning descr="Expected type 'Dict[str, int]', got 'Dict[str, str]' instead">{"key1": "key2"}</warning>)
|
||||
KeyValue(<warning descr="Expected type 'dict[str, int]', got 'int' instead">42</warning>)
|
||||
KeyValue(<warning descr="Expected type 'dict[str, int]', got 'dict[str, str]' instead">{"key1": "key2"}</warning>)
|
||||
|
||||
@@ -86,23 +86,21 @@ public class Py3CompletionTest extends PyTestCase {
|
||||
|
||||
|
||||
protected void doMultiFileTest(@NotNull List<String> 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<String> suggested = doTestByText("def func(): pass; func.func_<caret>");
|
||||
assertNotNull(suggested);
|
||||
assertEmpty(suggested);
|
||||
List<String> suggested = doTestByText("def func(): pass; func.func_<caret>");
|
||||
assertNotNull(suggested);
|
||||
assertEmpty(suggested);
|
||||
|
||||
suggested = doTestByText("def func(): pass; func.__<caret>");
|
||||
assertNotNull(suggested);
|
||||
assertContainsElements(suggested, "__defaults__", "__globals__", "__closure__",
|
||||
"__code__", "__name__", "__doc__", "__dict__", "__module__");
|
||||
assertContainsElements(suggested, "__annotations__", "__kwdefaults__");
|
||||
}
|
||||
);
|
||||
suggested = doTestByText("def func(): pass; func.__<caret>");
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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" +
|
||||
|
||||
@@ -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
|
||||
|
||||
+13
-14
@@ -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
|
||||
|
||||
@@ -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(<warning descr=\"Expected type 'Literal[\\\"abc\\\"]', got 'Literal[b\\\"abc\\\"]' instead\">b</warning>)\n" +
|
||||
"\n" +
|
||||
"def foo2(p1: Literal[b\"abc\"]):\n" +
|
||||
" pass\n" +
|
||||
"foo2(<warning descr=\"Expected type 'Literal[b\\\"abc\\\"]', got 'Literal[\\\"abc\\\"]' instead\">a</warning>)\n" +
|
||||
"foo2(b)\n" +
|
||||
"\n" +
|
||||
"def foo3(p1: str):\n" +
|
||||
" pass\n" +
|
||||
"foo3(a)\n" +
|
||||
"foo3(<warning descr=\"Expected type 'str', got 'Literal[b\\\"abc\\\"]' instead\">b</warning>)\n" +
|
||||
"\n" +
|
||||
"def foo4(p1: bytes):\n" +
|
||||
" pass\n" +
|
||||
"foo4(<warning descr=\"Expected type 'bytes', got 'Literal[\\\"abc\\\"]' instead\">a</warning>)\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(<warning descr=\"Expected type 'Literal[\\\"abc\\\"]', got 'Literal[b\\\"abc\\\"]' instead\">b</warning>)\n" +
|
||||
"\n" +
|
||||
"def foo2(p1: Literal[b\"abc\"]):\n" +
|
||||
" pass\n" +
|
||||
"foo2(<warning descr=\"Expected type 'Literal[b\\\"abc\\\"]', got 'Literal[\\\"abc\\\"]' instead\">a</warning>)\n" +
|
||||
"foo2(b)\n" +
|
||||
"\n" +
|
||||
"def foo3(p1: str):\n" +
|
||||
" pass\n" +
|
||||
"foo3(a)\n" +
|
||||
"foo3(<warning descr=\"Expected type 'str', got 'Literal[b\\\"abc\\\"]' instead\">b</warning>)\n" +
|
||||
"\n" +
|
||||
"def foo4(p1: bytes):\n" +
|
||||
" pass\n" +
|
||||
"foo4(<warning descr=\"Expected type 'bytes', got 'Literal[\\\"abc\\\"]' instead\">a</warning>)\n" +
|
||||
"foo4(b)\n");
|
||||
}
|
||||
|
||||
// PY-42418
|
||||
|
||||
+15
-28
@@ -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<String> 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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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[<warning descr=\"A 'TypeVar()' expression must always directly be assigned to a variable\">TypeVar('T1')</warning>]")
|
||||
);
|
||||
doTestByText("from typing import List, TypeVar\n" +
|
||||
"\n" +
|
||||
"T0 = TypeVar('T0')\n" +
|
||||
"a: List[T0]\n" +
|
||||
"b: List[<warning descr=\"A 'TypeVar()' expression must always directly be assigned to a variable\">TypeVar('T1')</warning>]");
|
||||
}
|
||||
|
||||
// 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(), <error descr=\"Type variables cannot be used with instance and class checks\">p1</error>)\n" +
|
||||
" assert issubclass(A, <error descr=\"Type variables cannot be used with instance and class checks\">p1</error>)\n" +
|
||||
"\n" +
|
||||
" assert isinstance(A(), p2)\n" +
|
||||
" assert issubclass(A, p2)\n" +
|
||||
"\n" +
|
||||
" assert isinstance(A(), <error descr=\"Type variables cannot be used with instance and class checks\">p3</error>)\n" +
|
||||
" assert issubclass(A, <error descr=\"Type variables cannot be used with instance and class checks\">p3</error>)")
|
||||
);
|
||||
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(), <error descr=\"Type variables cannot be used with instance and class checks\">p1</error>)\n" +
|
||||
" assert issubclass(A, <error descr=\"Type variables cannot be used with instance and class checks\">p1</error>)\n" +
|
||||
"\n" +
|
||||
" assert isinstance(A(), p2)\n" +
|
||||
" assert issubclass(A, p2)\n" +
|
||||
"\n" +
|
||||
" assert isinstance(A(), <error descr=\"Type variables cannot be used with instance and class checks\">p3</error>)\n" +
|
||||
" assert issubclass(A, <error descr=\"Type variables cannot be used with instance and class checks\">p3</error>)");
|
||||
}
|
||||
|
||||
// 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: <error descr=\"Invalid type 'self'\">self</error>.B\n" +
|
||||
" v2 = None # type: <error descr=\"Invalid type 'self'\">self</error>.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: <error descr=\"Invalid type 'self'\">self</error>.B\n" +
|
||||
" v2 = None # type: <error descr=\"Invalid type 'self'\">self</error>.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<warning descr=\"Types specified both in a type comment and annotation\">: int</warning> = None <warning descr=\"Types specified both in a type comment and annotation\"># type: int</warning>\n" +
|
||||
"\n" +
|
||||
"def foo(a<warning descr=\"Types specified both in a type comment and annotation\">: int</warning> <warning descr=\"Types specified both in a type comment and annotation\"># type: int</warning>\n" +
|
||||
" ,):\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"def <warning descr=\"Types specified both in a type comment and annotation\">bar</warning>(a: int) -> int:\n" +
|
||||
" <warning descr=\"Types specified both in a type comment and annotation\"># type: (int) -> int</warning>\n" +
|
||||
" pass\n" +
|
||||
" \n" +
|
||||
"def <warning descr=\"Types specified both in a type comment and annotation\">baz1</warning>(a: int):\n" +
|
||||
" <warning descr=\"Types specified both in a type comment and annotation\"># type: (int) -> int</warning>\n" +
|
||||
" pass\n" +
|
||||
" \n" +
|
||||
"def <warning descr=\"Types specified both in a type comment and annotation\">baz2</warning>(a) -> int:\n" +
|
||||
" <warning descr=\"Types specified both in a type comment and annotation\"># type: (int) -> int</warning>\n" +
|
||||
" pass"
|
||||
)
|
||||
doTestByText(
|
||||
"a<warning descr=\"Types specified both in a type comment and annotation\">: int</warning> = None <warning descr=\"Types specified both in a type comment and annotation\"># type: int</warning>\n" +
|
||||
"\n" +
|
||||
"def foo(a<warning descr=\"Types specified both in a type comment and annotation\">: int</warning> <warning descr=\"Types specified both in a type comment and annotation\"># type: int</warning>\n" +
|
||||
" ,):\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"def <warning descr=\"Types specified both in a type comment and annotation\">bar</warning>(a: int) -> int:\n" +
|
||||
" <warning descr=\"Types specified both in a type comment and annotation\"># type: (int) -> int</warning>\n" +
|
||||
" pass\n" +
|
||||
" \n" +
|
||||
"def <warning descr=\"Types specified both in a type comment and annotation\">baz1</warning>(a: int):\n" +
|
||||
" <warning descr=\"Types specified both in a type comment and annotation\"># type: (int) -> int</warning>\n" +
|
||||
" pass\n" +
|
||||
" \n" +
|
||||
"def <warning descr=\"Types specified both in a type comment and annotation\">baz2</warning>(a) -> int:\n" +
|
||||
" <warning descr=\"Types specified both in a type comment and annotation\"># type: (int) -> int</warning>\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], <error descr=\"Parameters to generic types must be types\">[int]</error>] = None\n" +
|
||||
"foo2: Callable[[int], <error descr=\"Parameters to generic types must be types\">[int, str]</error>] = None\n" +
|
||||
"foo3: List[<error descr=\"Parameters to generic types must be types\">[int]</error>]\n" +
|
||||
"foo4: List[<error descr=\"Parameters to generic types must be types\">[int, str]</error>]\n" +
|
||||
"\n" +
|
||||
"l1 = [int]\n" +
|
||||
"l2 = [int, str]\n" +
|
||||
"\n" +
|
||||
"foo5: Callable[[int], <error descr=\"Parameters to generic types must be types\">l1</error>] = None\n" +
|
||||
"foo6: Callable[[int], <error descr=\"Parameters to generic types must be types\">l2</error>] = None\n" +
|
||||
"foo7: List[<error descr=\"Parameters to generic types must be types\">l1</error>]\n" +
|
||||
"foo8: List[<error descr=\"Parameters to generic types must be types\">l2</error>]"
|
||||
)
|
||||
doTestByText(
|
||||
"from typing import Callable, List\n" +
|
||||
"\n" +
|
||||
"foo1: Callable[[int], <error descr=\"Parameters to generic types must be types\">[int]</error>] = None\n" +
|
||||
"foo2: Callable[[int], <error descr=\"Parameters to generic types must be types\">[int, str]</error>] = None\n" +
|
||||
"foo3: List[<error descr=\"Parameters to generic types must be types\">[int]</error>]\n" +
|
||||
"foo4: List[<error descr=\"Parameters to generic types must be types\">[int, str]</error>]\n" +
|
||||
"\n" +
|
||||
"l1 = [int]\n" +
|
||||
"l2 = [int, str]\n" +
|
||||
"\n" +
|
||||
"foo5: Callable[[int], <error descr=\"Parameters to generic types must be types\">l1</error>] = None\n" +
|
||||
"foo6: Callable[[int], <error descr=\"Parameters to generic types must be types\">l2</error>] = None\n" +
|
||||
"foo7: List[<error descr=\"Parameters to generic types must be types\">l1</error>]\n" +
|
||||
"foo8: List[<error descr=\"Parameters to generic types must be types\">l2</error>]"
|
||||
);
|
||||
}
|
||||
|
||||
// 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" +
|
||||
" <warning descr=\"Non-self attribute could not be type hinted\">b.a</warning>: int = 1\n" +
|
||||
"\n" +
|
||||
"class B:\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"<warning descr=\"Non-self attribute could not be type hinted\">B.a</warning>: str = \"2\"\n" +
|
||||
"\n" +
|
||||
"def func(a):\n" +
|
||||
" <warning descr=\"Non-self attribute could not be type hinted\">a.xxx</warning>: str = \"2\"")
|
||||
);
|
||||
doTestByText("class A:\n" +
|
||||
" def method(self, b):\n" +
|
||||
" <warning descr=\"Non-self attribute could not be type hinted\">b.a</warning>: int = 1\n" +
|
||||
"\n" +
|
||||
"class B:\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"<warning descr=\"Non-self attribute could not be type hinted\">B.a</warning>: str = \"2\"\n" +
|
||||
"\n" +
|
||||
"def func(a):\n" +
|
||||
" <warning descr=\"Non-self attribute could not be type hinted\">a.xxx</warning>: str = \"2\"");
|
||||
}
|
||||
|
||||
// PY-35235
|
||||
public void testLiteral() {
|
||||
runWithLanguageLevel(
|
||||
LanguageLevel.PYTHON36,
|
||||
() -> doTestByText("from typing_extensions import Literal\n" +
|
||||
"\n" +
|
||||
"a: Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">1 + 2</warning>]\n" +
|
||||
"b: Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">4j</warning>]\n" +
|
||||
"c: Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">3.14</warning>]\n" +
|
||||
"d: Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">...</warning>]\n" +
|
||||
"\n" +
|
||||
"class A:\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"e: Literal[Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">A</warning>]]\n" +
|
||||
"f = Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">A</warning>]\n" +
|
||||
"g: Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">f</warning>]")
|
||||
);
|
||||
doTestByText("from typing_extensions import Literal\n" +
|
||||
"\n" +
|
||||
"a: Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">1 + 2</warning>]\n" +
|
||||
"b: Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">4j</warning>]\n" +
|
||||
"c: Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">3.14</warning>]\n" +
|
||||
"d: Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">...</warning>]\n" +
|
||||
"\n" +
|
||||
"class A:\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"e: Literal[Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">A</warning>]]\n" +
|
||||
"f = Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">A</warning>]\n" +
|
||||
"g: Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">f</warning>]");
|
||||
}
|
||||
|
||||
// PY-35235
|
||||
public void testLiteralWithoutArguments() {
|
||||
runWithLanguageLevel(
|
||||
LanguageLevel.PYTHON36,
|
||||
() -> doTestByText("from typing import Literal\n" +
|
||||
"a: <warning descr=\"'Literal' must have at least one parameter\">Literal</warning> = 1\n" +
|
||||
"b = 2 # type: <warning descr=\"'Literal' must have at least one parameter\">Literal</warning>")
|
||||
);
|
||||
doTestByText("from typing import Literal\n" +
|
||||
"a: <warning descr=\"'Literal' must have at least one parameter\">Literal</warning> = 1\n" +
|
||||
"b = 2 # type: <warning descr=\"'Literal' must have at least one parameter\">Literal</warning>");
|
||||
}
|
||||
|
||||
// PY-35235
|
||||
public void testNonPlainStringAsTypingLiteralIndex() {
|
||||
runWithLanguageLevel(
|
||||
LanguageLevel.PYTHON36,
|
||||
() -> doTestByText("from typing import Literal\n" +
|
||||
"a: Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">f\"1\"</warning>] = \"1\"")
|
||||
);
|
||||
doTestByText("from typing import Literal\n" +
|
||||
"a: Literal[<warning descr=\"'Literal' may be parameterized with literal ints, byte and unicode strings, bools, Enum values, None, other literal types, or type aliases to other literal types\">f\"1\"</warning>] = \"1\"");
|
||||
}
|
||||
|
||||
public void testParameterizedBuiltinCollectionsBefore39() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user