mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Fixed bug that leads to a false negative when calling a callback function that returns a callable with a generic parameter type. This addresses #7718. (#7965)
This commit is contained in:
parent
582ead0aa0
commit
1027400ac0
@ -21958,7 +21958,11 @@ export function createTypeEvaluator(
|
||||
) {
|
||||
const specializedReturnType = FunctionType.getSpecializedReturnType(type, /* includeInferred */ false);
|
||||
if (specializedReturnType && !isUnknown(specializedReturnType)) {
|
||||
return adjustCallableReturnType(type, specializedReturnType, /* liveTypeVarScopes */ []);
|
||||
const liveTypeVarScopes = callSiteInfo?.errorNode
|
||||
? ParseTreeUtils.getTypeVarScopesForNode(callSiteInfo?.errorNode)
|
||||
: [];
|
||||
|
||||
return adjustCallableReturnType(type, specializedReturnType, liveTypeVarScopes);
|
||||
}
|
||||
|
||||
if (inferTypeIfNeeded) {
|
||||
|
@ -7,28 +7,23 @@ T = TypeVar("T")
|
||||
U = TypeVar("U")
|
||||
|
||||
|
||||
def foo(value: T) -> T:
|
||||
...
|
||||
def func1(value: T) -> T: ...
|
||||
|
||||
|
||||
def bar(values: Sequence[T]) -> T:
|
||||
...
|
||||
def func2(values: Sequence[T]) -> T: ...
|
||||
|
||||
|
||||
def baz(
|
||||
value: T,
|
||||
callback: Callable[[T], U],
|
||||
) -> U:
|
||||
...
|
||||
def func3(value: T, callback: Callable[[T], U]) -> U: ...
|
||||
|
||||
|
||||
def qux(
|
||||
values: Sequence[T],
|
||||
callback: Callable[[Sequence[T]], U],
|
||||
) -> U:
|
||||
...
|
||||
def func4(values: Sequence[T], callback: Callable[[Sequence[T]], U]) -> U: ...
|
||||
|
||||
|
||||
reveal_type(baz(1.0, foo), expected_text="float")
|
||||
reveal_type(qux([1.0], foo), expected_text="Sequence[float]")
|
||||
reveal_type(qux([1.0], bar), expected_text="float")
|
||||
reveal_type(func3(1.0, func1), expected_text="float")
|
||||
reveal_type(func4([1.0], func1), expected_text="Sequence[float]")
|
||||
reveal_type(func4([1.0], func2), expected_text="float")
|
||||
|
||||
|
||||
def func5(obj: object, cb: Callable[[], Callable[[T], object]]) -> None:
|
||||
# This should generate an error.
|
||||
cb()(obj)
|
||||
|
@ -654,7 +654,7 @@ test('Solver15', () => {
|
||||
test('Solver16', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['solver16.py']);
|
||||
|
||||
TestUtils.validateResults(analysisResults, 0);
|
||||
TestUtils.validateResults(analysisResults, 1);
|
||||
});
|
||||
|
||||
test('Solver17', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user