mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 16:06:39 +03:00
Changed the heuristics in the TypeVar constraint solver to preserve literals when solving for a TypeVar in a Callable return type.
This commit is contained in:
parent
648ae44bfe
commit
dd7e3b2b82
@ -22661,7 +22661,7 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
|
||||
srcReturnType,
|
||||
returnDiag?.createAddendum(),
|
||||
typeVarContext,
|
||||
flags,
|
||||
flags | CanAssignFlags.RetainLiteralsForTypeVar,
|
||||
recursionCount
|
||||
)
|
||||
) {
|
||||
|
@ -7,12 +7,23 @@ from typing import Callable, TypeVar, Literal
|
||||
_A = TypeVar("_A")
|
||||
|
||||
|
||||
def wrapper(fn: Callable[[_A], int]) -> _A:
|
||||
def wrapper1(fn: Callable[[_A], int]) -> _A:
|
||||
...
|
||||
|
||||
|
||||
def f3(a: Literal[0]) -> int:
|
||||
def f1(a: Literal[0]) -> int:
|
||||
...
|
||||
|
||||
|
||||
wrapper(f3)
|
||||
reveal_type(wrapper1(f1), expected_text="Literal[0]")
|
||||
|
||||
|
||||
def wrapper2(fn: Callable[..., _A]) -> Callable[..., _A]:
|
||||
...
|
||||
|
||||
|
||||
def f2() -> Literal["Foo"]:
|
||||
return "Foo"
|
||||
|
||||
|
||||
reveal_type(wrapper2(f2)(), expected_text="Literal['Foo']")
|
||||
|
Loading…
Reference in New Issue
Block a user