PY-82979 PY-81028 Adjust the heuristic for implicit type aliases to recognize Annotated and Literal

Namely, that `Annotated` can contain arbitrary expressions and that `Literal` might
contain boolean and integer literals.

GitOrigin-RevId: 6b3d4212679d6556dfe1d4905f06a78e2769b4e2
This commit is contained in:
Mikhail Golubev
2025-09-16 11:17:44 +00:00
committed by intellij-monorepo-bot
parent d281245b4b
commit 5e6b043e8c
6 changed files with 72 additions and 12 deletions
@@ -0,0 +1,4 @@
from m import StrictStr
s: StrictStr
@@ -0,0 +1,4 @@
from typing import Annotated
StrictStr = Annotated[str, object()]
@@ -0,0 +1,5 @@
from sample import HttpOk, Http400, Http404
def foo() -> HttpOk[None] | Http400 | Http404:
pass
@@ -0,0 +1,14 @@
from typing import Literal, TypeVar
Code = TypeVar("Code", bound=int)
Response = TypeVar("Response", bound=list | str | None)
Error = TypeVar("Error", default=str, bound= str | None)
Http = tuple[Code, Response]
HttpOk = Http[Literal[200], Response]
Http400 = Http[Literal[400], Error]
Http401 = Http[Literal[401], Error]
Http403 = Http[Literal[403], Error]
Http404 = Http[Literal[404], Error]
Http422 = Http[Literal[422], ErrorResponse[list[ErrorDetails]]]
Http500 = Http[Literal[500], Literal["Internal Server Error"]]