Update and rename python-3 project descriptor to python-latest

GitOrigin-RevId: 84ce9b75f90f443eb3dfbd129d2ba2e3142f7dab
This commit is contained in:
Semyon Proshev
2021-03-03 22:46:01 +00:00
committed by intellij-monorepo-bot
parent 72ce51916e
commit bf948101cc
26 changed files with 269 additions and 357 deletions
@@ -28,7 +28,7 @@ import java.util.List;
public class Py3CompletionTest extends PyTestCase {
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
public void testPropertyDecorator() {
@@ -423,12 +423,12 @@ public class Py3CompletionTest extends PyTestCase {
// PY-42700
public void testFStringLikeCompletionInOrdinaryStringLiterals() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::doTest);
doTest();
}
// PY-42700
public void testFStringLikeCompletionPreservesParenthesesForCallables() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::doTest);
doTest();
}
// PY-42700
@@ -438,58 +438,56 @@ public class Py3CompletionTest extends PyTestCase {
// PY-42700
public void testFStringLikeCompletionNotAvailableInByteLiterals() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest);
doNegativeTest();
}
// PY-42700
public void testFStringLikeCompletionNotAvailableInUnicodeLiterals() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest);
doNegativeTest();
}
// PY-42700
public void testFStringLikeCompletionNotAvailableInStrFormatCalls() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest);
doNegativeTest();
}
// PY-42700
public void testFStringLikeCompletionNotAvailableAfterEscapedOpeningBrace() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest);
doNegativeTest();
}
// PY-42700
public void testFStringLikeCompletionAvailableAfterOpeningBraceFollowingEscapedOne() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::doTest);
doTest();
}
// PY-42700
public void testFStringLikeCompletionDoesNotDuplicateClosingBrace() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::doTest);
doTest();
}
// PY-42700
public void testFStringLikeCompletionOnMultipleCaretsDoesNotDuplicatePrefix() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::doTest);
doTest();
}
// PY-42700
public void testFStringLikeCompletionDoesNotWorkInStringWithInjections() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest);
doNegativeTest();
}
// EA-232631
public void testFStringLikeCompletionNotAvailableInStringElementsInSyntacticallyIllegalPosition() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest);
doNegativeTest();
}
// PY-45459
public void testFStringLikeCompletionAvailableRightAfterOpeningBrace() {
runWithLanguageLevel(LanguageLevel.getLatest(), () -> {
myFixture.configureByFile(getTestName(true) + ".py");
LookupElement[] variants = myFixture.completeBasic();
assertNotNull(variants);
assertTrue(variants.length > 0);
assertTrue(ContainerUtil.exists(variants, v -> v.getLookupString().equals("my_expr")));
});
myFixture.configureByFile(getTestName(true) + ".py");
LookupElement[] variants = myFixture.completeBasic();
assertNotNull(variants);
assertTrue(variants.length > 0);
assertTrue(ContainerUtil.exists(variants, v -> v.getLookupString().equals("my_expr")));
}
// PY-46056
@@ -526,12 +524,10 @@ public class Py3CompletionTest extends PyTestCase {
// PY-46054
public void testFromImportFromSameDirectoryModule() {
runWithLanguageLevel(LanguageLevel.getLatest(), () -> {
myFixture.copyDirectoryToProject(getTestName(true), "");
myFixture.configureByFile("foo_bar/sample.py");
myFixture.completeBasic();
myFixture.checkResultByFile(getTestName(true) + "/foo_bar/sample.after.py");
});
myFixture.copyDirectoryToProject(getTestName(true), "");
myFixture.configureByFile("foo_bar/sample.py");
myFixture.completeBasic();
myFixture.checkResultByFile(getTestName(true) + "/foo_bar/sample.after.py");
}
@Override
@@ -23,6 +23,6 @@ public class Py3DeprecationTest extends PyTestCase {
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
}
@@ -29,7 +29,7 @@ public class Py3HighlightingTest extends PyTestCase {
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
// PY-20770
@@ -27,7 +27,7 @@ public class Py3MethodOverridingInspectionTest extends PyInspectionTestCase {
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
// PY-17828
@@ -34,7 +34,7 @@ import java.util.List;
public class Py3QuickFixTest extends PyTestCase {
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return PyTestCase.ourPy3Descriptor;
return PyTestCase.ourPyLatestDescriptor;
}
// PY-13685
@@ -33,7 +33,7 @@ import com.jetbrains.python.pyi.PyiUtil;
public class Py3ResolveTest extends PyResolveTestCase {
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return PyTestCase.ourPy3Descriptor;
return PyTestCase.ourPyLatestDescriptor;
}
@Override
@@ -843,22 +843,16 @@ public class Py3ResolveTest extends PyResolveTestCase {
// PY-25832
public void testTypeVarBoundAttribute() {
runWithLanguageLevel(LanguageLevel.getLatest(), () -> {
assertResolvesTo(PyFunction.class, "upper", "builtins.pyi");
});
assertResolvesTo(PyFunction.class, "upper", "builtins.pyi");
}
// PY-25832
public void testTypeVarConstraintAttribute() {
runWithLanguageLevel(LanguageLevel.getLatest(), () -> {
assertResolvesTo(PyFunction.class, "bit_length", "builtins.pyi");
});
assertResolvesTo(PyFunction.class, "bit_length", "builtins.pyi");
}
// PY-25832
public void testTypeVarClassObjectBoundAttribute() {
runWithLanguageLevel(LanguageLevel.getLatest(), () -> {
assertNull(doResolve());
});
assertNull(doResolve());
}
}
@@ -18,7 +18,7 @@ public class Py3TypeTest extends PyTestCase {
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
// PY-6702
@@ -171,7 +171,7 @@ public class Py3TypeTest extends PyTestCase {
"async def bar():\n" +
" expr = await foo()\n"));
}
// PY-16987
public void testNoTypeInGoogleDocstringParamAnnotation() {
runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("int", "def f(x: int):\n" +
@@ -181,7 +181,7 @@ public class Py3TypeTest extends PyTestCase {
" \"\"\" \n" +
" expr = x"));
}
// PY-16987
public void testUnfilledTypeInGoogleDocstringParamAnnotation() {
runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("int", "def f(x: int):\n" +
@@ -191,7 +191,7 @@ public class Py3TypeTest extends PyTestCase {
" \"\"\" \n" +
" expr = x"));
}
// PY-16987
public void testNoTypeInNumpyDocstringParamAnnotation() {
runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("int", "def f(x: int):\n" +
@@ -203,7 +203,7 @@ public class Py3TypeTest extends PyTestCase {
" \"\"\"\n" +
" expr = x"));
}
// PY-17010
public void testAnnotatedReturnTypePrecedesDocstring() {
runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("int", "def func() -> int:\n" +
@@ -551,7 +551,7 @@ public class Py3TypeTest extends PyTestCase {
// PY-22513
public void testGenericKwargs() {
doTest("Dict[str, Union[int, str]]",
doTest("dict[str, Union[int, str]]",
"from typing import Any, Dict, TypeVar\n" +
"\n" +
"T = TypeVar('T')\n" +
@@ -598,13 +598,13 @@ public class Py3TypeTest extends PyTestCase {
// PY-24445
public void testIsSubclassInsideListComprehension() {
doTest("List[Type[A]]",
doTest("list[Type[A]]",
"class A: pass\n" +
"expr = [e for e in [] if issubclass(e, A)]");
}
public void testIsInstanceInsideListComprehension() {
doTest("List[A]",
doTest("list[A]",
"class A: pass\n" +
"expr = [e for e in [] if isinstance(e, A)]");
}
@@ -1091,44 +1091,38 @@ public class Py3TypeTest extends PyTestCase {
// PY-27783
public void testApplyingSuperSubstitutionToGenericClass() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> doTest("dict[T, int]",
"from typing import TypeVar, Generic, Dict, List\n" +
"\n" +
"T = TypeVar('T')\n" +
"\n" +
"class A(Generic[T]):\n" +
" pass\n" +
"\n" +
"class B(A[List[T]], Generic[T]):\n" +
" def __init__(self) -> None:\n" +
" self.value_set: Dict[T, int] = {}\n" +
"\n" +
" def foo(self) -> None:\n" +
" expr = self.value_set")
);
doTest("dict[T, int]",
"from typing import TypeVar, Generic, Dict, List\n" +
"\n" +
"T = TypeVar('T')\n" +
"\n" +
"class A(Generic[T]):\n" +
" pass\n" +
"\n" +
"class B(A[List[T]], Generic[T]):\n" +
" def __init__(self) -> None:\n" +
" self.value_set: Dict[T, int] = {}\n" +
"\n" +
" def foo(self) -> None:\n" +
" expr = self.value_set");
}
// PY-27783
public void testApplyingSuperSubstitutionToBoundedGenericClass() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> doTest("dict[T, int]",
"from typing import TypeVar, Generic, Dict, List\n" +
"\n" +
"T = TypeVar('T', bound=str)\n" +
"\n" +
"class A(Generic[T]):\n" +
" pass\n" +
"\n" +
"class B(A[List[T]], Generic[T]):\n" +
" def __init__(self) -> None:\n" +
" self.value_set: Dict[T, int] = {}\n" +
"\n" +
" def foo(self) -> None:\n" +
" expr = self.value_set")
);
doTest("dict[T, int]",
"from typing import TypeVar, Generic, Dict, List\n" +
"\n" +
"T = TypeVar('T', bound=str)\n" +
"\n" +
"class A(Generic[T]):\n" +
" pass\n" +
"\n" +
"class B(A[List[T]], Generic[T]):\n" +
" def __init__(self) -> None:\n" +
" self.value_set: Dict[T, int] = {}\n" +
"\n" +
" def foo(self) -> None:\n" +
" expr = self.value_set");
}
// PY-13750
@@ -1165,28 +1159,22 @@ public class Py3TypeTest extends PyTestCase {
// PY-29891
public void testContextManagerType() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> doTest("str",
"from typing import Type, ContextManager\n" +
"def example():\n" +
" manager: Type[ContextManager[str]]\n" +
" with manager() as m:\n" +
" expr = m")
);
doTest("str",
"from typing import Type, ContextManager\n" +
"def example():\n" +
" manager: Type[ContextManager[str]]\n" +
" with manager() as m:\n" +
" expr = m");
}
// PY-29891
public void testAsyncContextManager() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> doTest("str",
"from typing import AsyncContextManager\n" +
"async def example():\n" +
" manager: AsyncContextManager[str]\n" +
" async with manager as m:\n" +
" expr = m")
);
doTest("str",
"from typing import AsyncContextManager\n" +
"async def example():\n" +
" manager: AsyncContextManager[str]\n" +
" async with manager as m:\n" +
" expr = m");
}
private void doTest(final String expectedType, final String text) {
@@ -82,7 +82,7 @@ abstract class PyExternalDocTest : PyTestCase() {
moduleName)}.$elementName")
}
override fun getProjectDescriptor() = ourPy3Descriptor
override fun getProjectDescriptor() = ourPyLatestDescriptor
}
class PyExternalDocTestPy3 : PyExternalDocTest() {
@@ -209,5 +209,5 @@ class PyNavigationTest : PyTestCase() {
return super.getTestDataPath() + "/navigation"
}
override fun getProjectDescriptor(): LightProjectDescriptor? = ourPy3Descriptor
override fun getProjectDescriptor(): LightProjectDescriptor? = ourPyLatestDescriptor
}
@@ -168,6 +168,6 @@ public class PyOverloadsProcessingPerformanceTest extends PyTestCase {
@Override
protected @Nullable LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
}
@@ -21,7 +21,7 @@ public class PyPackageIconTest extends PyTestCase {
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
@Override
@@ -233,7 +233,7 @@ public class PyRegexpTest extends PyTestCase {
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return getName().endsWith("Py3") ? ourPy3Descriptor : super.getProjectDescriptor();
return getName().endsWith("Py3") ? ourPyLatestDescriptor : super.getProjectDescriptor();
}
@NotNull
@@ -21,12 +21,10 @@ import com.intellij.psi.util.QualifiedName;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.PsiTestUtil;
import com.jetbrains.python.fixtures.PyMultiFileResolveTestCase;
import com.jetbrains.python.fixtures.PyTestCase;
import com.jetbrains.python.namespacePackages.PyNamespacePackagesService;
import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.psi.PyFile;
import com.jetbrains.python.psi.PyFunction;
import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher;
import com.jetbrains.python.psi.resolve.PyQualifiedNameResolveContext;
import com.jetbrains.python.psi.resolve.PyResolveImportUtil;
import org.jetbrains.annotations.NotNull;
@@ -52,7 +50,7 @@ public class PyRelativeImportResolveTest extends PyMultiFileResolveTestCase {
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return PyTestCase.ourPy3Descriptor;
return ourPyLatestDescriptor;
}
@Override
@@ -69,14 +67,12 @@ public class PyRelativeImportResolveTest extends PyMultiFileResolveTestCase {
protected void setUp() throws Exception {
super.setUp();
myNamespacePackageDirectory = null;
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), LanguageLevel.getLatest());
RegistryManager.getInstance().get("python.explicit.namespace.packages").resetToDefault();
}
@Override
protected void tearDown() throws Exception {
try {
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), null);
myNamespacePackageDirectory = null;
}
catch (Throwable e) {
@@ -40,7 +40,7 @@ public class PyTypingTest extends PyTestCase {
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
@Override
@@ -465,7 +465,7 @@ public class PyTypingTest extends PyTestCase {
// PY-22620
public void testVariableTypeCommentInjectionTuple() {
doTestInjectedText("x, y = undefined() # type: int,<caret> int",
doTestInjectedText("x, y = undefined() # type: int,<caret> int",
"int, int");
}
@@ -483,14 +483,14 @@ public class PyTypingTest extends PyTestCase {
// PY-22620
public void testVariableTypeCommentInjectionParenthesisedTuple() {
doTestInjectedText("x, y = undefined() # type: (int,<caret> int)",
doTestInjectedText("x, y = undefined() # type: (int,<caret> int)",
"(int, int)");
}
// PY-22620
public void testForTypeCommentInjectionTuple() {
doTestInjectedText("for x, y in undefined(): # type: int,<caret> int\n" +
" pass",
" pass",
"int, int");
}
@@ -555,7 +555,7 @@ public class PyTypingTest extends PyTestCase {
"def f(expr: Type):\n" +
" pass\n");
}
// PY-18254
public void testFunctionTypeComment() {
doTest("(x: int, args: Tuple[float, ...], kwargs: Dict[str, str]) -> List[bool]",
@@ -720,7 +720,7 @@ public class PyTypingTest extends PyTestCase {
"\n" +
"expr = f");
}
// PY-18386
public void testRecursiveType() {
doTest("Union[int, Any]",
@@ -1022,7 +1022,7 @@ public class PyTypingTest extends PyTestCase {
"def f(x: Type[MyClass]): \n" +
" expr = x");
}
// PY-20057
public void testConstrainedClassObjectTypeOfParam() {
doTest("Type[T]",
@@ -1033,7 +1033,7 @@ public class PyTypingTest extends PyTestCase {
"def f(x: Type[T]):\n" +
" expr = x");
}
// PY-20057
public void testFunctionCreatesInstanceFromType() {
doTest("int",
@@ -1068,7 +1068,7 @@ public class PyTypingTest extends PyTestCase {
"def f(x: Type):\n" +
" expr = x");
}
// PY-20057
public void testTypingTypeOfAnyMapsToBuiltinType() {
doTest("type",
@@ -1086,7 +1086,7 @@ public class PyTypingTest extends PyTestCase {
"def f(x: Tuple[Type[42], Type[], Type[unresolved]]):\n" +
" expr = x");
}
// PY-20057
public void testUnionOfClassObjectTypes() {
doTest("Type[Union[int, str]]",
@@ -1529,31 +1529,23 @@ public class PyTypingTest extends PyTestCase {
// PY-41847
public void testTypingAnnotated() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> {
doTest("int",
"from typing import Annotated\n" +
"A = Annotated[int, 'Some constraint']\n" +
"expr: A");
doTest("int",
"from typing_extensions import Annotated\n" +
"expr: Annotated[int, 'Some constraint'] = '5'");
doMultiFileStubAwareTest("int",
"from annotated import A\n" +
"expr: A = 'str'");
}
);
doTest("int",
"from typing import Annotated\n" +
"A = Annotated[int, 'Some constraint']\n" +
"expr: A");
doTest("int",
"from typing_extensions import Annotated\n" +
"expr: Annotated[int, 'Some constraint'] = '5'");
doMultiFileStubAwareTest("int",
"from annotated import A\n" +
"expr: A = 'str'");
}
// PY-35370
public void testAnyArgumentsCallableInTypeComment() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> doTestInjectedText("from typing import Callable\n" +
"a = b # type: Call<caret>able[..., int]",
"Callable[..., int]")
);
doTestInjectedText("from typing import Callable\n" +
"a = b # type: Call<caret>able[..., int]",
"Callable[..., int]");
}
// PY-42334
@@ -73,7 +73,7 @@ import java.util.function.Consumer;
public abstract class PyTestCase extends UsefulTestCase {
protected static final PyLightProjectDescriptor ourPyDescriptor = new PyLightProjectDescriptor(LanguageLevel.PYTHON27);
protected static final PyLightProjectDescriptor ourPy3Descriptor = new PyLightProjectDescriptor(LanguageLevel.PYTHON37);
protected static final PyLightProjectDescriptor ourPyLatestDescriptor = new PyLightProjectDescriptor(LanguageLevel.getLatest());
protected CodeInsightTestFixture myFixture;
@@ -17,7 +17,7 @@ public class Py3AbstractClassInspectionTest extends PyInspectionTestCase {
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
@NotNull
@@ -25,7 +25,7 @@ public class Py3CompatibilityInspectionTest extends PyInspectionTestCase {
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
// PY-18965
@@ -25,7 +25,7 @@ public class Py3NoneFunctionAssignmentInspectionTest extends PyInspectionTestCas
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
// PY-28729
@@ -30,7 +30,7 @@ public class Py3StringFormatInspectionTest extends PyInspectionTestCase {
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
// PY-16938
@@ -14,7 +14,7 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase {
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
@NotNull
@@ -33,18 +33,6 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase {
return TEST_DIRECTORY;
}
@Override
protected void setUp() throws Exception {
super.setUp();
setLanguageLevel(LanguageLevel.getLatest());
}
@Override
protected void tearDown() throws Exception {
setLanguageLevel(null);
super.tearDown();
}
// PY-9289
public void testWithOpenBinaryPy3() {
doTest();
@@ -437,67 +425,53 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase {
// PY-41847
public void testTypingAnnotatedType() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> {
doTestByText("from typing import Annotated\n" +
"A = Annotated[bool, 'Some constraint']\n" +
"a: A = <warning descr=\"Expected type 'bool', got 'str' instead\">'str'</warning>\n" +
"b: A = True\n" +
"c: Annotated[bool, 'Some constraint'] = <warning descr=\"Expected type 'bool', got 'str' instead\">'str'</warning>\n" +
"d: Annotated[str, 'Some constraint'] = 'str'\n");
}
);
doTestByText("from typing import Annotated\n" +
"A = Annotated[bool, 'Some constraint']\n" +
"a: A = <warning descr=\"Expected type 'bool', got 'str' instead\">'str'</warning>\n" +
"b: A = True\n" +
"c: Annotated[bool, 'Some constraint'] = <warning descr=\"Expected type 'bool', got 'str' instead\">'str'</warning>\n" +
"d: Annotated[str, 'Some constraint'] = 'str'\n");
}
// PY-41847
public void testTypingAnnotatedTypeMultiFile() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::doMultiFileTest);
doMultiFileTest();
}
// PY-43838
public void testParameterizedClassAgainstType() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> doTestByText("from typing import Type, Any, List\n" +
"\n" +
"def my_function(param: Type[Any]):\n" +
" pass\n" +
"\n" +
"my_function(List[str])")
);
doTestByText("from typing import Type, Any, List\n" +
"\n" +
"def my_function(param: Type[Any]):\n" +
" pass\n" +
"\n" +
"my_function(List[str])");
}
// PY-43838
public void testUnionAgainstType() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> doTestByText("from typing import Type, Any, Union\n" +
"\n" +
"def my_function(param: Type[Any]):\n" +
" pass\n" +
"\n" +
"my_function(Union[int, str])")
);
doTestByText("from typing import Type, Any, Union\n" +
"\n" +
"def my_function(param: Type[Any]):\n" +
" pass\n" +
"\n" +
"my_function(Union[int, str])");
}
// PY-44575
public void testArgsCallableAgainstOneParameterCallable() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> doTestByText("from typing import Any, Callable, Iterable, TypeVar\n" +
"_T1 = TypeVar(\"_T1\")\n" +
"def mymap(c: Callable[[_T1], Any], i: Iterable[_T1]) -> Iterable[_T1]:\n" +
" pass\n" +
"def myfoo(*args: int) -> int:\n" +
" pass\n" +
"mymap(myfoo, [1, 2, 3])\n")
);
doTestByText("from typing import Any, Callable, Iterable, TypeVar\n" +
"_T1 = TypeVar(\"_T1\")\n" +
"def mymap(c: Callable[[_T1], Any], i: Iterable[_T1]) -> Iterable[_T1]:\n" +
" pass\n" +
"def myfoo(*args: int) -> int:\n" +
" pass\n" +
"mymap(myfoo, [1, 2, 3])\n");
}
// PY-36062
public void testModuleTypeParameter() {
// `types.ModuleType` class qualified name is `_importlib_modulespec.ModuleType` in Python 3
runWithLanguageLevel(LanguageLevel.getLatest(), this::doMultiFileTest);
doMultiFileTest();
}
}
@@ -42,7 +42,7 @@ public class Py3UnresolvedReferencesInspectionTest extends PyInspectionTestCase
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
@NotNull
@@ -73,6 +73,6 @@ public class PyAsyncCallInspectionTest extends PyInspectionTestCase {
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
}
@@ -5,7 +5,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;
@@ -317,20 +316,15 @@ public class PyDataclassInspectionTest extends PyInspectionTestCase {
@Override
protected void doTest() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> {
myFixture.copyFileToProject(getTestCaseDirectory() + "/dataclasses.py", "dataclasses.py");
super.doTest();
assertProjectFilesNotParsed(myFixture.getFile());
}
);
myFixture.copyFileToProject(getTestCaseDirectory() + "/dataclasses.py", "dataclasses.py");
super.doTest();
assertProjectFilesNotParsed(myFixture.getFile());
}
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
@NotNull
@@ -547,110 +547,101 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase {
// PY-16853
public void testParenthesesAndTyping() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> doTestByText("from typing import Union, TypeAlias\n" +
"\n" +
"def a(b: <error descr=\"Generics should be specified through square brackets\">Union(int, str)</error>):\n" +
" pass\n" +
"\n" +
"def c(d):\n" +
" # type: (<error descr=\"Generics should be specified through square brackets\">Union(int, str)</error>) -> None\n" +
" pass\n" +
"\n" +
"def e(f: <error descr=\"Generics should be specified through square brackets\">Union()</error>):\n" +
" pass\n" +
"\n" +
"def g(h):\n" +
" # type: (<error descr=\"Generics should be specified through square brackets\">Union()</error>) -> None\n" +
" pass\n" +
" \n" +
"v1 = <error descr=\"Generics should be specified through square brackets\">Union(int, str)</error>\n" +
"v2 = None # type: <error descr=\"Generics should be specified through square brackets\">Union(int, str)</error>\n" +
"\n" +
"U = Union\n" +
"def i(j: <error descr=\"Generics should be specified through square brackets\">U(int, str)</error>):\n" +
" pass\n" +
" \n" +
"v3 = <error descr=\"Generics should be specified through square brackets\">U(int, str)</error>\n" +
"\n" +
"with foo() as bar: # type: <error descr=\"Generics should be specified through square brackets\">Union(int,str)</error>\n" +
" pass\n" +
" \n" +
"for x in []: # type: <error descr=\"Generics should be specified through square brackets\">Union(int,str)</error>\n" +
" pass\n" +
" \n" +
"A1: TypeAlias = <error descr=\"Generics should be specified through square brackets\">Union(int, str)</error>\n" +
"A2: TypeAlias = '<error descr=\"Generics should be specified through square brackets\">Union(int, str)</error>'\n" +
"A3 = <error descr=\"Generics should be specified through square brackets\">Union(int, str)</error> # type: TypeAlias\n" +
"A3 = '<error descr=\"Generics should be specified through square brackets\">Union(int, str)</error>' # type: TypeAlias")
);
doTestByText("from typing import Union, TypeAlias\n" +
"\n" +
"def a(b: <error descr=\"Generics should be specified through square brackets\">Union(int, str)</error>):\n" +
" pass\n" +
"\n" +
"def c(d):\n" +
" # type: (<error descr=\"Generics should be specified through square brackets\">Union(int, str)</error>) -> None\n" +
" pass\n" +
"\n" +
"def e(f: <error descr=\"Generics should be specified through square brackets\">Union()</error>):\n" +
" pass\n" +
"\n" +
"def g(h):\n" +
" # type: (<error descr=\"Generics should be specified through square brackets\">Union()</error>) -> None\n" +
" pass\n" +
" \n" +
"v1 = <error descr=\"Generics should be specified through square brackets\">Union(int, str)</error>\n" +
"v2 = None # type: <error descr=\"Generics should be specified through square brackets\">Union(int, str)</error>\n" +
"\n" +
"U = Union\n" +
"def i(j: <error descr=\"Generics should be specified through square brackets\">U(int, str)</error>):\n" +
" pass\n" +
" \n" +
"v3 = <error descr=\"Generics should be specified through square brackets\">U(int, str)</error>\n" +
"\n" +
"with foo() as bar: # type: <error descr=\"Generics should be specified through square brackets\">Union(int,str)</error>\n" +
" pass\n" +
" \n" +
"for x in []: # type: <error descr=\"Generics should be specified through square brackets\">Union(int,str)</error>\n" +
" pass\n" +
" \n" +
"A1: TypeAlias = <error descr=\"Generics should be specified through square brackets\">Union(int, str)</error>\n" +
"A2: TypeAlias = '<error descr=\"Generics should be specified through square brackets\">Union(int, str)</error>'\n" +
"A3 = <error descr=\"Generics should be specified through square brackets\">Union(int, str)</error> # type: TypeAlias\n" +
"A3 = '<error descr=\"Generics should be specified through square brackets\">Union(int, str)</error>' # type: TypeAlias");
}
// PY-16853
public void testParenthesesAndCustom() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> doTestByText("from typing import Generic, TypeVar, TypeAlias\n" +
"\n" +
"T = TypeVar(\"T\")\n" +
"\n" +
"class A(Generic[T]):\n" +
" def __init__(self, v):\n" +
" pass\n" +
"\n" +
"def a(b: <warning descr=\"Generics should be specified through square brackets\">A(int)</warning>):\n" +
" pass\n" +
"\n" +
"def c(d):\n" +
" # type: (<warning descr=\"Generics should be specified through square brackets\">A(int)</warning>) -> None\n" +
" pass\n" +
"\n" +
"def e(f: <warning descr=\"Generics should be specified through square brackets\">A()</warning>):\n" +
" pass\n" +
"\n" +
"def g(h):\n" +
" # type: (<warning descr=\"Generics should be specified through square brackets\">A()</warning>) -> None\n" +
" pass\n" +
" \n" +
"v1 = A(int)\n" +
"v2 = None # type: <warning descr=\"Generics should be specified through square brackets\">A(int)</warning>\n" +
"\n" +
"U = A\n" +
"def i(j: <warning descr=\"Generics should be specified through square brackets\">U(int)</warning>):\n" +
" pass\n" +
" \n" +
"v3 = None # type: <warning descr=\"Generics should be specified through square brackets\">U(int)</warning>\n" +
"\n" +
"A1: TypeAlias = <warning descr=\"Generics should be specified through square brackets\">A(int)</warning>\n" +
"A2: TypeAlias = '<warning descr=\"Generics should be specified through square brackets\">A(int)</warning>'\n" +
"A3 = <warning descr=\"Generics should be specified through square brackets\">A(int)</warning> # type: TypeAlias\n" +
"A4 = '<warning descr=\"Generics should be specified through square brackets\">A(int)</warning>' # type: TypeAlias")
);
doTestByText("from typing import Generic, TypeVar, TypeAlias\n" +
"\n" +
"T = TypeVar(\"T\")\n" +
"\n" +
"class A(Generic[T]):\n" +
" def __init__(self, v):\n" +
" pass\n" +
"\n" +
"def a(b: <warning descr=\"Generics should be specified through square brackets\">A(int)</warning>):\n" +
" pass\n" +
"\n" +
"def c(d):\n" +
" # type: (<warning descr=\"Generics should be specified through square brackets\">A(int)</warning>) -> None\n" +
" pass\n" +
"\n" +
"def e(f: <warning descr=\"Generics should be specified through square brackets\">A()</warning>):\n" +
" pass\n" +
"\n" +
"def g(h):\n" +
" # type: (<warning descr=\"Generics should be specified through square brackets\">A()</warning>) -> None\n" +
" pass\n" +
" \n" +
"v1 = A(int)\n" +
"v2 = None # type: <warning descr=\"Generics should be specified through square brackets\">A(int)</warning>\n" +
"\n" +
"U = A\n" +
"def i(j: <warning descr=\"Generics should be specified through square brackets\">U(int)</warning>):\n" +
" pass\n" +
" \n" +
"v3 = None # type: <warning descr=\"Generics should be specified through square brackets\">U(int)</warning>\n" +
"\n" +
"A1: TypeAlias = <warning descr=\"Generics should be specified through square brackets\">A(int)</warning>\n" +
"A2: TypeAlias = '<warning descr=\"Generics should be specified through square brackets\">A(int)</warning>'\n" +
"A3 = <warning descr=\"Generics should be specified through square brackets\">A(int)</warning> # type: TypeAlias\n" +
"A4 = '<warning descr=\"Generics should be specified through square brackets\">A(int)</warning>' # type: TypeAlias");
}
// PY-20530
public void testCallableParameters() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> doTestByText("from typing import Callable, TypeAlias\n" +
"\n" +
"a: Callable[..., str]\n" +
"b: Callable[[int], str]\n" +
"c: Callable[[int, str], str]\n" +
"\n" +
"d: Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">...</error>]\n" +
"e: Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">int</error>, str]\n" +
"f: Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">int, str</error>, str]\n" +
"g: Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">(int, str)</error>, str]\n" +
"h: Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">int</error>]\n" +
"h: Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">(int)</error>, str]\n" +
"\n" +
"A1: TypeAlias = Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">int</error>]\n" +
"A2: TypeAlias = 'Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">int</error>]'\n" +
"A3 = Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">int</error>] # type: TypeAlias\n" +
"A4 = 'Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">int</error>]' # type: TypeAlias")
);
doTestByText("from typing import Callable, TypeAlias\n" +
"\n" +
"a: Callable[..., str]\n" +
"b: Callable[[int], str]\n" +
"c: Callable[[int, str], str]\n" +
"\n" +
"d: Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">...</error>]\n" +
"e: Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">int</error>, str]\n" +
"f: Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">int, str</error>, str]\n" +
"g: Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">(int, str)</error>, str]\n" +
"h: Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">int</error>]\n" +
"h: Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">(int)</error>, str]\n" +
"\n" +
"A1: TypeAlias = Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">int</error>]\n" +
"A2: TypeAlias = 'Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">int</error>]'\n" +
"A3 = Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">int</error>] # type: TypeAlias\n" +
"A4 = 'Callable[<error descr=\"'Callable' must be used as 'Callable[[arg, ...], result]'\">int</error>]' # type: TypeAlias");
}
// PY-20530
@@ -963,30 +954,25 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase {
// PY-42418
public void testParameterizedBuiltinCollections() {
runWithLanguageLevel(LanguageLevel.getLatest(), () -> {
doTestByText("xs: type[str]\n" +
"ys: tuple[int, str]\n" +
"zs: dict[int, str]");
});
doTestByText("xs: type[str]\n" +
"ys: tuple[int, str]\n" +
"zs: dict[int, str]");
}
// PY-41847
public void testAnnotated() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> doTestByText("from typing import Annotated\n" +
"\n" +
"a: Annotated[<warning descr=\"'Annotated' must be called with at least two arguments\">1</warning>]\n" +
"b: Annotated[int, 1]\n" +
"c: Annotated[<warning descr=\"'Annotated' must be called with at least two arguments\">...</warning>]\n" +
"\n" +
"class A:\n" +
" pass\n" +
"\n" +
"d: Annotated[A, '']\n" +
"e: Annotated[<warning descr=\"'Annotated' must be called with at least two arguments\">Annotated[A, True]</warning>]\n" +
"f: Annotated[Annotated[<warning descr=\"'Annotated' must be called with at least two arguments\">A</warning>], '']")
);
doTestByText("from typing import Annotated\n" +
"\n" +
"a: Annotated[<warning descr=\"'Annotated' must be called with at least two arguments\">1</warning>]\n" +
"b: Annotated[int, 1]\n" +
"c: Annotated[<warning descr=\"'Annotated' must be called with at least two arguments\">...</warning>]\n" +
"\n" +
"class A:\n" +
" pass\n" +
"\n" +
"d: Annotated[A, '']\n" +
"e: Annotated[<warning descr=\"'Annotated' must be called with at least two arguments\">Annotated[A, True]</warning>]\n" +
"f: Annotated[Annotated[<warning descr=\"'Annotated' must be called with at least two arguments\">A</warning>], '']");
}
// PY-41847
@@ -1008,54 +994,46 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase {
// PY-41847
public void testAnnotatedWithoutArguments() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> doTestByText("from typing import Annotated\n" +
"a: <warning descr=\"'Annotated' must be called with at least two arguments\">Annotated</warning> = 1\n" +
"b = 2 # type: Annotated[<warning descr=\"'Annotated' must be called with at least two arguments\">int</warning>]")
);
doTestByText("from typing import Annotated\n" +
"a: <warning descr=\"'Annotated' must be called with at least two arguments\">Annotated</warning> = 1\n" +
"b = 2 # type: Annotated[<warning descr=\"'Annotated' must be called with at least two arguments\">int</warning>]");
}
// PY-42334
public void testParametrizedTypeAliasInExpression() {
runWithLanguageLevel(LanguageLevel.getLatest(),
() -> doTestByText("from typing import TypeAlias\n" +
"\n" +
"Alias = TypeAlias[<error descr=\"'TypeAlias' cannot be parameterized\">int</error>]"));
doTestByText("from typing import TypeAlias\n" +
"\n" +
"Alias = TypeAlias[<error descr=\"'TypeAlias' cannot be parameterized\">int</error>]");
}
// PY-42334
public void testParametrizedTypeAliasInAnnotation() {
runWithLanguageLevel(LanguageLevel.getLatest(),
() -> doTestByText("from typing import TypeAlias\n" +
"\n" +
"Alias: <warning descr=\"'TypeAlias' must be used as standalone type hint\">TypeAlias</warning>[int]"));
doTestByText("from typing import TypeAlias\n" +
"\n" +
"Alias: <warning descr=\"'TypeAlias' must be used as standalone type hint\">TypeAlias</warning>[int]");
}
// PY-42334
public void testNonTopLevelTypeAlias() {
runWithLanguageLevel(LanguageLevel.getLatest(),
() -> doTestByText("from typing import TypeAlias\n" +
"\n" +
"Alias: Final[<warning descr=\"'TypeAlias' must be used as standalone type hint\">TypeAlias</warning>] = str"));
doTestByText("from typing import TypeAlias\n" +
"\n" +
"Alias: Final[<warning descr=\"'TypeAlias' must be used as standalone type hint\">TypeAlias</warning>] = str");
}
// PY-42334
public void testNotInitializedTypeAlias() {
runWithLanguageLevel(LanguageLevel.getLatest(),
() -> doTestByText("from typing import TypeAlias\n" +
"\n" +
"<warning descr=\"Type alias must be immediately initialized\">Alias</warning>: TypeAlias"));
doTestByText("from typing import TypeAlias\n" +
"\n" +
"<warning descr=\"Type alias must be immediately initialized\">Alias</warning>: TypeAlias");
}
// PY-42334
public void testNotTopLevelTypeAlias() {
runWithLanguageLevel(LanguageLevel.getLatest(),
() -> doTestByText("from typing import TypeAlias\n" +
"\n" +
"def func():\n" +
" <warning descr=\"Type alias must be top-level declaration\">Alias</warning>: TypeAlias = str"));
doTestByText("from typing import TypeAlias\n" +
"\n" +
"def func():\n" +
" <warning descr=\"Type alias must be top-level declaration\">Alias</warning>: TypeAlias = str");
}
@NotNull
@@ -1066,6 +1044,6 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase {
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
}
@@ -59,7 +59,7 @@ public class PyiTypeTest extends PyTestCase {
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
@Override
@@ -25,6 +25,6 @@ public class PyAsyncCallQuickFixTest extends PyQuickFixTestCase {
@Nullable
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return ourPy3Descriptor;
return ourPyLatestDescriptor;
}
}