mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 16:06:39 +03:00
Modified previous heuristic change so it applies only in cases where the source function has a declared return type with a literal annotation in it. It doesn't apply in cases involving an inferred return type or generic types that are specialized with literals.
This commit is contained in:
parent
dd7e3b2b82
commit
5bbb3b5eb8
@ -22651,6 +22651,18 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
|
||||
|
||||
let isReturnTypeCompatible = false;
|
||||
|
||||
let effectiveFlags = flags;
|
||||
|
||||
// If the source has a declared return type that includes a literal
|
||||
// in its annotation, assume that we will want the constraint
|
||||
// solver to retain literals.
|
||||
if (
|
||||
srcType.details.declaredReturnType &&
|
||||
containsLiteralType(srcType.details.declaredReturnType, /* includeTypeArgs */ true)
|
||||
) {
|
||||
effectiveFlags |= CanAssignFlags.RetainLiteralsForTypeVar;
|
||||
}
|
||||
|
||||
if (isNever(srcReturnType)) {
|
||||
// We'll allow any function that returns NoReturn to match any
|
||||
// function return type, consistent with other type checkers.
|
||||
@ -22661,7 +22673,7 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
|
||||
srcReturnType,
|
||||
returnDiag?.createAddendum(),
|
||||
typeVarContext,
|
||||
flags | CanAssignFlags.RetainLiteralsForTypeVar,
|
||||
effectiveFlags,
|
||||
recursionCount
|
||||
)
|
||||
) {
|
||||
|
@ -27,3 +27,10 @@ def f2() -> Literal["Foo"]:
|
||||
|
||||
|
||||
reveal_type(wrapper2(f2)(), expected_text="Literal['Foo']")
|
||||
|
||||
|
||||
def f3():
|
||||
return "Foo"
|
||||
|
||||
|
||||
reveal_type(wrapper2(f3)(), expected_text="str")
|
||||
|
Loading…
Reference in New Issue
Block a user