Skip to content

Commit

Permalink
Added test case for microsoft#5027.
Browse files Browse the repository at this point in the history
  • Loading branch information
msfterictraut committed Jun 18, 2023
1 parent 0559382 commit 327ce37
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/pyright-internal/src/tests/samples/protocol42.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This sample tests the case where a protocol implementation uses a
# method-scoped type variable.

from typing import Protocol, Sequence, TypeVar

Input = TypeVar("Input", contravariant=True)
Output = TypeVar("Output", covariant=True)
T = TypeVar("T")


class ProtoA(Protocol[Input, Output]):
def __call__(self, input: Input) -> Output:
raise NotImplementedError


class ImplA:
def __call__(self, input: Sequence[T]) -> T:
return input[0]


v1: ProtoA[Sequence[int], int] = ImplA()
6 changes: 6 additions & 0 deletions packages/pyright-internal/src/tests/typeEvaluator2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,12 @@ test('Protocol41', () => {
TestUtils.validateResults(analysisResults, 0);
});

test('Protocol42', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['protocol42.py']);

TestUtils.validateResults(analysisResults, 0);
});

test('TypedDict1', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['typedDict1.py']);

Expand Down

0 comments on commit 327ce37

Please sign in to comment.