Fixed regression that results in incorrect type evaluation for annotations that involve nested protocols (such as P[P[T]]). This addresses #6767. (#7963)

This commit is contained in:
Eric Traut 2024-05-20 19:34:46 -07:00 committed by GitHub
parent 7fb7b4158d
commit 51225759d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 1 deletions

View File

@ -537,7 +537,7 @@ export function assignTypeToTypeVar(
adjWideTypeBound,
newNarrowTypeBound,
diag?.createAddendum(),
typeVarContext,
/* destTypeVarContext */ undefined,
/* srcTypeVarContext */ undefined,
AssignTypeFlags.IgnoreTypeVarScope,
recursionCount

View File

@ -0,0 +1,18 @@
# This sample tests the case where a protocol is used as a type argument
# for itself.
from typing import Generic, Protocol, TypeVar
V_co = TypeVar("V_co", covariant=True)
class Proto1(Generic[V_co]):
def f(self, /) -> V_co: ...
class Proto2(Protocol[V_co]):
def f(self, /) -> V_co: ...
def func1(v0: Proto1[Proto1[object]]):
v2: Proto2[Proto2[object]] = v0

View File

@ -575,6 +575,12 @@ test('Protocol49', () => {
TestUtils.validateResults(analysisResults, 0);
});
test('Protocol50', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['protocol50.py']);
TestUtils.validateResults(analysisResults, 0);
});
test('ProtocolExplicit1', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['protocolExplicit1.py']);