mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-24990 Add extra tests on more elaborate cases of annotations for cls/self
First, on matching type var with a union receiver type. Though we're not able to match types like "Union[Type[A], Type[B]]" with parametrized "Type[T]" to infer that T is Union[A, B] yet (should we?). Second, on calling an annotated instance method on a class object (when an argument for "self" is provided explicitly).
This commit is contained in:
@@ -1165,6 +1165,82 @@ public class PyTypingTest extends PyTestCase {
|
||||
"expr = D().factory()");
|
||||
}
|
||||
|
||||
// PY-24990
|
||||
public void testSelfAnnotationReceiverUnionType() {
|
||||
doTest("Union[A, B]",
|
||||
"from typing import TypeVar\n" +
|
||||
"\n" +
|
||||
"T = TypeVar('T')\n" +
|
||||
"\n" +
|
||||
"class Base:\n" +
|
||||
" def method(self: T) -> T:\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"class A(Base):\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"class B(Base): \n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"expr = (A() or B()).method()");
|
||||
}
|
||||
|
||||
// PY-24990
|
||||
public void _testClsAnnotationReceiverUnionType() {
|
||||
doTest("Union[A, B]",
|
||||
"from typing import TypeVar, Type\n" +
|
||||
"\n" +
|
||||
"T = TypeVar('T')\n" +
|
||||
"\n" +
|
||||
"class Base:\n" +
|
||||
" @classmethod\n" +
|
||||
" def factory(cls: Type[T]) -> T:\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"class A(Base):\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"class B(Base):\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"expr = (A or B).factory()");
|
||||
}
|
||||
|
||||
// PY-24990
|
||||
public void testClsAnnotationReceiverUnionTypeClassMethodCalledOnMixedInstanceClassObject() {
|
||||
doTest("A",
|
||||
"from typing import TypeVar, Type\n" +
|
||||
"\n" +
|
||||
"T = TypeVar('T')\n" +
|
||||
"\n" +
|
||||
"class Base:\n" +
|
||||
" @classmethod\n" +
|
||||
" def factory(cls: Type[T]) -> T:\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"class A(Base):\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"expr = (A or A()).factory()");
|
||||
}
|
||||
|
||||
// PY-24990
|
||||
public void testSelfAnnotationInstanceMethodCalledOnClassObject() {
|
||||
doTest("D",
|
||||
"from typing import TypeVar\n" +
|
||||
"\n" +
|
||||
"T = TypeVar('T')\n" +
|
||||
"\n" +
|
||||
"class C:\n" +
|
||||
" def method(self: T) -> T:\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"class D(C):\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"expr = C.method(D())");
|
||||
}
|
||||
|
||||
// PY-24990
|
||||
public void testSelfAnnotationInTypeCommentSameClassInstance() {
|
||||
doTest("C",
|
||||
|
||||
Reference in New Issue
Block a user