diff --git a/python/testSrc/com/jetbrains/python/PyTypingTest.java b/python/testSrc/com/jetbrains/python/PyTypingTest.java index 34e0726be345..ff9cd6a45d3c 100644 --- a/python/testSrc/com/jetbrains/python/PyTypingTest.java +++ b/python/testSrc/com/jetbrains/python/PyTypingTest.java @@ -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",