diff --git a/packages/pyright-internal/src/analyzer/typeEvaluator.ts b/packages/pyright-internal/src/analyzer/typeEvaluator.ts index 046d0ad0f..a710985ba 100644 --- a/packages/pyright-internal/src/analyzer/typeEvaluator.ts +++ b/packages/pyright-internal/src/analyzer/typeEvaluator.ts @@ -23979,6 +23979,15 @@ export function createTypeEvaluator( } if (isOverloadedFunction(concreteSrcType)) { + // If this is the first pass of an argument assignment, skip + // all attempts to assign an overloaded function to a function + // because we probably don't have enough information to properly + // filter the overloads at this time. We will do this work on + // subsequent passes. + if ((flags & AssignTypeFlags.ArgAssignmentFirstPass) !== 0) { + return true; + } + // Find all of the overloaded functions that match the parameters. const overloads = OverloadedFunctionType.getOverloads(concreteSrcType); const filteredOverloads: FunctionType[] = []; diff --git a/packages/pyright-internal/src/tests/samples/solver39.py b/packages/pyright-internal/src/tests/samples/solver39.py new file mode 100644 index 000000000..d736f1d0f --- /dev/null +++ b/packages/pyright-internal/src/tests/samples/solver39.py @@ -0,0 +1,11 @@ +# This sample tests the case where an overloaded function is passed as +# an argument and the overloads cannot be filtered during the first +# pass through the arguments. + +from functools import reduce +from operator import getitem +from typing import Any + + +def deep_getitem(data: dict[str, Any], attr: str) -> Any: + return reduce(getitem, attr.split("."), data) diff --git a/packages/pyright-internal/src/tests/typeEvaluator2.test.ts b/packages/pyright-internal/src/tests/typeEvaluator2.test.ts index 695433bf2..cf350787b 100644 --- a/packages/pyright-internal/src/tests/typeEvaluator2.test.ts +++ b/packages/pyright-internal/src/tests/typeEvaluator2.test.ts @@ -795,6 +795,12 @@ test('Solver38', () => { TestUtils.validateResults(analysisResults, 0); }); +test('Solver39', () => { + const analysisResults = TestUtils.typeAnalyzeSampleFiles(['solver39.py']); + + TestUtils.validateResults(analysisResults, 0); +}); + test('SolverScoring1', () => { const analysisResults = TestUtils.typeAnalyzeSampleFiles(['solverScoring1.py']);