mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-31424 Adjust the signature to TypeVar to accept type references
One can pass string literals containing such references both to "*constraints" and "bound" parameters.
This commit is contained in:
@@ -312,8 +312,9 @@ public class PyTypingTypeProvider extends PyTypeProviderBase {
|
||||
final PyElementGenerator generator = PyElementGenerator.getInstance(referenceExpression.getProject());
|
||||
|
||||
parameters.add(PyCallableParameterImpl.nonPsi("name", builtinCache.getStringType(languageLevel)));
|
||||
parameters.add(PyCallableParameterImpl.positionalNonPsi("constraints", builtinCache.getTypeType()));
|
||||
parameters.add(PyCallableParameterImpl.nonPsi("bound", builtinCache.getTypeType(), generator.createEllipsis()));
|
||||
final PyType typeOrForwardReference = PyUnionType.union(builtinCache.getTypeType(), builtinCache.getStrType());
|
||||
parameters.add(PyCallableParameterImpl.positionalNonPsi("constraints", typeOrForwardReference));
|
||||
parameters.add(PyCallableParameterImpl.nonPsi("bound", typeOrForwardReference, generator.createEllipsis()));
|
||||
|
||||
final PyClassType boolType = builtinCache.getBoolType();
|
||||
final PyExpression falseValue = generator.createExpressionFromText(languageLevel, "False");
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
from typing import TypeVar
|
||||
|
||||
TypeVar("T", int, str, bound=int, covariant=True, contravariant=True)
|
||||
TypeVar("T", <warning descr="Expected type 'type', got 'int' instead">0</warning>, <warning descr="Expected type 'type', got 'int' instead">1</warning>, <warning descr="Expected type 'type', got 'int' instead">bound=2</warning>, <warning descr="Expected type 'bool', got 'int' instead">covariant=3</warning>, <warning descr="Expected type 'bool', got 'int' instead">contravariant=4</warning>)
|
||||
TypeVar("T", int, str, bound='int', covariant=True, contravariant=True)
|
||||
TypeVar("T", int, 'str', bound=int, covariant=True, contravariant=True)
|
||||
TypeVar("T", 'int', 'str', bound=int, covariant=True, contravariant=True)
|
||||
TypeVar("T", <warning descr="Expected type 'Union[type, str]', got 'int' instead">0</warning>, <warning descr="Expected type 'Union[type, str]', got 'int' instead">1</warning>, <warning descr="Expected type 'Union[type, str]', got 'int' instead">bound=2</warning>, <warning descr="Expected type 'bool', got 'int' instead">covariant=3</warning>, <warning descr="Expected type 'bool', got 'int' instead">contravariant=4</warning>)
|
||||
@@ -846,14 +846,15 @@ public class PyParameterInfoTest extends LightMarkedTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
// PY-28127
|
||||
// PY-28127 PY-31424
|
||||
public void testInitializingTypeVar() {
|
||||
runWithLanguageLevel(
|
||||
LanguageLevel.PYTHON34,
|
||||
() -> {
|
||||
final int offset = loadTest(1).get("<arg1>").getTextOffset();
|
||||
|
||||
feignCtrlP(offset).check("name: str, *constraints: type, bound: type=..., covariant: bool=False, contravariant: bool=False",
|
||||
feignCtrlP(offset).check("name: str, *constraints: Union[type, str], bound: Union[type, str]=..., " +
|
||||
"covariant: bool=False, contravariant: bool=False",
|
||||
new String[]{"name: str, "},
|
||||
ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase {
|
||||
public void testStrFormatPy3() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
// PY-18762
|
||||
public void testHomogeneousTuples() {
|
||||
doTest();
|
||||
@@ -341,7 +341,7 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON37, () -> super.doMultiFileTest());
|
||||
}
|
||||
|
||||
// PY-28127
|
||||
// PY-28127 PY-31424
|
||||
public void testInitializingTypeVar() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user