From 57a24228e33ef01bccff30aae99445c5ab12f46a Mon Sep 17 00:00:00 2001 From: Reid Barton Date: Sun, 26 Jun 2016 15:44:57 -0700 Subject: [PATCH] Add regression tests for a fix mentioned in #1721 --- test-data/unit/check-inference-context.test | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test-data/unit/check-inference-context.test b/test-data/unit/check-inference-context.test index d4bf76b85556..e75a434c8edb 100644 --- a/test-data/unit/check-inference-context.test +++ b/test-data/unit/check-inference-context.test @@ -795,3 +795,26 @@ class A(Generic[S]): [builtins fixtures/list.py] [out] main: note: In member "f" of class "A": + +[case testLambdaInGenericFunction] +from typing import TypeVar, Callable +T = TypeVar('T') +S = TypeVar('S') +def f(a: T, b: S) -> None: + c = lambda x: x # type: Callable[[T], S] +[out] +main: note: In function "f": +main:5: error: Incompatible return value type (got "T", expected "S") +main:5: error: Incompatible types in assignment (expression has type Callable[[T], T], variable has type Callable[[T], S]) + +[case testLambdaInGenericClass] +from typing import TypeVar, Callable, Generic +T = TypeVar('T') +S = TypeVar('S') +class A(Generic[T]): + def f(self, b: S) -> None: + c = lambda x: x # type: Callable[[T], S] +[out] +main: note: In member "f" of class "A": +main:6: error: Incompatible return value type (got "T", expected "S") +main:6: error: Incompatible types in assignment (expression has type Callable[[T], T], variable has type Callable[[T], S])