mirror of
https://github.com/microsoft/pyright.git
synced 2024-10-04 03:47:28 +03:00
Fixed bug that results in a false positive error when using a callback protocol with a function-scoped type variable. This addresses #8177. (#8207)
This commit is contained in:
parent
ee12ebcccf
commit
6ffb60bd53
@ -962,7 +962,7 @@ export class Checker extends ParseTreeWalker {
|
|||||||
declaredReturnType,
|
declaredReturnType,
|
||||||
returnType,
|
returnType,
|
||||||
diagAddendum,
|
diagAddendum,
|
||||||
new TypeVarContext(),
|
/* destTypeVarContext */ undefined,
|
||||||
/* srcTypeVarContext */ undefined,
|
/* srcTypeVarContext */ undefined,
|
||||||
AssignTypeFlags.AllowBoolTypeGuard
|
AssignTypeFlags.AllowBoolTypeGuard
|
||||||
)
|
)
|
||||||
|
@ -24166,7 +24166,7 @@ export function createTypeEvaluator(
|
|||||||
destType,
|
destType,
|
||||||
concreteSrcType,
|
concreteSrcType,
|
||||||
diag?.createAddendum(),
|
diag?.createAddendum(),
|
||||||
destTypeVarContext ?? new TypeVarContext(getTypeVarScopeId(destType)),
|
destTypeVarContext ?? new TypeVarContext(getTypeVarScopeIds(destType)),
|
||||||
srcTypeVarContext ?? new TypeVarContext(getTypeVarScopeIds(concreteSrcType)),
|
srcTypeVarContext ?? new TypeVarContext(getTypeVarScopeIds(concreteSrcType)),
|
||||||
flags,
|
flags,
|
||||||
recursionCount
|
recursionCount
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
# This sample tests the case where a callback protocol uses a function-
|
||||||
|
# scoped type variable.
|
||||||
|
|
||||||
|
from typing import Generic, Protocol, TypeVar
|
||||||
|
|
||||||
|
T = TypeVar("T")
|
||||||
|
T_co = TypeVar("T_co", covariant=True)
|
||||||
|
U_co = TypeVar("U_co", covariant=True)
|
||||||
|
|
||||||
|
|
||||||
|
class A(Generic[T_co, U_co]): ...
|
||||||
|
|
||||||
|
|
||||||
|
class BProto(Protocol):
|
||||||
|
def __call__(self) -> A[list[T], T]: ...
|
||||||
|
|
||||||
|
|
||||||
|
def func1() -> BProto:
|
||||||
|
def make_a() -> A[list[T], T]: ...
|
||||||
|
|
||||||
|
return make_a
|
@ -73,6 +73,12 @@ test('CallbackProtocol10', () => {
|
|||||||
TestUtils.validateResults(analysisResults, 0);
|
TestUtils.validateResults(analysisResults, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('CallbackProtocol11', () => {
|
||||||
|
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['callbackProtocol11.py']);
|
||||||
|
|
||||||
|
TestUtils.validateResults(analysisResults, 0);
|
||||||
|
});
|
||||||
|
|
||||||
test('Assignment1', () => {
|
test('Assignment1', () => {
|
||||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['assignment1.py']);
|
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['assignment1.py']);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user