diff --git a/python/testSrc/com/jetbrains/python/types/PyGenericTypeTest.kt b/python/testSrc/com/jetbrains/python/types/PyGenericTypeTest.kt index 925d4e585ca6..aaa6d2d61bc9 100644 --- a/python/testSrc/com/jetbrains/python/types/PyGenericTypeTest.kt +++ b/python/testSrc/com/jetbrains/python/types/PyGenericTypeTest.kt @@ -733,6 +733,65 @@ class PyGenericTypeTest : PyCodeInsightTestCase() { expr: TypeAlias[int] #└ TYPE type[int] """) + + @Test + @TestFor(issues = ["PY-90345"]) + fun `call inference via union TypeAlias with class-object arm`() = test(""" + from typing import Generic, TypeVar + T = TypeVar('T') + class Role(Generic[T]): ... + Alias = Role[T] | type[T] + def f(x: Alias[T]) -> T: ... + expr = f(int) + #└ TYPE int + """) + + @Test + @TestFor(issues = ["PY-90345"]) + fun `call inference via union TypeAlias with class-object arm first`() = test(""" + from typing import Generic, TypeVar + T = TypeVar('T') + class Role(Generic[T]): ... + Alias = type[T] | Role[T] + def f(x: Alias[T]) -> T: ... + expr = f(int) + #└ TYPE int + """) + + @Test + @TestFor(issues = ["PY-90345"]) + fun `call inference via three-arm union TypeAlias with class-object`() = test(""" + from typing import Generic, TypeVar + T = TypeVar('T') + class A(Generic[T]): ... + class B(Generic[T]): ... + Alias = A[T] | B[T] | type[T] + def f(x: Alias[T]) -> T: ... + expr = f(int) + #└ TYPE int + """) + + @Test + @TestFor(issues = ["PY-90345"]) + fun `parameterized union TypeAlias with class-object arm`() = test(""" + from typing import Generic, TypeVar + T = TypeVar('T') + class Role(Generic[T]): ... + Alias = Role[T] | type[T] + expr: Alias[int] + #└ TYPE Role[int] | type[int] + """) + + @Test + @TestFor(issues = ["PY-90345"]) + fun `parameterized union TypeAlias with class-object arm PEP695`() = test(""" + from typing import Generic, TypeVar + T = TypeVar('T') + class Role(Generic[T]): ... + type Alias[T] = Role[T] | type[T] + expr: Alias[int] + #└ TYPE Role[int] | type[int] + """) } @Nested @@ -1758,4 +1817,5 @@ class PyGenericTypeTest : PyCodeInsightTestCase() { # FIXME PY-37876: an error is expected here but is not produced; documents current behavior. func(42, accepts_anything) """) + }