mirror of
https://github.com/microsoft/pyright.git
synced 2024-10-06 12:57:14 +03:00
Fixed a bug that results in an incorrect type evaluation of a higher-order function that is passed an overloaded function. This addresses #8898. (#8900)
This commit is contained in:
parent
49235d38ba
commit
12d5fe168f
@ -4197,6 +4197,12 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
||||
return callback();
|
||||
}
|
||||
|
||||
// Handle the case where we're already processing one of the signature contexts
|
||||
// and are called recursively. Don't loop over all the signature contexts again.
|
||||
if (this._activeConstraintSetIndex !== undefined) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
// Loop through all of the signature contexts in the type var context
|
||||
// to create an overload type.
|
||||
const overloadTypes = solutionSets.map((_, index) => {
|
||||
|
@ -0,0 +1,34 @@
|
||||
# This sample tests the case where a function with an overload
|
||||
# is passed to a higher-order function and the return type uses
|
||||
# a nested Callable type.
|
||||
|
||||
from typing import overload, Callable
|
||||
|
||||
|
||||
def func1[A, B](f: Callable[[A], B]) -> Callable[[Callable[[], A]], B]: ...
|
||||
|
||||
|
||||
@overload
|
||||
def func2(v: int) -> None: ...
|
||||
|
||||
|
||||
@overload
|
||||
def func2(v: str) -> None: ...
|
||||
|
||||
|
||||
def func2(v: int | str) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def func3() -> int:
|
||||
return 1
|
||||
|
||||
|
||||
v1 = func1(func2)
|
||||
reveal_type(v1, expected_text="Overload[(() -> int) -> None, (() -> str) -> None]")
|
||||
|
||||
v2 = v1(func3)
|
||||
reveal_type(v2, expected_text="None")
|
||||
|
||||
v3 = v1(lambda: 1)
|
||||
reveal_type(v3, expected_text="None")
|
@ -915,6 +915,12 @@ test('SolverHigherOrder13', () => {
|
||||
TestUtils.validateResults(analysisResults, 0);
|
||||
});
|
||||
|
||||
test('SolverHigherOrder14', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['solverHigherOrder14.py']);
|
||||
|
||||
TestUtils.validateResults(analysisResults, 0);
|
||||
});
|
||||
|
||||
test('SolverLiteral1', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['solverLiteral1.py']);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user