mirror of
https://github.com/microsoft/pyright.git
synced 2024-10-06 21:07:19 +03:00
Fixed a bug that resulted in a missing type error when a generic function returned a Callable type that used a TypeVar in its parameter types.
This commit is contained in:
parent
2377d1b86f
commit
9466ee48d3
@ -792,7 +792,7 @@ export class Checker extends ParseTreeWalker {
|
||||
declaredReturnType,
|
||||
returnType,
|
||||
diagAddendum,
|
||||
/* typeVarMap */ undefined,
|
||||
new TypeVarMap(),
|
||||
CanAssignFlags.AllowBoolTypeGuard
|
||||
)
|
||||
) {
|
||||
|
@ -20394,13 +20394,6 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
|
||||
}
|
||||
|
||||
if (srcFunction) {
|
||||
if (typeVarMap) {
|
||||
const scopeId = getTypeVarScopeId(destType);
|
||||
if (scopeId !== WildcardTypeVarScopeId) {
|
||||
typeVarMap.addSolveForScope(scopeId);
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
canAssignFunction(
|
||||
destType,
|
||||
|
@ -0,0 +1,23 @@
|
||||
# This sample tests the case where a generic function
|
||||
# returns a generic Callable.
|
||||
|
||||
from typing import Callable, TypeVar
|
||||
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
|
||||
def func1(val1: _T) -> Callable[[_T], None]:
|
||||
def f(a: str):
|
||||
...
|
||||
|
||||
# This should generate an error because str isn't
|
||||
# compatible with _T.
|
||||
return f
|
||||
|
||||
|
||||
def func2(val1: _T) -> Callable[[_T], None]:
|
||||
def f(a: _T):
|
||||
...
|
||||
|
||||
return f
|
@ -799,6 +799,12 @@ test('GenericTypes77', () => {
|
||||
TestUtils.validateResults(analysisResults, 1);
|
||||
});
|
||||
|
||||
test('GenericTypes78', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['genericTypes78.py']);
|
||||
|
||||
TestUtils.validateResults(analysisResults, 1);
|
||||
});
|
||||
|
||||
test('Protocol1', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['protocol1.py']);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user