From 2c499d5e2852e5e06b7d75d7ec225ed0bfd92a5d Mon Sep 17 00:00:00 2001 From: MechanicalConstruct Date: Tue, 3 Dec 2024 19:57:12 -0500 Subject: [PATCH 1/4] Update printing for Callables --- mypy/messages.py | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 6b0760cd79c6..d8df79817930 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -24,9 +24,6 @@ from mypy.errorcodes import ErrorCode from mypy.errors import ErrorInfo, Errors, ErrorWatcher from mypy.nodes import ( - ARG_NAMED, - ARG_NAMED_OPT, - ARG_OPT, ARG_POS, ARG_STAR, ARG_STAR2, @@ -112,17 +109,6 @@ "typing.cast", } - -ARG_CONSTRUCTOR_NAMES: Final = { - ARG_POS: "Arg", - ARG_OPT: "DefaultArg", - ARG_NAMED: "NamedArg", - ARG_NAMED_OPT: "DefaultNamedArg", - ARG_STAR: "VarArg", - ARG_STAR2: "KwArg", -} - - # Map from the full name of a missing definition to the test fixture (under # test-data/unit/fixtures/) that provides the definition. This is used for # generating better error messages when running mypy tests only. @@ -2039,6 +2025,7 @@ def report_non_method_protocol( def note_call( self, subtype: Type, call: Type, context: Context, *, code: ErrorCode | None ) -> None: + # breakpoint() self.note( '"{}.__call__" has type {}'.format( format_type_bare(subtype, self.options), @@ -2487,11 +2474,10 @@ def format_callable_args( if arg_kind == ARG_POS and arg_name is None or verbosity == 0 and arg_kind.is_positional(): arg_strings.append(format(arg_type)) else: - constructor = ARG_CONSTRUCTOR_NAMES[arg_kind] if arg_kind.is_star() or arg_name is None: - arg_strings.append(f"{constructor}({format(arg_type)})") + arg_strings.append(f"{format(arg_type)}") else: - arg_strings.append(f"{constructor}({format(arg_type)}, {repr(arg_name)})") + arg_strings.append(f"{arg_name}: {format(arg_type)}") return ", ".join(arg_strings) @@ -2709,14 +2695,14 @@ def format_literal_value(typ: LiteralType) -> str: else: return_type = format(func.ret_type) if func.is_ellipsis_args: - return f"Callable[..., {return_type}]" + return f"(..., {return_type})" param_spec = func.param_spec() if param_spec is not None: - return f"Callable[{format(param_spec)}, {return_type}]" + return f"({format(param_spec)}, {return_type})" args = format_callable_args( func.arg_types, func.arg_kinds, func.arg_names, format, verbosity ) - return f"Callable[[{args}], {return_type}]" + return f"({args}) -> {return_type}" else: # Use a simple representation for function types; proper # function types may result in long and difficult-to-read From 4dfccc627498cf711c3d95c66049bb6d7e4ac87a Mon Sep 17 00:00:00 2001 From: MechanicalConstruct Date: Fri, 6 Dec 2024 18:24:44 -0500 Subject: [PATCH 2/4] stage unit test changes --- test-data/unit/check-functools.test | 8 ++++---- test-data/unit/check-inference.test | 14 ++++++------- test-data/unit/check-namedtuple.test | 2 +- test-data/unit/check-recursive-types.test | 4 ++-- test-data/unit/daemon.test | 4 ++-- test-data/unit/fine-grained.test | 24 +++++++++++------------ test-data/unit/pythoneval-asyncio.test | 2 +- test-data/unit/pythoneval.test | 4 ++-- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/test-data/unit/check-functools.test b/test-data/unit/check-functools.test index c1868b3e3d72..636eca22c83d 100644 --- a/test-data/unit/check-functools.test +++ b/test-data/unit/check-functools.test @@ -332,7 +332,7 @@ p = functools.partial(foo, kwarg="asdf") def bar(a: int, b: str, c: float) -> None: ... p(bar, 1, "a", 3.0) # OK p(bar, 1, "a", 3.0, kwarg="asdf") # OK -p(bar, 1, "a", "b") # E: Argument 1 to "foo" has incompatible type "Callable[[int, str, float], None]"; expected "Callable[[int, str, str], None]" +p(bar, 1, "a", "b") # E: Argument 1 to "foo" has incompatible type "(int, str, float) -> None"; expected "(int, str, str) -> None" [builtins fixtures/dict.pyi] [case testFunctoolsPartialUnion] @@ -353,7 +353,7 @@ reveal_type(functools.partial(fn2, 2)()) # N: Revealed type is "Union[builtins. fn3: Union[Callable[[int], int], str] reveal_type(functools.partial(fn3, 2)()) # E: "str" not callable \ # N: Revealed type is "builtins.int" \ - # E: Argument 1 to "partial" has incompatible type "Union[Callable[[int], int], str]"; expected "Callable[..., int]" + # E: Argument 1 to "partial" has incompatible type "Union[Callable[[int], int], str]"; expected "(..., int)" [builtins fixtures/tuple.pyi] [case testFunctoolsPartialUnionOfTypeAndCallable] @@ -385,8 +385,8 @@ p: partial[str] = partial(generic, resulting_type=str) q: partial[bool] = partial(generic, resulting_type=str) # E: Argument "resulting_type" to "generic" has incompatible type "Type[str]"; expected "Type[bool]" pc: Callable[..., str] = partial(generic, resulting_type=str) -qc: Callable[..., bool] = partial(generic, resulting_type=str) # E: Incompatible types in assignment (expression has type "partial[str]", variable has type "Callable[..., bool]") \ - # N: "partial[str].__call__" has type "Callable[[VarArg(Any), KwArg(Any)], str]" +qc: Callable[..., bool] = partial(generic, resulting_type=str) # E: Incompatible types in assignment (expression has type "partial[str]", variable has type "(..., bool)") \ + # N: "partial[str].__call__" has type "(Any, Any) -> str" [builtins fixtures/tuple.pyi] [case testFunctoolsPartialNestedPartial] diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index 5a99e65c9c90..6b12216dccad 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -400,7 +400,7 @@ main:6: error: Need more than 3 values to unpack (4 expected) [case testInvalidRvalueTypeInInferredMultipleLvarDefinition] import typing def f() -> None: - a, b = f # E: "Callable[[], None]" object is not iterable + a, b = f # E: "() -> None" object is not iterable c, d = A() # E: "A" object is not iterable class A: pass [builtins fixtures/for.pyi] @@ -409,7 +409,7 @@ class A: pass [case testInvalidRvalueTypeInInferredNestedTupleAssignment] import typing def f() -> None: - a1, (a2, b) = A(), f # E: "Callable[[], None]" object is not iterable + a1, (a2, b) = A(), f # E: "() -> None" object is not iterable a3, (c, d) = A(), A() # E: "A" object is not iterable class A: pass [builtins fixtures/for.pyi] @@ -988,7 +988,7 @@ a = k2 if int(): a = k2 if int(): - a = k1 # E: Incompatible types in assignment (expression has type "Callable[[int, List[T@k1]], List[Union[T@k1, int]]]", variable has type "Callable[[S, List[T@k2]], List[Union[T@k2, int]]]") + a = k1 # E: Incompatible types in assignment (expression has type "(int, List[T@k1]) -> List[Union[T@k1, int]]", variable has type "(S, List[T@k2]) -> List[Union[T@k2, int]]") b = k1 if int(): b = k1 @@ -1109,7 +1109,7 @@ def f(*, x: int) -> int: ... def g(*, y: int) -> int: ... def h(*, x: int) -> int: ... -list_1 = [f, g] # E: List item 0 has incompatible type "Callable[[NamedArg(int, 'x')], int]"; expected "Callable[[NamedArg(int, 'y')], int]" +list_1 = [f, g] # E: List item 0 has incompatible type "(x: int) -> int"; expected "(y: int) -> int" list_2 = [f, h] [builtins fixtures/list.pyi] @@ -1390,14 +1390,14 @@ from typing import List, Callable li = [1] l = lambda: li f1 = l # type: Callable[[], List[int]] -f2 = l # type: Callable[[], List[str]] # E: Incompatible types in assignment (expression has type "Callable[[], List[int]]", variable has type "Callable[[], List[str]]") +f2 = l # type: Callable[[], List[str]] # E: Incompatible types in assignment (expression has type "() -> List[int]", variable has type "() -> List[str]") [builtins fixtures/list.pyi] [case testInferLambdaType2] from typing import List, Callable l = lambda: [B()] f1 = l # type: Callable[[], List[B]] -f2 = l # type: Callable[[], List[A]] # E: Incompatible types in assignment (expression has type "Callable[[], List[B]]", variable has type "Callable[[], List[A]]") +f2 = l # type: Callable[[], List[A]] # E: Incompatible types in assignment (expression has type "() -> List[B]", variable has type "() -> List[A]") class A: pass class B: pass @@ -1435,7 +1435,7 @@ from typing import Callable def f(a: Callable[..., None] = lambda *a, **k: None): pass -def g(a: Callable[..., None] = lambda *a, **k: 1): # E: Incompatible default for argument "a" (default has type "Callable[[VarArg(Any), KwArg(Any)], int]", argument has type "Callable[..., None]") +def g(a: Callable[..., None] = lambda *a, **k: 1): # E: Incompatible default for argument "a" (default has type "(Any, Any) -> int", argument has type "(..., None)") pass [builtins fixtures/dict.pyi] diff --git a/test-data/unit/check-namedtuple.test b/test-data/unit/check-namedtuple.test index df2c7ffc8067..1f832353be4e 100644 --- a/test-data/unit/check-namedtuple.test +++ b/test-data/unit/check-namedtuple.test @@ -549,7 +549,7 @@ b = B._make(['']) # type: B [case testNamedTupleIncompatibleRedefinition] from typing import NamedTuple class Crash(NamedTuple): - count: int # E: Incompatible types in assignment (expression has type "int", base class "tuple" defined the type as "Callable[[Tuple[int, ...], object], int]") + count: int # E: Incompatible types in assignment (expression has type "int", base class "tuple" defined the type as "(Tuple[int, ...], object) -> int") [builtins fixtures/tuple.pyi] [case testNamedTupleInClassNamespace] diff --git a/test-data/unit/check-recursive-types.test b/test-data/unit/check-recursive-types.test index 4d7af98204fb..c38f23b470c3 100644 --- a/test-data/unit/check-recursive-types.test +++ b/test-data/unit/check-recursive-types.test @@ -1012,5 +1012,5 @@ p = ta from typing import Callable from bogus import Foo # type: ignore -A = Callable[[Foo, "B"], Foo] # E: Type alias target becomes "Callable[[Any, B], Any]" due to an unfollowed import -B = Callable[[Foo, A], Foo] # E: Type alias target becomes "Callable[[Any, A], Any]" due to an unfollowed import +A = Callable[[Foo, "B"], Foo] # E: Type alias target becomes "(Any, B) -> Any" due to an unfollowed import +B = Callable[[Foo, A], Foo] # E: Type alias target becomes "(Any, A) -> Any" due to an unfollowed import diff --git a/test-data/unit/daemon.test b/test-data/unit/daemon.test index 7dfddd8f74df..8976e59cbc5d 100644 --- a/test-data/unit/daemon.test +++ b/test-data/unit/daemon.test @@ -456,7 +456,7 @@ $ dmypy inspect foo.py:3:10:3:17 -vv $ dmypy inspect foo.py:9:9:9:11 "int" $ dmypy inspect foo.py:11:1:11:3 -"Callable[[Optional[int]], None]" +"(Optional[int]) -> None" $ dmypy inspect foo.py:11:1:13:1 "None" $ dmypy inspect foo.py:1:2:3:4 @@ -517,7 +517,7 @@ $ dmypy inspect foo.py:7:5 -vv $ dmypy inspect foo.py:7:5 -vv --limit=1 "builtins.int" $ dmypy inspect foo.py:7:3 -"Callable[[int], None]" +"(int) -> None" "None" $ dmypy inspect foo.py:1:2 Can't find any expressions at position 1:2 diff --git a/test-data/unit/fine-grained.test b/test-data/unit/fine-grained.test index 9ff8a37ae9ae..5d7e1271ed0c 100644 --- a/test-data/unit/fine-grained.test +++ b/test-data/unit/fine-grained.test @@ -1340,7 +1340,7 @@ class A: [out] == -- This is a bad error message -main:7: error: Argument 1 to "use" has incompatible type "Type[A]"; expected "Callable[[], A]" +main:7: error: Argument 1 to "use" has incompatible type "Type[A]"; expected "() -> A" [case testConstructorSignatureChanged3] from a import C @@ -2227,7 +2227,7 @@ class B: x: int [out] == -a.py:3: error: Argument 1 to "deca" has incompatible type "Callable[[B], B]"; expected "Callable[[str], str]" +a.py:3: error: Argument 1 to "deca" has incompatible type "(B) -> B"; expected "(str) -> str" == a.py:6: error: "B" has no attribute "x" == @@ -2295,7 +2295,7 @@ class B: x: int [out] == -a.py:4: error: Argument 1 to "deca" has incompatible type "Callable[[B], B]"; expected "Callable[[str], str]" +a.py:4: error: Argument 1 to "deca" has incompatible type "(B) -> B"; expected "(str) -> str" == a.py:7: error: "B" has no attribute "x" == @@ -2363,7 +2363,7 @@ class B: x: int [out] == -a.py:4: error: Argument 1 to "deca" has incompatible type "Callable[[D, B], B]"; expected "Callable[..., str]" +a.py:4: error: Argument 1 to "deca" has incompatible type "(D, B) -> B"; expected "(..., str)" == a.py:7: error: "B" has no attribute "x" == @@ -2389,7 +2389,7 @@ def dec(func: Callable[[str], str]) -> Callable[[str], str]: pass [out] == -a.py:5: error: Argument 1 to "dec" has incompatible type "Callable[[int], int]"; expected "Callable[[str], str]" +a.py:5: error: Argument 1 to "dec" has incompatible type "(int) -> int"; expected "(str) -> str" [case testDecoratorUpdateNestedClass] import a @@ -2414,7 +2414,7 @@ class C: pass [out] == -a.py:6: error: Argument 1 to "dec" of "C" has incompatible type "Callable[[Inner, int], int]"; expected "Callable[..., str]" +a.py:6: error: Argument 1 to "dec" of "C" has incompatible type "(Inner, int) -> int"; expected "(..., str)" [case testDecoratorUpdateClassInFunction] import a @@ -2450,7 +2450,7 @@ class B: x: str [out] == -a.py:6: error: Argument 1 to "dec" of "C" has incompatible type "Callable[[Inner, B], int]"; expected "Callable[..., str]" +a.py:6: error: Argument 1 to "dec" of "C" has incompatible type "(Inner, B) -> int"; expected "(..., str)" == a.py:8: error: Incompatible return value type (got "str", expected "int") @@ -2480,7 +2480,7 @@ def dec(f: Callable[[C], int]) -> Callable[[int], int]: pass [out] == -a.py:3: error: Argument 1 to "dec" has incompatible type "Callable[[B], int]"; expected "Callable[[C], int]" +a.py:3: error: Argument 1 to "dec" has incompatible type "(B) -> int"; expected "(C) -> int" [case testOverloadRefresh] from typing import overload @@ -4514,9 +4514,9 @@ x = 0 x = '' [builtins fixtures/tuple.pyi] [out] -b.py:5: error: Incompatible types in assignment (expression has type "int", base class "tuple" defined the type as "Callable[[Tuple[int, ...], object], int]") +b.py:5: error: Incompatible types in assignment (expression has type "int", base class "tuple" defined the type as "(Tuple[int, ...], object) -> int") == -b.py:5: error: Incompatible types in assignment (expression has type "int", base class "tuple" defined the type as "Callable[[Tuple[int, ...], object], int]") +b.py:5: error: Incompatible types in assignment (expression has type "int", base class "tuple" defined the type as "(Tuple[int, ...], object) -> int") [case testReprocessEllipses1] import a @@ -6161,7 +6161,7 @@ class C: pass [out] == -a.py:6: error: Argument 1 to "func" has incompatible type "Type[C]"; expected "Callable[[int], Any]" +a.py:6: error: Argument 1 to "func" has incompatible type "Type[C]"; expected "(int) -> Any" [case testDunderNewDefine] import a @@ -8094,7 +8094,7 @@ def A(x: str) -> str: pass [builtins fixtures/list.pyi] [out] == -a.py:4: error: Incompatible import of "A" (imported name has type "Callable[[str], str]", local name has type "Type[List[Any]]") +a.py:4: error: Incompatible import of "A" (imported name has type "(str) -> str", local name has type "Type[List[Any]]") [case testFakeOverloadCrash] import b diff --git a/test-data/unit/pythoneval-asyncio.test b/test-data/unit/pythoneval-asyncio.test index 4a185557495b..57435c617b98 100644 --- a/test-data/unit/pythoneval-asyncio.test +++ b/test-data/unit/pythoneval-asyncio.test @@ -364,7 +364,7 @@ try: finally: loop.close() [out] -_program.py:17: error: Argument 1 to "add_done_callback" of "Future" has incompatible type "Callable[[Future[int]], None]"; expected "Callable[[Future[str]], object]" +_program.py:17: error: Argument 1 to "add_done_callback" of "Future" has incompatible type "(Future[int]) -> None"; expected "(Future[str]) -> object" [case testErrorOneMoreFutureInReturnType] import typing diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index 70003545754c..312208126f3d 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -616,7 +616,7 @@ def f(*args: str) -> str: return args[0] map(f, ['x']) map(f, [1]) [out] -_program.py:4: error: Argument 1 to "map" has incompatible type "Callable[[VarArg(str)], str]"; expected "Callable[[int], str]" +_program.py:4: error: Argument 1 to "map" has incompatible type "(str) -> str"; expected "(int) -> str" [case testMapStr] import typing @@ -823,7 +823,7 @@ class MyDDict(t.DefaultDict[int,T], t.Generic[T]): MyDDict(dict)['0'] MyDDict(dict)[0] [out] -_program.py:7: error: Argument 1 to "defaultdict" has incompatible type "Type[List[Any]]"; expected "Optional[Callable[[], str]]" +_program.py:7: error: Argument 1 to "defaultdict" has incompatible type "Type[List[Any]]"; expected "Optional[() -> str]" _program.py:10: error: Invalid index type "str" for "defaultdict[int, str]"; expected type "int" _program.py:10: error: Incompatible types in assignment (expression has type "int", target has type "str") _program.py:20: error: Argument 1 to "tst" has incompatible type "defaultdict[str, List[Never]]"; expected "defaultdict[int, List[Never]]" From d4d893c71cbc8fbe6437f5f893b319ac6cb99086 Mon Sep 17 00:00:00 2001 From: MechanicalConstruct Date: Fri, 6 Dec 2024 20:19:55 -0500 Subject: [PATCH 3/4] update tests to follow new error / printing syntax --- test-data/unit/check-assert-type-fail.test | 2 +- test-data/unit/check-callable.test | 16 ++-- test-data/unit/check-classes.test | 74 +++++++-------- test-data/unit/check-custom-plugin.test | 2 +- test-data/unit/check-dataclasses.test | 8 +- test-data/unit/check-deprecated.test | 2 +- test-data/unit/check-dynamic-typing.test | 28 +++--- test-data/unit/check-errorcodes.test | 2 +- test-data/unit/check-expressions.test | 10 +- test-data/unit/check-flags.test | 10 +- test-data/unit/check-functions.test | 92 +++++++++---------- test-data/unit/check-functools.test | 8 +- test-data/unit/check-generics.test | 52 +++++------ test-data/unit/check-incremental.test | 4 +- test-data/unit/check-inference-context.test | 12 +-- test-data/unit/check-inference.test | 22 ++--- test-data/unit/check-modules.test | 22 ++--- test-data/unit/check-newsemanal.test | 4 +- test-data/unit/check-optional.test | 2 +- test-data/unit/check-overloading.test | 8 +- .../unit/check-parameter-specification.test | 56 +++++------ test-data/unit/check-plugin-attrs.test | 8 +- test-data/unit/check-protocols.test | 66 ++++++------- test-data/unit/check-python311.test | 2 +- test-data/unit/check-redefine.test | 2 +- test-data/unit/check-selftype.test | 22 ++--- test-data/unit/check-serialize.test | 2 +- test-data/unit/check-singledispatch.test | 2 +- test-data/unit/check-statements.test | 6 +- test-data/unit/check-tuples.test | 2 +- test-data/unit/check-type-aliases.test | 2 +- test-data/unit/check-typeguard.test | 10 +- test-data/unit/check-typeis.test | 16 ++-- test-data/unit/check-typevar-tuple.test | 56 +++++------ test-data/unit/check-typevar-values.test | 2 +- test-data/unit/check-varargs.test | 2 +- 36 files changed, 318 insertions(+), 318 deletions(-) diff --git a/test-data/unit/check-assert-type-fail.test b/test-data/unit/check-assert-type-fail.test index 89b3a863f8c7..6f5261e1bc43 100644 --- a/test-data/unit/check-assert-type-fail.test +++ b/test-data/unit/check-assert-type-fail.test @@ -30,4 +30,4 @@ def f(si: arr.array[int]): [case testAssertTypeFailCallableArgKind] from typing import assert_type, Callable def myfunc(arg: int) -> None: pass -assert_type(myfunc, Callable[[int], None]) # E: Expression is of type "Callable[[Arg(int, 'arg')], None]", not "Callable[[int], None]" +assert_type(myfunc, Callable[[int], None]) # E: Expression is of type "(arg: int) -> None", not "(int) -> None" diff --git a/test-data/unit/check-callable.test b/test-data/unit/check-callable.test index 39e6c4fa3ff1..ae70b9cfbca5 100644 --- a/test-data/unit/check-callable.test +++ b/test-data/unit/check-callable.test @@ -155,8 +155,8 @@ x = 5 # type: Union[int, Callable[[], str]] if callable(x) and x() == 'test': x() else: - x + 5 # E: Unsupported left operand type for + ("Callable[[], str]") \ - # N: Left operand is of type "Union[int, Callable[[], str]]" + x + 5 # E: Unsupported left operand type for + ("() -> str") \ + # N: Left operand is of type "Union[int, () -> str]" [builtins fixtures/callable.pyi] @@ -605,14 +605,14 @@ class Call(Protocol): def __call__(self, x: int, *args: Any, **kwargs: Any) -> None: ... def f1() -> None: ... -a1: Call = f1 # E: Incompatible types in assignment (expression has type "Callable[[], None]", variable has type "Call") \ - # N: "Call.__call__" has type "Callable[[Arg(int, 'x'), VarArg(Any), KwArg(Any)], None]" +a1: Call = f1 # E: Incompatible types in assignment (expression has type "() -> None", variable has type "Call") \ + # N: "Call.__call__" has type "(x: int, Any, Any) -> None" def f2(x: str) -> None: ... -a2: Call = f2 # E: Incompatible types in assignment (expression has type "Callable[[str], None]", variable has type "Call") \ - # N: "Call.__call__" has type "Callable[[Arg(int, 'x'), VarArg(Any), KwArg(Any)], None]" +a2: Call = f2 # E: Incompatible types in assignment (expression has type "(str) -> None", variable has type "Call") \ + # N: "Call.__call__" has type "(x: int, Any, Any) -> None" def f3(y: int) -> None: ... -a3: Call = f3 # E: Incompatible types in assignment (expression has type "Callable[[int], None]", variable has type "Call") \ - # N: "Call.__call__" has type "Callable[[Arg(int, 'x'), VarArg(Any), KwArg(Any)], None]" +a3: Call = f3 # E: Incompatible types in assignment (expression has type "(int) -> None", variable has type "Call") \ + # N: "Call.__call__" has type "(x: int, Any, Any) -> None" def f4(x: int) -> None: ... a4: Call = f4 diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index 5ce80faaee18..c62bf2fdc7c1 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -104,7 +104,7 @@ import typing class A: def f(self): pass A().f = None # E: Cannot assign to a method \ - # E: Incompatible types in assignment (expression has type "None", variable has type "Callable[[], Any]") + # E: Incompatible types in assignment (expression has type "None", variable has type "() -> Any") [case testOverrideAttributeWithMethod] @@ -145,7 +145,7 @@ class Base: pass class Derived(Base): - __hash__ = 1 # E: Incompatible types in assignment (expression has type "int", base class "Base" defined the type as "Callable[[Base], int]") + __hash__ = 1 # E: Incompatible types in assignment (expression has type "int", base class "Base" defined the type as "(Base) -> int") [case testOverridePartialAttributeWithMethod] # This was crashing: https://github.com/python/mypy/issues/11686. @@ -740,13 +740,13 @@ class A: f3: Callable[[str], None] class B(A): - def f1(self, x: object) -> None: pass # E: Covariant override of a mutable attribute (base class "A" defined the type as "Callable[[str], None]", override has type "Callable[[object], None]") + def f1(self, x: object) -> None: pass # E: Covariant override of a mutable attribute (base class "A" defined the type as "(str) -> None", override has type "(object) -> None") @classmethod - def f2(cls, x: object) -> None: pass # E: Covariant override of a mutable attribute (base class "A" defined the type as "Callable[[str], None]", override has type "Callable[[object], None]") + def f2(cls, x: object) -> None: pass # E: Covariant override of a mutable attribute (base class "A" defined the type as "(str) -> None", override has type "(object) -> None") @staticmethod - def f3(x: object) -> None: pass # E: Covariant override of a mutable attribute (base class "A" defined the type as "Callable[[str], None]", override has type "Callable[[object], None]") + def f3(x: object) -> None: pass # E: Covariant override of a mutable attribute (base class "A" defined the type as "(str) -> None", override has type "(object) -> None") [builtins fixtures/classmethod.pyi] [case testOverrideCallableAttributeWithSettableProperty] @@ -770,7 +770,7 @@ class A: f: Callable[[str], None] class B(A): - @property # E: Covariant override of a mutable attribute (base class "A" defined the type as "Callable[[str], None]", override has type "Callable[[object], None]") + @property # E: Covariant override of a mutable attribute (base class "A" defined the type as "(str) -> None", override has type "(object) -> None") def f(self) -> Callable[[object], None]: pass @func.setter def f(self, x: object) -> None: pass @@ -812,18 +812,18 @@ class A: f4: Union[Callable[[str], str], str] class B(A): - def f1(self, x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[Callable[[str], str], str]", override has type "Callable[[str], str]") + def f1(self, x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[(str) -> str, str]", override has type "(str) -> str") pass - def f2(self, x: object) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[Callable[[str], str], str]", override has type "Callable[[object], str]") + def f2(self, x: object) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[(str) -> str, str]", override has type "(object) -> str") pass @classmethod - def f3(cls, x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[Callable[[str], str], str]", override has type "Callable[[str], str]") + def f3(cls, x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[(str) -> str, str]", override has type "(str) -> str") pass @staticmethod - def f4(x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[Callable[[str], str], str]", override has type "Callable[[str], str]") + def f4(x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[(str) -> str, str]", override has type "(str) -> str") pass [builtins fixtures/classmethod.pyi] @@ -1095,9 +1095,9 @@ class A: if int(): h = f g = h - ff = f # type: Callable[[B], None] # E: Incompatible types in assignment (expression has type "Callable[[A], None]", variable has type "Callable[[B], None]") + ff = f # type: Callable[[B], None] # E: Incompatible types in assignment (expression has type "(A) -> None", variable has type "(B) -> None") if int(): - g = ff # E: Incompatible types in assignment (expression has type "Callable[[B], None]", variable has type "Callable[[A], None]") + g = ff # E: Incompatible types in assignment (expression has type "(B) -> None", variable has type "(A) -> None") [out] @@ -1206,7 +1206,7 @@ import typing class A: def f(self): pass A.f = None # E: Cannot assign to a method \ - # E: Incompatible types in assignment (expression has type "None", variable has type "Callable[[A], Any]") + # E: Incompatible types in assignment (expression has type "None", variable has type "(A) -> Any") [case testAssignToNestedClassViaClass] import typing @@ -2345,8 +2345,8 @@ class B: class C: def __radd__(self, other, oops) -> int: ... [out] -tmp/foo.pyi:3: error: Invalid signature "Callable[[B], A]" -tmp/foo.pyi:5: error: Invalid signature "Callable[[C, Any, Any], int]" +tmp/foo.pyi:3: error: Invalid signature "(B) -> A" +tmp/foo.pyi:5: error: Invalid signature "(C, Any, Any) -> int" [case testReverseOperatorOrderingCase1] class A: @@ -2934,8 +2934,8 @@ class C: class D: def __getattribute__(self, x: str) -> None: pass [out] -main:4: error: Invalid signature "Callable[[B, A], B]" for "__getattribute__" -main:6: error: Invalid signature "Callable[[C, str, str], C]" for "__getattribute__" +main:4: error: Invalid signature "(B, A) -> B" for "__getattribute__" +main:6: error: Invalid signature "(C, str, str) -> C" for "__getattribute__" [case testGetattr] a: A @@ -3004,7 +3004,7 @@ class C: def do(cd: Callable[..., Any]) -> None: ... -do(C()) # E: Argument 1 to "do" has incompatible type "C"; expected "Callable[..., Any]" +do(C()) # E: Argument 1 to "do" has incompatible type "C"; expected "(..., Any)" [case testGetattrWithCallableTypeVar] from typing import Callable, Any, TypeVar @@ -3040,8 +3040,8 @@ class C: class D: def __getattr__(self, x: str) -> None: pass [out] -main:4: error: Invalid signature "Callable[[B, A], B]" for "__getattr__" -main:6: error: Invalid signature "Callable[[C, str, str], C]" for "__getattr__" +main:4: error: Invalid signature "(B, A) -> B" for "__getattr__" +main:6: error: Invalid signature "(C, str, str) -> C" for "__getattr__" [case testSetattr] from typing import Union, Any @@ -3119,12 +3119,12 @@ b.bad = 'a' # E: Incompatible types in assignment (expression has type "str", v from typing import Any class Test: - def __setattr__() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument? # E: Invalid signature "Callable[[], None]" for "__setattr__" + def __setattr__() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument? # E: Invalid signature "() -> None" for "__setattr__" t = Test() t.crash = 'test' # E: "Test" has no attribute "crash" class A: - def __setattr__(self): ... # E: Invalid signature "Callable[[A], Any]" for "__setattr__" + def __setattr__(self): ... # E: Invalid signature "(A) -> Any" for "__setattr__" a = A() a.test = 4 # E: "A" has no attribute "test" @@ -3134,7 +3134,7 @@ b = B() b.integer = 5 class C: - def __setattr__(self, name: int, value: int) -> None: ... # E: Invalid signature "Callable[[C, int, int], None]" for "__setattr__" + def __setattr__(self, name: int, value: int) -> None: ... # E: Invalid signature "(C, int, int) -> None" for "__setattr__" c = C() c.check = 13 @@ -3355,7 +3355,7 @@ class B: a = A bad = lambda: 42 -B().bad() # E: Attribute function "bad" with type "Callable[[], int]" does not accept self argument +B().bad() # E: Attribute function "bad" with type "() -> int" does not accept self argument reveal_type(B.a) # N: Revealed type is "def () -> __main__.A" reveal_type(B().a) # N: Revealed type is "def () -> __main__.A" reveal_type(B().a()) # N: Revealed type is "__main__.A" @@ -4439,7 +4439,7 @@ class A: def a(self) -> None: pass b = 1 class B(A): - a = 1 # E: Incompatible types in assignment (expression has type "int", base class "A" defined the type as "Callable[[A], None]") + a = 1 # E: Incompatible types in assignment (expression has type "int", base class "A" defined the type as "(A) -> None") def b(self) -> None: pass # E: Signature of "b" incompatible with supertype "A" \ # N: Superclass: \ # N: int \ @@ -4483,7 +4483,7 @@ class C(B): def m(self, a: str) -> None: pass n = m [out] -main:5: error: Incompatible types in assignment (expression has type "Callable[[str], None]", base class "B" defined the type as "Callable[[int], None]") +main:5: error: Incompatible types in assignment (expression has type "(str) -> None", base class "B" defined the type as "(int) -> None") [case testInstanceMethodOverwriteTypevar] from typing import Generic, TypeVar @@ -4527,7 +4527,7 @@ class C(B): n = m [builtins fixtures/classmethod.pyi] [out] -main:7: error: Incompatible types in assignment (expression has type "Callable[[str], None]", base class "B" defined the type as "Callable[[int], None]") +main:7: error: Incompatible types in assignment (expression has type "(str) -> None", base class "B" defined the type as "(int) -> None") [case testClassSpec] from typing import Callable @@ -4545,7 +4545,7 @@ class B(A): def c(self, a: str) -> int: pass b = c [out] -main:6: error: Incompatible types in assignment (expression has type "Callable[[str], int]", base class "A" defined the type as "Callable[[int], int]") +main:6: error: Incompatible types in assignment (expression has type "(str) -> int", base class "A" defined the type as "(int) -> int") [case testClassStaticMethod] class A(): @@ -4557,7 +4557,7 @@ class B(A): a = b [builtins fixtures/staticmethod.pyi] [out] -main:7: error: Incompatible types in assignment (expression has type "Callable[[str], None]", base class "A" defined the type as "Callable[[int], None]") +main:7: error: Incompatible types in assignment (expression has type "(str) -> None", base class "A" defined the type as "(int) -> None") [case testClassStaticMethodIndirect] class A(): @@ -4570,7 +4570,7 @@ class B(A): c = b [builtins fixtures/staticmethod.pyi] [out] -main:8: error: Incompatible types in assignment (expression has type "Callable[[str], None]", base class "A" defined the type as "Callable[[int], None]") +main:8: error: Incompatible types in assignment (expression has type "(str) -> None", base class "A" defined the type as "(int) -> None") [case testClassStaticMethodSubclassing] class A: @@ -5053,9 +5053,9 @@ reveal_type(A.g4) # N: Revealed type is "def () -> def () -> __main__.A" class B(metaclass=M): def foo(self): pass -B.g1 # E: Invalid self argument "Type[B]" to attribute function "g1" with type "Callable[[Type[A]], A]" -B.g2 # E: Invalid self argument "Type[B]" to attribute function "g2" with type "Callable[[Type[TA]], TA]" -B.g3 # E: Invalid self argument "Type[B]" to attribute function "g3" with type "Callable[[TTA], TTA]" +B.g1 # E: Invalid self argument "Type[B]" to attribute function "g1" with type "(Type[A]) -> A" +B.g2 # E: Invalid self argument "Type[B]" to attribute function "g2" with type "(Type[TA]) -> TA" +B.g3 # E: Invalid self argument "Type[B]" to attribute function "g3" with type "(TTA) -> TTA" reveal_type(B.g4) # N: Revealed type is "def () -> def () -> __main__.B" # 4 examples of unsoundness - instantiation, classmethod, staticmethod and ClassVar: @@ -5068,9 +5068,9 @@ reveal_type(ta.g3) # N: Revealed type is "def () -> Type[__main__.A]" reveal_type(ta.g4) # N: Revealed type is "def () -> Type[__main__.A]" x: M = ta -x.g1 # E: Invalid self argument "M" to attribute function "g1" with type "Callable[[Type[A]], A]" -x.g2 # E: Invalid self argument "M" to attribute function "g2" with type "Callable[[Type[TA]], TA]" -x.g3 # E: Invalid self argument "M" to attribute function "g3" with type "Callable[[TTA], TTA]" +x.g1 # E: Invalid self argument "M" to attribute function "g1" with type "(Type[A]) -> A" +x.g2 # E: Invalid self argument "M" to attribute function "g2" with type "(Type[TA]) -> TA" +x.g3 # E: Invalid self argument "M" to attribute function "g3" with type "(TTA) -> TTA" reveal_type(x.g4) # N: Revealed type is "def () -> __main__.M" def r(ta: Type[TA], tta: TTA) -> None: @@ -7823,7 +7823,7 @@ class Foo: def meth1(self, a: str) -> str: ... # E: Name "meth1" already defined on line 5 def meth2(self, a: str) -> str: ... - from mod1 import meth2 # E: Incompatible import of "meth2" (imported name has type "Callable[[int], int]", local name has type "Callable[[Foo, str], str]") + from mod1 import meth2 # E: Incompatible import of "meth2" (imported name has type "(int) -> int", local name has type "(Foo, str) -> str") class Bar: from mod1 import foo # E: Unsupported class scoped import diff --git a/test-data/unit/check-custom-plugin.test b/test-data/unit/check-custom-plugin.test index 1e06f300570e..75138e83996e 100644 --- a/test-data/unit/check-custom-plugin.test +++ b/test-data/unit/check-custom-plugin.test @@ -330,7 +330,7 @@ from mypy_extensions import DefaultArg from m import Signal s: Signal[[int, DefaultArg(str, 'x')]] = Signal() reveal_type(s) # N: Revealed type is "m.Signal[def (builtins.int, x: builtins.str =)]" -s.x # E: "Signal[Callable[[int, str], None]]" has no attribute "x" +s.x # E: "Signal[(int, str) -> None]" has no attribute "x" ss: Signal[int, str] # E: Invalid "Signal" type (expected "Signal[[t, ...]]") [file m.py] from typing import TypeVar, Generic, Callable diff --git a/test-data/unit/check-dataclasses.test b/test-data/unit/check-dataclasses.test index 6de428109c72..a010f02343f2 100644 --- a/test-data/unit/check-dataclasses.test +++ b/test-data/unit/check-dataclasses.test @@ -297,7 +297,7 @@ class Person: age: int = field(init=None) # E: No overload variant of "field" matches argument type "None" \ # N: Possible overload variants: \ # N: def [_T] field(*, default: _T, init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., metadata: Optional[Mapping[str, Any]] = ..., kw_only: bool = ...) -> _T \ - # N: def [_T] field(*, default_factory: Callable[[], _T], init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., metadata: Optional[Mapping[str, Any]] = ..., kw_only: bool = ...) -> _T \ + # N: def [_T] field(*, default_factory: () -> _T, init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., metadata: Optional[Mapping[str, Any]] = ..., kw_only: bool = ...) -> _T \ # N: def field(*, init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., metadata: Optional[Mapping[str, Any]] = ..., kw_only: bool = ...) -> Any [builtins fixtures/dataclasses.pyi] @@ -1374,7 +1374,7 @@ def x2(s: str) -> str: a = A(lambda i:i) a.x = x -a.x = x2 # E: Incompatible types in assignment (expression has type "Callable[[str], str]", variable has type "Callable[[int], int]") +a.x = x2 # E: Incompatible types in assignment (expression has type "(str) -> str", variable has type "(int) -> int") [builtins fixtures/dataclasses.pyi] [case testDataclassFieldDoesNotFailOnKwargsUnpacking] @@ -1389,7 +1389,7 @@ main:6: error: Unpacking **kwargs in "field()" is not supported main:6: error: No overload variant of "field" matches argument type "Dict[str, bool]" main:6: note: Possible overload variants: main:6: note: def [_T] field(*, default: _T, init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., metadata: Optional[Mapping[str, Any]] = ..., kw_only: bool = ...) -> _T -main:6: note: def [_T] field(*, default_factory: Callable[[], _T], init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., metadata: Optional[Mapping[str, Any]] = ..., kw_only: bool = ...) -> _T +main:6: note: def [_T] field(*, default_factory: () -> _T, init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., metadata: Optional[Mapping[str, Any]] = ..., kw_only: bool = ...) -> _T main:6: note: def field(*, init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., metadata: Optional[Mapping[str, Any]] = ..., kw_only: bool = ...) -> Any [builtins fixtures/dataclasses.pyi] @@ -1402,7 +1402,7 @@ class C: # E: No overload variant of "field" matches argument type "int" \ # N: Possible overload variants: \ # N: def [_T] field(*, default: _T, init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., metadata: Optional[Mapping[str, Any]] = ..., kw_only: bool = ...) -> _T \ - # N: def [_T] field(*, default_factory: Callable[[], _T], init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., metadata: Optional[Mapping[str, Any]] = ..., kw_only: bool = ...) -> _T \ + # N: def [_T] field(*, default_factory: () -> _T, init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., metadata: Optional[Mapping[str, Any]] = ..., kw_only: bool = ...) -> _T \ # N: def field(*, init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., metadata: Optional[Mapping[str, Any]] = ..., kw_only: bool = ...) -> Any [builtins fixtures/dataclasses.pyi] diff --git a/test-data/unit/check-deprecated.test b/test-data/unit/check-deprecated.test index 8bbb887d4567..386b69cf1393 100644 --- a/test-data/unit/check-deprecated.test +++ b/test-data/unit/check-deprecated.test @@ -53,7 +53,7 @@ f # E: function __main__.f is deprecated: use f2 instead # type: ignore[deprec f(1) # E: function __main__.f is deprecated: use f2 instead \ # E: Too many arguments for "f" f[1] # E: function __main__.f is deprecated: use f2 instead \ - # E: Value of type "Callable[[], None]" is not indexable + # E: Value of type "() -> None" is not indexable g = f # E: function __main__.f is deprecated: use f2 instead g() t = (f, f, g) # E: function __main__.f is deprecated: use f2 instead diff --git a/test-data/unit/check-dynamic-typing.test b/test-data/unit/check-dynamic-typing.test index 21fd52169ff5..3472cc04b4dc 100644 --- a/test-data/unit/check-dynamic-typing.test +++ b/test-data/unit/check-dynamic-typing.test @@ -375,7 +375,7 @@ def f(x): pass f() # E: Missing positional argument "x" in call to "f" f(x, x) # E: Too many arguments for "f" if int(): - g = f # E: Incompatible types in assignment (expression has type "Callable[[Any], Any]", variable has type "Callable[[], None]") + g = f # E: Incompatible types in assignment (expression has type "(Any) -> Any", variable has type "() -> None") f(a) f(x) if int(): @@ -396,13 +396,13 @@ def f0(): pass def f2(x, y): pass if int(): - g1 = f0 # E: Incompatible types in assignment (expression has type "Callable[[], Any]", variable has type "Callable[[A], None]") + g1 = f0 # E: Incompatible types in assignment (expression has type "() -> Any", variable has type "(A) -> None") if int(): - g2 = f0 # E: Incompatible types in assignment (expression has type "Callable[[], Any]", variable has type "Callable[[A, A], None]") + g2 = f0 # E: Incompatible types in assignment (expression has type "() -> Any", variable has type "(A, A) -> None") if int(): - g0 = f2 # E: Incompatible types in assignment (expression has type "Callable[[Any, Any], Any]", variable has type "Callable[[], None]") + g0 = f2 # E: Incompatible types in assignment (expression has type "(Any, Any) -> Any", variable has type "() -> None") if int(): - g1 = f2 # E: Incompatible types in assignment (expression has type "Callable[[Any, Any], Any]", variable has type "Callable[[A], None]") + g1 = f2 # E: Incompatible types in assignment (expression has type "(Any, Any) -> Any", variable has type "(A) -> None") if int(): g0 = g0 @@ -434,11 +434,11 @@ f01(a, a) # E: Too many arguments for "f01" f13() # E: Missing positional argument "x" in call to "f13" f13(a, a, a, a) # E: Too many arguments for "f13" if int(): - g2 = f01 # E: Incompatible types in assignment (expression has type "Callable[[Any], Any]", variable has type "Callable[[A, A], None]") + g2 = f01 # E: Incompatible types in assignment (expression has type "(Any) -> Any", variable has type "(A, A) -> None") if int(): - g0 = f13 # E: Incompatible types in assignment (expression has type "Callable[[Any, Any, Any], Any]", variable has type "Callable[[], None]") + g0 = f13 # E: Incompatible types in assignment (expression has type "(Any, Any, Any) -> Any", variable has type "() -> None") if int(): - g4 = f13 # E: Incompatible types in assignment (expression has type "Callable[[Any, Any, Any], Any]", variable has type "Callable[[A, A, A, A], None]") + g4 = f13 # E: Incompatible types in assignment (expression has type "(Any, Any, Any) -> Any", variable has type "(A, A, A, A) -> None") f01() f01(a) @@ -488,11 +488,11 @@ g2: Callable[[A, A], None] a: A if int(): - g0 = a.f # E: Incompatible types in assignment (expression has type "Callable[[Any], Any]", variable has type "Callable[[], None]") + g0 = a.f # E: Incompatible types in assignment (expression has type "(Any) -> Any", variable has type "() -> None") if int(): - g2 = a.f # E: Incompatible types in assignment (expression has type "Callable[[Any], Any]", variable has type "Callable[[A, A], None]") + g2 = a.f # E: Incompatible types in assignment (expression has type "(Any) -> Any", variable has type "(A, A) -> None") if int(): - a = a.f # E: Incompatible types in assignment (expression has type "Callable[[Any], Any]", variable has type "A") + a = a.f # E: Incompatible types in assignment (expression has type "(Any) -> Any", variable has type "A") class A: def g(self) -> None: @@ -520,7 +520,7 @@ g1: Callable[[A], None] a: A if int(): - g0 = a.f # E: Incompatible types in assignment (expression has type "Callable[[Any], Any]", variable has type "Callable[[], None]") + g0 = a.f # E: Incompatible types in assignment (expression has type "(Any) -> Any", variable has type "() -> None") if int(): g1 = a.f @@ -569,7 +569,7 @@ a: A A(a) # E: Missing positional argument "b" in call to "A" if int(): - f1 = A # E: Incompatible types in assignment (expression has type "Type[A]", variable has type "Callable[[A], A]") + f1 = A # E: Incompatible types in assignment (expression has type "Type[A]", variable has type "(A) -> A") A(a, a) if int(): @@ -659,7 +659,7 @@ f1: Callable[[Any], None] f2: Callable[[Any, Any], None] if int(): - f1 = f2 # E: Incompatible types in assignment (expression has type "Callable[[Any, Any], None]", variable has type "Callable[[Any], None]") + f1 = f2 # E: Incompatible types in assignment (expression has type "(Any, Any) -> None", variable has type "(Any) -> None") -- Overriding diff --git a/test-data/unit/check-errorcodes.test b/test-data/unit/check-errorcodes.test index 10cc145d0c70..bcd0aea8e017 100644 --- a/test-data/unit/check-errorcodes.test +++ b/test-data/unit/check-errorcodes.test @@ -1081,7 +1081,7 @@ def h(self: A) -> None: pass A.f = h # This actually works at runtime, but there is no way to express this in current type system -A.f = A().g # E: Incompatible types in assignment (expression has type "Callable[[], None]", variable has type "Callable[[A], None]") [assignment] +A.f = A().g # E: Incompatible types in assignment (expression has type "() -> None", variable has type "(A) -> None") [assignment] [case testMethodAssignCoveredByAssignmentIgnore] class A: diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index cd26c9bb408a..730d22b8067a 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -1247,7 +1247,7 @@ if int(): f = lambda: ''.x # E: "str" has no attribute "x" if int(): f = lambda: '' \ - # E: Incompatible types in assignment (expression has type "Callable[[], str]", variable has type "Callable[[], int]") \ + # E: Incompatible types in assignment (expression has type "() -> str", variable has type "() -> int") \ # E: Incompatible return value type (got "str", expected "int") [case testVoidLambda] @@ -1422,7 +1422,7 @@ from typing import Callable, Iterator, List a = [] # type: List[Callable[[], str]] b: Iterator[Callable[[], int]] if int(): - b = (x for x in a) # E: Generator has incompatible item type "Callable[[], str]"; expected "Callable[[], int]" + b = (x for x in a) # E: Generator has incompatible item type "() -> str"; expected "() -> int" [builtins fixtures/list.pyi] -- Conditional expressions @@ -1518,8 +1518,8 @@ def f() -> None: pass a: A None + a # E: Unsupported left operand type for + ("None") -f + a # E: Unsupported left operand type for + ("Callable[[], None]") -a + f # E: Unsupported operand types for + ("A" and "Callable[[], None]") +f + a # E: Unsupported left operand type for + ("() -> None") +a + f # E: Unsupported operand types for + ("A" and "() -> None") cast(A, f) [case testOperatorMethodWithInvalidArgCount] @@ -1902,7 +1902,7 @@ def things() -> int: return 42 stuff: Dict[int, Callable[[], str]] = { - 1: things # E: Dict entry 0 has incompatible type "int": "Callable[[], int]"; expected "int": "Callable[[], str]" + 1: things # E: Dict entry 0 has incompatible type "int": "() -> int"; expected "int": "() -> str" } [builtins fixtures/dict.pyi] diff --git a/test-data/unit/check-flags.test b/test-data/unit/check-flags.test index c6419923ebc6..8bb903060ca5 100644 --- a/test-data/unit/check-flags.test +++ b/test-data/unit/check-flags.test @@ -1059,7 +1059,7 @@ def foo(f: Callable[[], Unchecked]) -> Tuple[Unchecked]: [builtins fixtures/list.pyi] [out] main:5: error: Return type becomes "Tuple[Any]" due to an unfollowed import -main:5: error: Argument 1 to "foo" becomes "Callable[[], Any]" due to an unfollowed import +main:5: error: Argument 1 to "foo" becomes "() -> Any" due to an unfollowed import [case testDisallowImplicitAnySubclassingExplicitAny] # flags: --ignore-missing-imports --disallow-any-unimported --disallow-subclassing-any @@ -1147,7 +1147,7 @@ def d(f) -> Callable[..., None]: return f @d -def g(i: int, s: str) -> None: pass # E: Type of decorated function contains type "Any" ("Callable[..., None]") +def g(i: int, s: str) -> None: pass # E: Type of decorated function contains type "Any" ("(..., None)") [builtins fixtures/list.pyi] [case testDisallowAnyDecoratedNonexistentDecorator] @@ -1167,13 +1167,13 @@ def d2(f) -> Callable[[int], List[Any]]: pass def d3(f) -> Callable[[Any], List[str]]: pass @d -def f(i: int, s: str) -> None: # E: Type of decorated function contains type "Any" ("Callable[[int, Any], Any]") +def f(i: int, s: str) -> None: # E: Type of decorated function contains type "Any" ("(int, Any) -> Any") pass @d2 -def g(i: int) -> None: # E: Type of decorated function contains type "Any" ("Callable[[int], List[Any]]") +def g(i: int) -> None: # E: Type of decorated function contains type "Any" ("(int) -> List[Any]") pass @d3 -def h(i: int) -> None: # E: Type of decorated function contains type "Any" ("Callable[[Any], List[str]]") +def h(i: int) -> None: # E: Type of decorated function contains type "Any" ("(Any) -> List[str]") pass [builtins fixtures/list.pyi] diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index b8a02a1ec7d4..b8c66b361a24 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -86,13 +86,13 @@ f: Callable[[B], A] g: Callable[[A], A] # subtype of f h: Callable[[B], B] # subtype of f if int(): - g = h # E: Incompatible types in assignment (expression has type "Callable[[B], B]", variable has type "Callable[[A], A]") + g = h # E: Incompatible types in assignment (expression has type "(B) -> B", variable has type "(A) -> A") if int(): - h = f # E: Incompatible types in assignment (expression has type "Callable[[B], A]", variable has type "Callable[[B], B]") + h = f # E: Incompatible types in assignment (expression has type "(B) -> A", variable has type "(B) -> B") if int(): - h = g # E: Incompatible types in assignment (expression has type "Callable[[A], A]", variable has type "Callable[[B], B]") + h = g # E: Incompatible types in assignment (expression has type "(A) -> A", variable has type "(B) -> B") if int(): - g = f # E: Incompatible types in assignment (expression has type "Callable[[B], A]", variable has type "Callable[[A], A]") + g = f # E: Incompatible types in assignment (expression has type "(B) -> A", variable has type "(A) -> A") if int(): f = g if int(): @@ -108,13 +108,13 @@ if int(): def l(x) -> None: ... def r(__, *, x) -> None: ... -r = l # E: Incompatible types in assignment (expression has type "Callable[[Any], None]", variable has type "Callable[[Any, NamedArg(Any, 'x')], None]") +r = l # E: Incompatible types in assignment (expression has type "(Any) -> None", variable has type "(Any, x: Any) -> None") [case testSubtypingFunctionsRequiredLeftArgNotPresent] def l(x, y) -> None: ... def r(x) -> None: ... -r = l # E: Incompatible types in assignment (expression has type "Callable[[Any, Any], None]", variable has type "Callable[[Any], None]") +r = l # E: Incompatible types in assignment (expression has type "(Any, Any) -> None", variable has type "(Any) -> None") [case testSubtypingFunctionsImplicitNames] from typing import Any @@ -148,13 +148,13 @@ if int(): if int(): ff_nonames = f_nonames # reset if int(): - ff = ff_nonames # E: Incompatible types in assignment (expression has type "Callable[[int, str], None]", variable has type "Callable[[Arg(int, 'a'), Arg(str, 'b')], None]") + ff = ff_nonames # E: Incompatible types in assignment (expression has type "(int, str) -> None", variable has type "(a: int, b: str) -> None") if int(): ff = f # reset if int(): - gg = ff # E: Incompatible types in assignment (expression has type "Callable[[Arg(int, 'a'), Arg(str, 'b')], None]", variable has type "Callable[[Arg(int, 'a'), DefaultArg(str, 'b')], None]") + gg = ff # E: Incompatible types in assignment (expression has type "(a: int, b: str) -> None", variable has type "(a: int, b: str) -> None") if int(): - gg = hh # E: Incompatible types in assignment (expression has type "Callable[[Arg(int, 'aa'), DefaultArg(str, 'b')], None]", variable has type "Callable[[Arg(int, 'a'), DefaultArg(str, 'b')], None]") + gg = hh # E: Incompatible types in assignment (expression has type "(aa: int, b: str) -> None", variable has type "(a: int, b: str) -> None") [case testSubtypingFunctionsArgsKwargs] from typing import Any, Callable @@ -223,7 +223,7 @@ gg = g if int(): ff = g if int(): - gg = f # E: Incompatible types in assignment (expression has type "Callable[[int, str], None]", variable has type "Callable[[Arg(int, 'a'), Arg(str, 'b')], None]") + gg = f # E: Incompatible types in assignment (expression has type "(int, str) -> None", variable has type "(a: int, b: str) -> None") [case testLackOfNamesFastparse] def f(__a: int, __b: str) -> None: pass @@ -235,7 +235,7 @@ gg = g if int(): ff = g if int(): - gg = f # E: Incompatible types in assignment (expression has type "Callable[[int, str], None]", variable has type "Callable[[Arg(int, 'a'), Arg(str, 'b')], None]") + gg = f # E: Incompatible types in assignment (expression has type "(int, str) -> None", variable has type "(a: int, b: str) -> None") [case testFunctionTypeCompatibilityWithOtherTypes] # flags: --no-strict-optional @@ -243,11 +243,11 @@ from typing import Callable f = None # type: Callable[[], None] a, o = None, None # type: (A, object) if int(): - a = f # E: Incompatible types in assignment (expression has type "Callable[[], None]", variable has type "A") + a = f # E: Incompatible types in assignment (expression has type "() -> None", variable has type "A") if int(): - f = a # E: Incompatible types in assignment (expression has type "A", variable has type "Callable[[], None]") + f = a # E: Incompatible types in assignment (expression has type "A", variable has type "() -> None") if int(): - f = o # E: Incompatible types in assignment (expression has type "object", variable has type "Callable[[], None]") + f = o # E: Incompatible types in assignment (expression has type "object", variable has type "() -> None") if int(): f = f() # E: Function does not return a value (it only ever returns None) @@ -276,7 +276,7 @@ from typing import Callable f: Callable[[], None] g: Callable[[], object] if int(): - f = g # E: Incompatible types in assignment (expression has type "Callable[[], object]", variable has type "Callable[[], None]") + f = g # E: Incompatible types in assignment (expression has type "() -> object", variable has type "() -> None") if int(): g = f # OK @@ -291,11 +291,11 @@ f: Callable[[A, A], None] g: Callable[[A, B], None] h: Callable[[B, B], None] if int(): - f = g # E: Incompatible types in assignment (expression has type "Callable[[A, B], None]", variable has type "Callable[[A, A], None]") + f = g # E: Incompatible types in assignment (expression has type "(A, B) -> None", variable has type "(A, A) -> None") if int(): - f = h # E: Incompatible types in assignment (expression has type "Callable[[B, B], None]", variable has type "Callable[[A, A], None]") + f = h # E: Incompatible types in assignment (expression has type "(B, B) -> None", variable has type "(A, A) -> None") if int(): - g = h # E: Incompatible types in assignment (expression has type "Callable[[B, B], None]", variable has type "Callable[[A, B], None]") + g = h # E: Incompatible types in assignment (expression has type "(B, B) -> None", variable has type "(A, B) -> None") if int(): g = f if int(): @@ -319,13 +319,13 @@ g: Callable[[A], None] h: Callable[[A, A], None] if int(): - f = g # E: Incompatible types in assignment (expression has type "Callable[[A], None]", variable has type "Callable[[], None]") + f = g # E: Incompatible types in assignment (expression has type "(A) -> None", variable has type "() -> None") if int(): - f = h # E: Incompatible types in assignment (expression has type "Callable[[A, A], None]", variable has type "Callable[[], None]") + f = h # E: Incompatible types in assignment (expression has type "(A, A) -> None", variable has type "() -> None") if int(): - h = f # E: Incompatible types in assignment (expression has type "Callable[[], None]", variable has type "Callable[[A, A], None]") + h = f # E: Incompatible types in assignment (expression has type "() -> None", variable has type "(A, A) -> None") if int(): - h = g # E: Incompatible types in assignment (expression has type "Callable[[A], None]", variable has type "Callable[[A, A], None]") + h = g # E: Incompatible types in assignment (expression has type "(A) -> None", variable has type "(A, A) -> None") if int(): f = f @@ -349,7 +349,7 @@ a: A if int(): a = A # E: Incompatible types in assignment (expression has type "Type[A]", variable has type "A") if int(): - t = f # E: Incompatible types in assignment (expression has type "Callable[[], None]", variable has type "type") + t = f # E: Incompatible types in assignment (expression has type "() -> None", variable has type "type") if int(): t = A @@ -362,7 +362,7 @@ g: Callable[[B], B] h: Callable[[A], AA] if int(): - h = i # E: Incompatible types in assignment (expression has type overloaded function, variable has type "Callable[[A], AA]") + h = i # E: Incompatible types in assignment (expression has type overloaded function, variable has type "(A) -> AA") if int(): f = j @@ -411,7 +411,7 @@ if int(): if int(): b = f(c) # E: Incompatible types in assignment (expression has type "C", variable has type "B") if int(): - g4 = f # E: Incompatible types in assignment (expression has type overloaded function, variable has type "Callable[[A], B]") + g4 = f # E: Incompatible types in assignment (expression has type overloaded function, variable has type "(A) -> B") if int(): g1 = f @@ -442,10 +442,10 @@ def f(x: C) -> C: pass from typing import Any, Callable, List def f(fields: List[Callable[[Any], Any]]): pass class C: pass -f([C]) # E: List item 0 has incompatible type "Type[C]"; expected "Callable[[Any], Any]" +f([C]) # E: List item 0 has incompatible type "Type[C]"; expected "(Any) -> Any" class D: def __init__(self, a, b): pass -f([D]) # E: List item 0 has incompatible type "Type[D]"; expected "Callable[[Any], Any]" +f([D]) # E: List item 0 has incompatible type "Type[D]"; expected "(Any) -> Any" [builtins fixtures/list.pyi] [case testSubtypingTypeTypeAsCallable] @@ -461,7 +461,7 @@ class A: pass x: Callable[..., A] y: Type[A] if int(): - y = x # E: Incompatible types in assignment (expression has type "Callable[..., A]", variable has type "Type[A]") + y = x # E: Incompatible types in assignment (expression has type "(..., A)", variable has type "Type[A]") -- Default argument values -- ----------------------- @@ -594,8 +594,8 @@ class A: f = x # type: ClassVar[Callable[[], None]] g = x # type: ClassVar[Callable[[B], None]] a: A -a.f() # E: Attribute function "f" with type "Callable[[], None]" does not accept self argument -a.g() # E: Invalid self argument "A" to attribute function "g" with type "Callable[[B], None]" +a.f() # E: Attribute function "f" with type "() -> None" does not accept self argument +a.g() # E: Invalid self argument "A" to attribute function "g" with type "(B) -> None" [case testMethodWithDynamicallyTypedMethodAsDataAttribute] from typing import Any, Callable, ClassVar @@ -670,7 +670,7 @@ class A(Generic[t]): ab: A[B] ac: A[C] ab.f() -ac.f() # E: Invalid self argument "A[C]" to attribute function "f" with type "Callable[[A[B]], None]" +ac.f() # E: Invalid self argument "A[C]" to attribute function "f" with type "(A[B]) -> None" [case testPartiallyTypedSelfInMethodDataAttribute] from typing import Any, TypeVar, Generic, Callable, ClassVar @@ -806,8 +806,8 @@ def f() -> None: g(1) g.x # E [out] -main:7: error: "Callable[..., Any]" has no attribute "x" -main:11: error: "Callable[..., Any]" has no attribute "x" +main:7: error: "(..., Any)" has no attribute "x" +main:11: error: "(..., Any)" has no attribute "x" [case testNestedGenericFunctions] from typing import TypeVar @@ -916,7 +916,7 @@ f(None) # E: Too many arguments for "f" from typing import Any, Callable def dec1(f: Callable[[Any], None]) -> Callable[[], None]: pass def dec2(f: Callable[[Any, Any], None]) -> Callable[[Any], None]: pass -@dec1 # E: Argument 1 to "dec2" has incompatible type "Callable[[Any], Any]"; expected "Callable[[Any, Any], None]" +@dec1 # E: Argument 1 to "dec2" has incompatible type "(Any) -> Any"; expected "(Any, Any) -> None" @dec2 def f(x): pass @@ -924,7 +924,7 @@ def f(x): pass from typing import Any, Callable def dec1(f: Callable[[Any, Any], None]) -> Callable[[], None]: pass def dec2(f: Callable[[Any, Any], None]) -> Callable[[Any], None]: pass -@dec1 # E: Argument 1 to "dec1" has incompatible type "Callable[[Any], None]"; expected "Callable[[Any, Any], None]" +@dec1 # E: Argument 1 to "dec1" has incompatible type "(Any) -> None"; expected "(Any, Any) -> None" @dec2 def f(x, y): pass @@ -1464,7 +1464,7 @@ if x: @dec def f(): pass else: - def f(x: str) -> None: pass # E: Incompatible redefinition (redefinition with type "Callable[[str], None]", original type "Callable[[int], None]") + def f(x: str) -> None: pass # E: Incompatible redefinition (redefinition with type "(str) -> None", original type "(int) -> None") [case testConditionalFunctionDefinitionUsingDecorator3] @@ -1507,7 +1507,7 @@ def baz() -> None: if False: foo: int = 1 else: - def foo(obj): ... # E: Incompatible redefinition (redefinition with type "Callable[[Any], Any]", original type "int") + def foo(obj): ... # E: Incompatible redefinition (redefinition with type "(Any) -> Any", original type "int") [builtins fixtures/tuple.pyi] [case testConditionalRedefinitionOfAnUnconditionalFunctionDefinition1] @@ -1564,7 +1564,7 @@ def g() -> None: def g(): pass f = g if g(): - def f(x): pass # E: Incompatible redefinition (redefinition with type "Callable[[Any], Any]", original type "Callable[[], Any]") + def f(x): pass # E: Incompatible redefinition (redefinition with type "(Any) -> Any", original type "() -> Any") [case testRedefineFunctionDefinedAsVariableWithVariance1] class B: pass @@ -1993,12 +1993,12 @@ def isf_unnamed(__i: int, __s: str) -> str: int_str_fun = isf int_str_fun = isf_unnamed -int_named_str_fun = isf_unnamed # E: Incompatible types in assignment (expression has type "Callable[[int, str], str]", variable has type "Callable[[int, Arg(str, 's')], str]") +int_named_str_fun = isf_unnamed # E: Incompatible types in assignment (expression has type "(int, str) -> str", variable has type "(int, s: str) -> str") int_opt_str_fun = iosf int_str_fun = iosf -int_opt_str_fun = isf # E: Incompatible types in assignment (expression has type "Callable[[Arg(int, 'ii'), Arg(str, 'ss')], str]", variable has type "Callable[[int, DefaultArg(str)], str]") +int_opt_str_fun = isf # E: Incompatible types in assignment (expression has type "(ii: int, ss: str) -> str", variable has type "(int, str) -> str") -int_named_str_fun = isf # E: Incompatible types in assignment (expression has type "Callable[[Arg(int, 'ii'), Arg(str, 'ss')], str]", variable has type "Callable[[int, Arg(str, 's')], str]") +int_named_str_fun = isf # E: Incompatible types in assignment (expression has type "(ii: int, ss: str) -> str", variable has type "(int, s: str) -> str") int_named_str_fun = iosf [builtins fixtures/dict.pyi] @@ -2031,7 +2031,7 @@ f(x=4) + '' # E: Unsupported operand types for + ("int" and "str") from typing import Callable def f(x: Callable[..., int]) -> None: if int(): - x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Callable[..., int]") + x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "(..., int)") [out] [case testCallableWithArbitraryArgsInGenericFunction] @@ -2053,7 +2053,7 @@ def g4(*, y: int) -> str: pass f(g1) f(g2) f(g3) -f(g4) # E: Argument 1 to "f" has incompatible type "Callable[[NamedArg(int, 'y')], str]"; expected "Callable[..., int]" +f(g4) # E: Argument 1 to "f" has incompatible type "(y: int) -> str"; expected "(..., int)" [case testCallableWithArbitraryArgsSubtypingWithGenericFunc] from typing import Callable, TypeVar @@ -2215,8 +2215,8 @@ def g(x, y): pass def h(x): pass def j(y) -> Any: pass f = h -f = j # E: Incompatible types in assignment (expression has type "Callable[[Arg(Any, 'y')], Any]", variable has type "Callable[[Arg(Any, 'x')], Any]") -f = g # E: Incompatible types in assignment (expression has type "Callable[[Any, Any], Any]", variable has type "Callable[[Any], Any]") +f = j # E: Incompatible types in assignment (expression has type "(y: Any) -> Any", variable has type "(x: Any) -> Any") +f = g # E: Incompatible types in assignment (expression has type "(Any, Any) -> Any", variable has type "(Any) -> Any") [case testRedefineFunction2] def f() -> None: pass @@ -3361,7 +3361,7 @@ class Foo: class Bar(Foo): @property - def method(self) -> Callable[[int, A], None]: # E: Argument 2 of "method" is incompatible with supertype "Foo"; supertype defines the argument type as "Union[Callable[[C], None], Callable[[D], None]]" \ + def method(self) -> Callable[[int, A], None]: # E: Argument 2 of "method" is incompatible with supertype "Foo"; supertype defines the argument type as "Union[(C) -> None, (D) -> None]" \ # N: This violates the Liskov substitution principle \ # N: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides ... diff --git a/test-data/unit/check-functools.test b/test-data/unit/check-functools.test index 636eca22c83d..4b380ea3931f 100644 --- a/test-data/unit/check-functools.test +++ b/test-data/unit/check-functools.test @@ -161,8 +161,8 @@ reveal_type(p1) # N: Revealed type is "functools.partial[builtins.int]" def takes_callable_int(f: Callable[..., int]) -> None: ... def takes_callable_str(f: Callable[..., str]) -> None: ... takes_callable_int(p1) -takes_callable_str(p1) # E: Argument 1 to "takes_callable_str" has incompatible type "partial[int]"; expected "Callable[..., str]" \ - # N: "partial[int].__call__" has type "Callable[[VarArg(Any), KwArg(Any)], int]" +takes_callable_str(p1) # E: Argument 1 to "takes_callable_str" has incompatible type "partial[int]"; expected "(..., str)" \ + # N: "partial[int].__call__" has type "(Any, Any) -> int" p2 = functools.partial(foo, 1) p2("a") # OK @@ -186,7 +186,7 @@ functools.partial(foo, "a") # E: Argument 1 to "foo" has incompatible type "str functools.partial(foo, b=1) # E: Argument "b" to "foo" has incompatible type "int"; expected "str" functools.partial(foo, a=1, b=2, c=3) # E: Argument "b" to "foo" has incompatible type "int"; expected "str" functools.partial(1) # E: "int" not callable \ - # E: Argument 1 to "partial" has incompatible type "int"; expected "Callable[..., Never]" + # E: Argument 1 to "partial" has incompatible type "int"; expected "(..., Never)" [builtins fixtures/dict.pyi] [case testFunctoolsPartialStar] @@ -353,7 +353,7 @@ reveal_type(functools.partial(fn2, 2)()) # N: Revealed type is "Union[builtins. fn3: Union[Callable[[int], int], str] reveal_type(functools.partial(fn3, 2)()) # E: "str" not callable \ # N: Revealed type is "builtins.int" \ - # E: Argument 1 to "partial" has incompatible type "Union[Callable[[int], int], str]"; expected "(..., int)" + # E: Argument 1 to "partial" has incompatible type "Union[(int) -> int, str]"; expected "(..., int)" [builtins fixtures/tuple.pyi] [case testFunctoolsPartialUnionOfTypeAndCallable] diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index b8cc0422b749..3cdee6ea679a 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -863,9 +863,9 @@ reveal_type(make_cb(1)) # N: Revealed type is "def (*Any, **Any) -> builtins.int def use_cb(arg: T, cb: C2[T]) -> Node[T]: return cb(arg, arg) -use_cb(1, 1) # E: Argument 2 to "use_cb" has incompatible type "int"; expected "Callable[[int, int], Node[int]]" +use_cb(1, 1) # E: Argument 2 to "use_cb" has incompatible type "int"; expected "(int, int) -> Node[int]" my_cb: C2[int] -use_cb('x', my_cb) # E: Argument 2 to "use_cb" has incompatible type "Callable[[int, int], Node[int]]"; expected "Callable[[str, str], Node[str]]" +use_cb('x', my_cb) # E: Argument 2 to "use_cb" has incompatible type "(int, int) -> Node[int]"; expected "(str, str) -> Node[str]" reveal_type(use_cb(1, my_cb)) # N: Revealed type is "__main__.Node[builtins.int]" [builtins fixtures/tuple.pyi] @@ -1423,7 +1423,7 @@ T = TypeVar('T') a: A[object, Callable[[], None]] def f(a: 'B') -> None: pass -f(a) # E: Argument 1 to "f" has incompatible type "A[object, Callable[[], None]]"; expected "B" +f(a) # E: Argument 1 to "f" has incompatible type "A[object, () -> None]"; expected "B" class A(Generic[S, T]): pass class B: pass @@ -1612,17 +1612,17 @@ if int(): if int(): y1 = f3 if int(): - y1 = f4 # E: Incompatible types in assignment (expression has type "Callable[[int], A@f4]", variable has type "Callable[[A@f1], A@f1]") + y1 = f4 # E: Incompatible types in assignment (expression has type "(int) -> A@f4", variable has type "(A@f1) -> A@f1") y2 = f2 if int(): y2 = f2 if int(): - y2 = f1 # E: Incompatible types in assignment (expression has type "Callable[[A@f1], A@f1]", variable has type "Callable[[A@f2], B]") + y2 = f1 # E: Incompatible types in assignment (expression has type "(A@f1) -> A@f1", variable has type "(A@f2) -> B") if int(): - y2 = f3 # E: Incompatible types in assignment (expression has type "Callable[[B@f3], B@f3]", variable has type "Callable[[A], B@f2]") + y2 = f3 # E: Incompatible types in assignment (expression has type "(B@f3) -> B@f3", variable has type "(A) -> B@f2") if int(): - y2 = f4 # E: Incompatible types in assignment (expression has type "Callable[[int], A@f4]", variable has type "Callable[[A@f2], B]") + y2 = f4 # E: Incompatible types in assignment (expression has type "(int) -> A@f4", variable has type "(A@f2) -> B") y3 = f3 if int(): @@ -1632,17 +1632,17 @@ if int(): if int(): y3 = f2 if int(): - y3 = f4 # E: Incompatible types in assignment (expression has type "Callable[[int], A]", variable has type "Callable[[B], B]") + y3 = f4 # E: Incompatible types in assignment (expression has type "(int) -> A", variable has type "(B) -> B") y4 = f4 if int(): y4 = f4 if int(): - y4 = f1 # E: Incompatible types in assignment (expression has type "Callable[[A@f1], A@f1]", variable has type "Callable[[int], A@f4]") + y4 = f1 # E: Incompatible types in assignment (expression has type "(A@f1) -> A@f1", variable has type "(int) -> A@f4") if int(): y4 = f2 if int(): - y4 = f3 # E: Incompatible types in assignment (expression has type "Callable[[B], B]", variable has type "Callable[[int], A]") + y4 = f3 # E: Incompatible types in assignment (expression has type "(B) -> B", variable has type "(int) -> A") [case testSubtypingWithGenericInnerFunctions] from typing import TypeVar @@ -1659,27 +1659,27 @@ def outer(t: T) -> None: y1 = f1 if int(): y1 = f2 - y1 = f3 # E: Incompatible types in assignment (expression has type "Callable[[T], A@f3]", variable has type "Callable[[A@f1], A@f1]") - y1 = f4 # E: Incompatible types in assignment (expression has type "Callable[[A@f4], T]", variable has type "Callable[[A@f1], A@f1]") - y1 = f5 # E: Incompatible types in assignment (expression has type "Callable[[T], T]", variable has type "Callable[[A], A]") + y1 = f3 # E: Incompatible types in assignment (expression has type "(T) -> A@f3", variable has type "(A@f1) -> A@f1") + y1 = f4 # E: Incompatible types in assignment (expression has type "(A@f4) -> T", variable has type "(A@f1) -> A@f1") + y1 = f5 # E: Incompatible types in assignment (expression has type "(T) -> T", variable has type "(A) -> A") y2 = f2 if int(): - y2 = f1 # E: Incompatible types in assignment (expression has type "Callable[[A@f1], A@f1]", variable has type "Callable[[A@f2], B]") + y2 = f1 # E: Incompatible types in assignment (expression has type "(A@f1) -> A@f1", variable has type "(A@f2) -> B") y3 = f3 if int(): - y3 = f1 # E: Incompatible types in assignment (expression has type "Callable[[A@f1], A@f1]", variable has type "Callable[[T], A@f3]") + y3 = f1 # E: Incompatible types in assignment (expression has type "(A@f1) -> A@f1", variable has type "(T) -> A@f3") y3 = f2 - y3 = f4 # E: Incompatible types in assignment (expression has type "Callable[[A@f4], T]", variable has type "Callable[[T], A@f3]") - y3 = f5 # E: Incompatible types in assignment (expression has type "Callable[[T], T]", variable has type "Callable[[T], A]") + y3 = f4 # E: Incompatible types in assignment (expression has type "(A@f4) -> T", variable has type "(T) -> A@f3") + y3 = f5 # E: Incompatible types in assignment (expression has type "(T) -> T", variable has type "(T) -> A") y4 = f4 if int(): - y4 = f1 # E: Incompatible types in assignment (expression has type "Callable[[A@f1], A@f1]", variable has type "Callable[[A@f4], T]") + y4 = f1 # E: Incompatible types in assignment (expression has type "(A@f1) -> A@f1", variable has type "(A@f4) -> T") y4 = f2 - y4 = f3 # E: Incompatible types in assignment (expression has type "Callable[[T], A@f3]", variable has type "Callable[[A@f4], T]") - y4 = f5 # E: Incompatible types in assignment (expression has type "Callable[[T], T]", variable has type "Callable[[A], T]") + y4 = f3 # E: Incompatible types in assignment (expression has type "(T) -> A@f3", variable has type "(A@f4) -> T") + y4 = f5 # E: Incompatible types in assignment (expression has type "(T) -> T", variable has type "(A) -> T") y5 = f5 if int(): @@ -1697,8 +1697,8 @@ g1(f) def g2(f: Callable[[int], int]) -> None: pass g2(f) def g3(f: Callable[[object], object]) -> None: pass -g3(f) # E: Argument 1 to "g3" has incompatible type "Callable[[T], T]"; \ - expected "Callable[[object], object]" +g3(f) # E: Argument 1 to "g3" has incompatible type "(T) -> T"; \ + expected "(object) -> object" [case testSubtypingWithGenericFunctionUsingTypevarWithValues2] from typing import TypeVar, Callable @@ -1771,7 +1771,7 @@ T = TypeVar('T') class C(Generic[T]): def __init__(self) -> None: pass x = C # type: Callable[[], C[int]] -y = C # type: Callable[[], int] # E: Incompatible types in assignment (expression has type "Type[C[Any]]", variable has type "Callable[[], int]") +y = C # type: Callable[[], int] # E: Incompatible types in assignment (expression has type "Type[C[Any]]", variable has type "() -> int") -- Special cases @@ -2305,7 +2305,7 @@ class Box(Generic[T]): class IteratorBox(Box[Iterator[T]]): ... -@IteratorBox.wrap # E: Argument 1 to "wrap" of "Box" has incompatible type "Callable[[], int]"; expected "Callable[[], Iterator[Never]]" +@IteratorBox.wrap # E: Argument 1 to "wrap" of "Box" has incompatible type "() -> int"; expected "() -> Iterator[Never]" def g() -> int: ... [builtins fixtures/classmethod.pyi] @@ -3074,7 +3074,7 @@ reveal_type(dec1(id1)) # N: Revealed type is "def [S <: __main__.B] (S`1) -> bu reveal_type(dec1(id2)) # N: Revealed type is "def [S in (builtins.int, builtins.str)] (S`3) -> builtins.list[S`3]" reveal_type(dec2(id1)) # N: Revealed type is "def [UC <: __main__.C] (UC`5) -> builtins.list[UC`5]" reveal_type(dec2(id2)) # N: Revealed type is "def (Never) -> builtins.list[Never]" \ - # E: Argument 1 to "dec2" has incompatible type "Callable[[V], V]"; expected "Callable[[Never], Never]" + # E: Argument 1 to "dec2" has incompatible type "(V) -> V"; expected "(Never) -> Never" [case testInferenceAgainstGenericLambdas] # flags: --new-type-inference @@ -3509,7 +3509,7 @@ class Proto(Protocol[P, R]): @overload def __call__(self, f: Callable[P2, R2]) -> C[P2, R2, ..., R]: ... @overload - def __call__(self, **kwargs) -> C[P, R, ..., ...]: ... # E: Cannot use "[VarArg(Any), KwArg(Any)]" for regular type variable, only for ParamSpec + def __call__(self, **kwargs) -> C[P, R, ..., ...]: ... # E: Cannot use "[Any, Any]" for regular type variable, only for ParamSpec [builtins fixtures/tuple.pyi] [case testGenericOverloadOverlapUnion] diff --git a/test-data/unit/check-incremental.test b/test-data/unit/check-incremental.test index 888b4c26a7c7..686510dc0a5c 100644 --- a/test-data/unit/check-incremental.test +++ b/test-data/unit/check-incremental.test @@ -6639,8 +6639,8 @@ p3 = functools.partial(foo, b="a") [builtins fixtures/dict.pyi] [out] tmp/a.py:8: note: Revealed type is "functools.partial[builtins.int]" -tmp/a.py:13: error: Argument 1 to "takes_callable_str" has incompatible type "partial[int]"; expected "Callable[..., str]" -tmp/a.py:13: note: "partial[int].__call__" has type "Callable[[VarArg(Any), KwArg(Any)], int]" +tmp/a.py:13: error: Argument 1 to "takes_callable_str" has incompatible type "partial[int]"; expected "(..., str)" +tmp/a.py:13: note: "partial[int].__call__" has type "(Any, Any) -> int" tmp/a.py:18: error: Argument 1 to "foo" has incompatible type "int"; expected "str" tmp/a.py:19: error: Too many arguments for "foo" tmp/a.py:19: error: Argument 1 to "foo" has incompatible type "int"; expected "str" diff --git a/test-data/unit/check-inference-context.test b/test-data/unit/check-inference-context.test index 17ae6d9934b7..2ad427218cb8 100644 --- a/test-data/unit/check-inference-context.test +++ b/test-data/unit/check-inference-context.test @@ -662,9 +662,9 @@ f2 = lambda: A() # type: Callable[[A], A] class A: pass [out] main:2: error: Cannot infer type of lambda -main:2: error: Incompatible types in assignment (expression has type "Callable[[Any], A]", variable has type "Callable[[], A]") +main:2: error: Incompatible types in assignment (expression has type "(Any) -> A", variable has type "() -> A") main:3: error: Cannot infer type of lambda -main:3: error: Incompatible types in assignment (expression has type "Callable[[], A]", variable has type "Callable[[A], A]") +main:3: error: Incompatible types in assignment (expression has type "() -> A", variable has type "(A) -> A") [case testEllipsisContextForLambda] from typing import Callable @@ -675,7 +675,7 @@ f4 = lambda x: x # type: Callable[..., int] g = lambda x: 1 # type: Callable[..., str] [builtins fixtures/dict.pyi] [out] -main:6: error: Incompatible types in assignment (expression has type "Callable[[Any], int]", variable has type "Callable[..., str]") +main:6: error: Incompatible types in assignment (expression has type "(Any) -> int", variable has type "(..., str)") main:6: error: Incompatible return value type (got "int", expected "str") [case testEllipsisContextForLambda2] @@ -705,7 +705,7 @@ reveal_type(f(lambda x: 0 if isinstance(x, B) else 1)) # N: Revealed type is "U f(lambda x: 0 if isinstance(x, B) else 1, A())() # E: "int" not callable f(lambda x: x if isinstance(x, B) else B(), A(), r=B())() # E: "B" not callable f( - lambda x: # E: Argument 1 to "f" has incompatible type "Callable[[A], A]"; expected "Callable[[A], B]" + lambda x: # E: Argument 1 to "f" has incompatible type "(A) -> A"; expected "(A) -> B" B() if isinstance(x, B) else x, # E: Incompatible return value type (got "A", expected "B") A(), r=B()) [builtins fixtures/isinstance.pyi] @@ -892,7 +892,7 @@ S = TypeVar('S') def f(a: T, b: S) -> None: c = lambda x: x # type: Callable[[T], S] [out] -main:5: error: Incompatible types in assignment (expression has type "Callable[[T], T]", variable has type "Callable[[T], S]") +main:5: error: Incompatible types in assignment (expression has type "(T) -> T", variable has type "(T) -> S") main:5: error: Incompatible return value type (got "T", expected "S") [case testLambdaInGenericClass] @@ -903,7 +903,7 @@ class A(Generic[T]): def f(self, b: S) -> None: c = lambda x: x # type: Callable[[T], S] [out] -main:6: error: Incompatible types in assignment (expression has type "Callable[[T], T]", variable has type "Callable[[T], S]") +main:6: error: Incompatible types in assignment (expression has type "(T) -> T", variable has type "(T) -> S") main:6: error: Incompatible return value type (got "T", expected "S") [case testRevealTypeContext] diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index 6b12216dccad..9fa74f35f662 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -2933,7 +2933,7 @@ def f(): pass [file m.py] def f(): pass _ = f -_ = 0 # E: Incompatible types in assignment (expression has type "int", variable has type "Callable[[], Any]") +_ = 0 # E: Incompatible types in assignment (expression has type "int", variable has type "() -> Any") [file a.py] def foo() -> None: import _ @@ -2948,12 +2948,12 @@ def foo() -> None: def foo() -> None: from m import _ _() - _ = '' # E: Incompatible types in assignment (expression has type "str", variable has type "Callable[[], Any]") + _ = '' # E: Incompatible types in assignment (expression has type "str", variable has type "() -> Any") [file d.py] def foo() -> None: from m import f as _ _() - _ = 0 # E: Incompatible types in assignment (expression has type "int", variable has type "Callable[[], Any]") + _ = 0 # E: Incompatible types in assignment (expression has type "int", variable has type "() -> Any") [builtins fixtures/module.pyi] [case testUnderscoreClass] @@ -3677,8 +3677,8 @@ def f(x: Call[T]) -> Tuple[T, T]: ... def g(__x: str) -> None: pass reveal_type(f(g)) # N: Revealed type is "Tuple[Never, Never]" \ - # E: Argument 1 to "f" has incompatible type "Callable[[str], None]"; expected "Call[Never]" \ - # N: "Call[Never].__call__" has type "Callable[[NamedArg(Never, 'x')], None]" + # E: Argument 1 to "f" has incompatible type "(str) -> None"; expected "Call[Never]" \ + # N: "Call[Never].__call__" has type "(x: Never) -> None" [builtins fixtures/list.pyi] [case testCallableInferenceAgainstCallableNamedVsPosOnly] @@ -3694,8 +3694,8 @@ def f(x: Call[T]) -> Tuple[T, T]: ... def g(*, x: str) -> None: pass reveal_type(f(g)) # N: Revealed type is "Tuple[Never, Never]" \ - # E: Argument 1 to "f" has incompatible type "Callable[[NamedArg(str, 'x')], None]"; expected "Call[Never]" \ - # N: "Call[Never].__call__" has type "Callable[[Never], None]" + # E: Argument 1 to "f" has incompatible type "(x: str) -> None"; expected "Call[Never]" \ + # N: "Call[Never].__call__" has type "(Never) -> None" [builtins fixtures/list.pyi] [case testCallableInferenceAgainstCallablePosOnlyVsKwargs] @@ -3711,8 +3711,8 @@ def f(x: Call[T]) -> Tuple[T, T]: ... def g(**x: str) -> None: pass reveal_type(f(g)) # N: Revealed type is "Tuple[Never, Never]" \ - # E: Argument 1 to "f" has incompatible type "Callable[[KwArg(str)], None]"; expected "Call[Never]" \ - # N: "Call[Never].__call__" has type "Callable[[Never], None]" + # E: Argument 1 to "f" has incompatible type "(str) -> None"; expected "Call[Never]" \ + # N: "Call[Never].__call__" has type "(Never) -> None" [builtins fixtures/list.pyi] [case testCallableInferenceAgainstCallableNamedVsArgs] @@ -3728,8 +3728,8 @@ def f(x: Call[T]) -> Tuple[T, T]: ... def g(*args: str) -> None: pass reveal_type(f(g)) # N: Revealed type is "Tuple[Never, Never]" \ - # E: Argument 1 to "f" has incompatible type "Callable[[VarArg(str)], None]"; expected "Call[Never]" \ - # N: "Call[Never].__call__" has type "Callable[[NamedArg(Never, 'x')], None]" + # E: Argument 1 to "f" has incompatible type "(str) -> None"; expected "Call[Never]" \ + # N: "Call[Never].__call__" has type "(x: Never) -> None" [builtins fixtures/list.pyi] [case testInferenceAgainstTypeVarActualBound] diff --git a/test-data/unit/check-modules.test b/test-data/unit/check-modules.test index 68897790e4bf..3f54af5978de 100644 --- a/test-data/unit/check-modules.test +++ b/test-data/unit/check-modules.test @@ -572,7 +572,7 @@ x = 1 # input, which is maybe better, but no error about f, which seems # wrong) from m import * -f = None # E: Incompatible types in assignment (expression has type "None", variable has type "Callable[[], Any]") +f = None # E: Incompatible types in assignment (expression has type "None", variable has type "() -> Any") x = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int") [file m.py] def f(): pass @@ -650,11 +650,11 @@ x = '' def f(x): pass def g(x): pass try: - from m import f, g # E: Incompatible import of "g" (imported name has type "Callable[[Any, Any], Any]", local name has type "Callable[[Any], Any]") + from m import f, g # E: Incompatible import of "g" (imported name has type "(Any, Any) -> Any", local name has type "(Any) -> Any") except: pass -import m as f # E: Incompatible import of "f" (imported name has type "object", local name has type "Callable[[Any], Any]") +import m as f # E: Incompatible import of "f" (imported name has type "object", local name has type "(Any) -> Any") [file m.py] def f(x): pass @@ -707,7 +707,7 @@ def f(x): pass try: from m import f except: - f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Callable[[], Any]") + f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "() -> Any") [file m.py] def f(): pass @@ -719,7 +719,7 @@ def g() -> None: global f f = None if int(): - f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Callable[[], Any]") + f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "() -> Any") [file m.py] def f(): pass [out] @@ -728,7 +728,7 @@ def f(): pass # flags: --no-strict-optional import m.n m.n.f = None -m.n.f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Callable[[], Any]") +m.n.f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "() -> Any") [file m/__init__.py] [file m/n.py] def f(): pass @@ -738,7 +738,7 @@ def f(): pass # flags: --no-strict-optional import m m.f = None -m.f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Callable[[], Any]") +m.f = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "() -> Any") [file m.py] def f(): pass [out] @@ -1049,7 +1049,7 @@ def y() -> str: return "foo" class z: pass [out] main:2: error: Incompatible import of "x" (imported name has type "str", local name has type "int") -main:2: error: Incompatible import of "y" (imported name has type "Callable[[], str]", local name has type "Callable[[], int]") +main:2: error: Incompatible import of "y" (imported name has type "() -> str", local name has type "() -> int") main:2: error: Incompatible import of "z" (imported name has type "Type[b.z]", local name has type "Type[a.z]") -- Misc @@ -2047,7 +2047,7 @@ reveal_type(has_getattr.any_attribute) def __getattr__(x: int, y: str) -> str: ... [out] -tmp/has_getattr.pyi:1: error: Invalid signature "Callable[[int, str], str]" for "__getattr__" +tmp/has_getattr.pyi:1: error: Invalid signature "(int, str) -> str" for "__getattr__" main:3: note: Revealed type is "builtins.str" [builtins fixtures/module.pyi] @@ -2162,7 +2162,7 @@ def make_getattr_bad() -> Callable[[], int]: ... __getattr__ = make_getattr_bad() [out] -tmp/non_stub.py:4: error: Invalid signature "Callable[[], int]" for "__getattr__" +tmp/non_stub.py:4: error: Invalid signature "() -> int" for "__getattr__" main:2: note: Revealed type is "builtins.int" [case testModuleLevelGetattrImportedGood] @@ -2186,7 +2186,7 @@ from has_getattr import __getattr__ def __getattr__() -> int: ... [out] -tmp/has_getattr.py:1: error: Invalid signature "Callable[[], int]" for "__getattr__" +tmp/has_getattr.py:1: error: Invalid signature "() -> int" for "__getattr__" main:2: note: Revealed type is "builtins.int" [builtins fixtures/module.pyi] diff --git a/test-data/unit/check-newsemanal.test b/test-data/unit/check-newsemanal.test index 784b9db9f66e..1b9a15a2cc5c 100644 --- a/test-data/unit/check-newsemanal.test +++ b/test-data/unit/check-newsemanal.test @@ -295,7 +295,7 @@ reveal_type(y2) # N: Revealed type is "builtins.int" y3, y4 = y, y if MYPY: # Tweak processing order - from b import f as y3 # E: Incompatible import of "y3" (imported name has type "Callable[[], Any]", local name has type "int") + from b import f as y3 # E: Incompatible import of "y3" (imported name has type "() -> Any", local name has type "int") reveal_type(y3) # N: Revealed type is "builtins.int" [file b.py] @@ -321,7 +321,7 @@ class y2: pass # E: Name "y2" already defined on line 7 reveal_type(y2) # N: Revealed type is "builtins.int" y3, y4 = y, y -from b import f as y3 # E: Incompatible import of "y3" (imported name has type "Callable[[], Any]", local name has type "int") +from b import f as y3 # E: Incompatible import of "y3" (imported name has type "() -> Any", local name has type "int") reveal_type(y3) # N: Revealed type is "builtins.int" [file b.py] diff --git a/test-data/unit/check-optional.test b/test-data/unit/check-optional.test index 683ce0446915..369fa2882c04 100644 --- a/test-data/unit/check-optional.test +++ b/test-data/unit/check-optional.test @@ -434,7 +434,7 @@ def foo(l: List[Callable[[], str]]) -> None: pass def f() -> int: return 42 -foo([f]) # E: List item 0 has incompatible type "Callable[[], int]"; expected "Callable[[], str]" +foo([f]) # E: List item 0 has incompatible type "() -> int"; expected "() -> str" [builtins fixtures/list.pyi] [case testInferEqualsNotOptional] diff --git a/test-data/unit/check-overloading.test b/test-data/unit/check-overloading.test index 9d01ce6bd480..c84d3427abf6 100644 --- a/test-data/unit/check-overloading.test +++ b/test-data/unit/check-overloading.test @@ -1574,7 +1574,7 @@ def f(a: Callable[[], int]) -> None: pass def f(a: str) -> None: pass f(0) # E: No overload variant of "f" matches argument type "int" \ # N: Possible overload variants: \ - # N: def f(a: Callable[[], int]) -> None \ + # N: def f(a: () -> int) -> None \ # N: def f(a: str) -> None [case testCustomRedefinitionDecorator] @@ -6463,7 +6463,7 @@ class D: ... def f1(g: A) -> A: ... if True: @overload # E: Single overload definition, multiple required - def f1(g: B) -> B: ... # E: Incompatible redefinition (redefinition with type "Callable[[B], B]", original type "Callable[[A], A]") + def f1(g: B) -> B: ... # E: Incompatible redefinition (redefinition with type "(B) -> B", original type "(A) -> A") if maybe_true: # E: Condition can't be inferred, unable to merge overloads \ # E: Name "maybe_true" is not defined @overload @@ -6480,14 +6480,14 @@ if True: def f2(g: B) -> B: ... elif maybe_true: # E: Name "maybe_true" is not defined @overload # E: Single overload definition, multiple required - def f2(g: C) -> C: ... # E: Incompatible redefinition (redefinition with type "Callable[[C], C]", original type "Callable[[A], A]") + def f2(g: C) -> C: ... # E: Incompatible redefinition (redefinition with type "(C) -> C", original type "(A) -> A") def f2(g): ... # E: Name "f2" already defined on line 21 @overload # E: Single overload definition, multiple required def f3(g: A) -> A: ... if True: @overload # E: Single overload definition, multiple required - def f3(g: B) -> B: ... # E: Incompatible redefinition (redefinition with type "Callable[[B], B]", original type "Callable[[A], A]") + def f3(g: B) -> B: ... # E: Incompatible redefinition (redefinition with type "(B) -> B", original type "(A) -> A") if True: pass # Some other node @overload # E: Name "f3" already defined on line 32 \ diff --git a/test-data/unit/check-parameter-specification.test b/test-data/unit/check-parameter-specification.test index 7f038b811741..a334d278f9b4 100644 --- a/test-data/unit/check-parameter-specification.test +++ b/test-data/unit/check-parameter-specification.test @@ -347,8 +347,8 @@ def f(c1: C[P], c2: C[P2]) -> None: def g(f: Callable[P, None], g: Callable[P2, None]) -> None: f = f g = g - f = g # E: Incompatible types in assignment (expression has type "Callable[P2, None]", variable has type "Callable[P, None]") - g = f # E: Incompatible types in assignment (expression has type "Callable[P, None]", variable has type "Callable[P2, None]") + f = g # E: Incompatible types in assignment (expression has type "(P2, None)", variable has type "(P, None)") + g = f # E: Incompatible types in assignment (expression has type "(P, None)", variable has type "(P2, None)") [builtins fixtures/dict.pyi] [case testParamSpecJoin] @@ -422,8 +422,8 @@ def g(x: int, y: str) -> None: pass reveal_type(register(lambda: f(1))) # N: Revealed type is "def ()" reveal_type(register(lambda x: f(x), x=1)) # N: Revealed type is "def (x: Literal[1]?)" register(lambda x: f(x)) # E: Cannot infer type of lambda \ - # E: Argument 1 to "register" has incompatible type "Callable[[Any], None]"; expected "Callable[[], None]" -register(lambda x: f(x), y=1) # E: Argument 1 to "register" has incompatible type "Callable[[Arg(int, 'x')], None]"; expected "Callable[[Arg(int, 'y')], None]" + # E: Argument 1 to "register" has incompatible type "(Any) -> None"; expected "() -> None" +register(lambda x: f(x), y=1) # E: Argument 1 to "register" has incompatible type "(x: int) -> None"; expected "(y: int) -> None" reveal_type(register(lambda x: f(x), 1)) # N: Revealed type is "def (Literal[1]?)" reveal_type(register(lambda x, y: g(x, y), 1, "a")) # N: Revealed type is "def (Literal[1]?, Literal['a']?)" reveal_type(register(lambda x, y: g(x, y), 1, y="a")) # N: Revealed type is "def (Literal[1]?, y: Literal['a']?)" @@ -599,14 +599,14 @@ reveal_type(transform(bar)) # N: Revealed type is "def (builtins.str, *args: bui # CASE 4 def expects_int_first(x: Callable[Concatenate[int, P], int]) -> None: ... -@expects_int_first # E: Argument 1 to "expects_int_first" has incompatible type "Callable[[str], int]"; expected "Callable[[int], int]" \ +@expects_int_first # E: Argument 1 to "expects_int_first" has incompatible type "(str) -> int"; expected "(int) -> int" \ # N: This is likely because "one" has named arguments: "x". Consider marking them positional-only def one(x: str) -> int: ... -@expects_int_first # E: Argument 1 to "expects_int_first" has incompatible type "Callable[[NamedArg(int, 'x')], int]"; expected "Callable[[int, NamedArg(int, 'x')], int]" +@expects_int_first # E: Argument 1 to "expects_int_first" has incompatible type "(x: int) -> int"; expected "(int, x: int) -> int" def two(*, x: int) -> int: ... -@expects_int_first # E: Argument 1 to "expects_int_first" has incompatible type "Callable[[KwArg(int)], int]"; expected "Callable[[int, KwArg(int)], int]" +@expects_int_first # E: Argument 1 to "expects_int_first" has incompatible type "(int) -> int"; expected "(int, int) -> int" def three(**kwargs: int) -> int: ... @expects_int_first # Accepted @@ -664,7 +664,7 @@ def f2(c: Callable[P, R]) -> Callable[Concatenate[int, P], R]: f2(lambda x: 42)(42, x=42) [builtins fixtures/paramspec.pyi] [out] -main:17: error: Incompatible return value type (got "Callable[[Arg(int, 'x'), **P], R]", expected "Callable[[int, **P], R]") +main:17: error: Incompatible return value type (got "([x: int, **P], R)", expected "([int, **P], R)") main:17: note: This is likely because "result" has named arguments: "x". Consider marking them positional-only [case testNonStrictParamSpecConcatenateNamedArgs] @@ -762,15 +762,15 @@ def f1(n: str) -> None: ... def f2(b: bytes, i: int) -> None: ... Z[[int]](lambda one, two: None) # E: Cannot infer type of lambda \ - # E: Argument 1 to "Z" has incompatible type "Callable[[Any, Any], None]"; expected "Callable[[int], None]" -Z[[int]](f1) # E: Argument 1 to "Z" has incompatible type "Callable[[str], None]"; expected "Callable[[int], None]" + # E: Argument 1 to "Z" has incompatible type "(Any, Any) -> None"; expected "(int) -> None" +Z[[int]](f1) # E: Argument 1 to "Z" has incompatible type "(str) -> None"; expected "(int) -> None" Z[[]](lambda one: None) # E: Cannot infer type of lambda \ - # E: Argument 1 to "Z" has incompatible type "Callable[[Any], None]"; expected "Callable[[], None]" + # E: Argument 1 to "Z" has incompatible type "(Any) -> None"; expected "() -> None" Z[bytes, str](lambda one: None) # E: Cannot infer type of lambda \ - # E: Argument 1 to "Z" has incompatible type "Callable[[Any], None]"; expected "Callable[[bytes, str], None]" -Z[bytes, str](f2) # E: Argument 1 to "Z" has incompatible type "Callable[[bytes, int], None]"; expected "Callable[[bytes, str], None]" + # E: Argument 1 to "Z" has incompatible type "(Any) -> None"; expected "(bytes, str) -> None" +Z[bytes, str](f2) # E: Argument 1 to "Z" has incompatible type "(bytes, int) -> None"; expected "(bytes, str) -> None" [builtins fixtures/paramspec.pyi] @@ -1040,18 +1040,18 @@ a2 = Job(f1) # and this is not legal def f4(n: bytes) -> None: ... -a1 = f4 # E: Incompatible types in assignment (expression has type "Callable[[bytes], None]", variable has type "Callable[[bool], None]") -a2 = Job(f4) # E: Argument 1 to "Job" has incompatible type "Callable[[bytes], None]"; expected "Callable[[bool], None]" +a1 = f4 # E: Incompatible types in assignment (expression has type "(bytes) -> None", variable has type "(bool) -> None") +a2 = Job(f4) # E: Argument 1 to "Job" has incompatible type "(bytes) -> None"; expected "(bool) -> None" # nor is this: a4: Job[[int]] -a4 = Job(f3) # E: Argument 1 to "Job" has incompatible type "Callable[[bool], None]"; expected "Callable[[int], None]" +a4 = Job(f3) # E: Argument 1 to "Job" has incompatible type "(bool) -> None"; expected "(int) -> None" a4 = Job(f2) a4 = Job(f1) # just like this: a3: Callable[[int], None] -a3 = f3 # E: Incompatible types in assignment (expression has type "Callable[[bool], None]", variable has type "Callable[[int], None]") +a3 = f3 # E: Incompatible types in assignment (expression has type "(bool) -> None", variable has type "(int) -> None") a3 = f2 a3 = f1 [builtins fixtures/paramspec.pyi] @@ -1411,7 +1411,7 @@ def f(n: C[P]) -> C[P]: ... @f def bar(x: int) -> int: ... -@f # E: Argument 1 to "f" has incompatible type "Callable[[int], str]"; expected "Callable[[int], int]" +@f # E: Argument 1 to "f" has incompatible type "(int) -> str"; expected "(int) -> int" def foo(x: int) -> str: ... x: C[[int, str]] @@ -1428,7 +1428,7 @@ P = ParamSpec("P") C = Callable[Concatenate[int, P], int] def f(n: C[P]) -> C[P]: ... -@f # E: Argument 1 to "f" has incompatible type "Callable[[], int]"; expected "Callable[[int], int]" +@f # E: Argument 1 to "f" has incompatible type "() -> int"; expected "(int) -> int" def bad() -> int: ... @f @@ -1438,11 +1438,11 @@ def bar(x: int) -> int: ... def bar2(x: int, y: str) -> int: ... reveal_type(bar2) # N: Revealed type is "def (builtins.int, y: builtins.str) -> builtins.int" -@f # E: Argument 1 to "f" has incompatible type "Callable[[int], str]"; expected "Callable[[int], int]" \ +@f # E: Argument 1 to "f" has incompatible type "(int) -> str"; expected "(int) -> int" \ # N: This is likely because "foo" has named arguments: "x". Consider marking them positional-only def foo(x: int) -> str: ... -@f # E: Argument 1 to "f" has incompatible type "Callable[[str, int], int]"; expected "Callable[[int, int], int]" \ +@f # E: Argument 1 to "f" has incompatible type "(str, int) -> int"; expected "(int, int) -> int" \ # N: This is likely because "foo2" has named arguments: "x". Consider marking them positional-only def foo2(x: str, y: int) -> int: ... @@ -1476,10 +1476,10 @@ def bar(x: int) -> int: ... @f def bar2(__x: int) -> Callable[[int], int]: ... -@f # E: Argument 1 to "f" has incompatible type "Callable[[int], str]"; expected "C[[int]]" +@f # E: Argument 1 to "f" has incompatible type "(int) -> str"; expected "C[[int]]" def foo(x: int) -> str: ... -@f # E: Argument 1 to "f" has incompatible type "Callable[[int], Callable[[int], str]]"; expected "C[[int]]" +@f # E: Argument 1 to "f" has incompatible type "(int) -> (int) -> str"; expected "C[[int]]" def foo2(__x: int) -> Callable[[int], str]: ... x: C[[int, str]] @@ -1699,14 +1699,14 @@ def apply(fn: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> None: ... def test(x: int) -> int: ... apply(apply, test, x=42) # OK apply(apply, test, 42) # Also OK (but requires some special casing) -apply(apply, test, "bad") # E: Argument 1 to "apply" has incompatible type "Callable[[Callable[P, T], **P], None]"; expected "Callable[[Callable[[int], int], str], None]" +apply(apply, test, "bad") # E: Argument 1 to "apply" has incompatible type "([(P, T), **P], None)"; expected "((int) -> int, str) -> None" def test2(x: int, y: str) -> None: ... apply(apply, test2, 42, "yes") -apply(apply, test2, "no", 42) # E: Argument 1 to "apply" has incompatible type "Callable[[Callable[P, T], **P], None]"; expected "Callable[[Callable[[int, str], None], str, int], None]" +apply(apply, test2, "no", 42) # E: Argument 1 to "apply" has incompatible type "([(P, T), **P], None)"; expected "((int, str) -> None, str, int) -> None" apply(apply, test2, x=42, y="yes") apply(apply, test2, y="yes", x=42) -apply(apply, test2, y=42, x="no") # E: Argument 1 to "apply" has incompatible type "Callable[[Callable[P, T], **P], None]"; expected "Callable[[Callable[[int, str], None], int, str], None]" +apply(apply, test2, y=42, x="no") # E: Argument 1 to "apply" has incompatible type "([(P, T), **P], None)"; expected "((int, str) -> None, int, str) -> None" [builtins fixtures/paramspec.pyi] [case testParamSpecApplyPosVsNamedOptional] @@ -2131,7 +2131,7 @@ reveal_type(submit( # N: Revealed type is "__main__.Result" backend="asyncio", )) submit( - run, # E: Argument 1 to "submit" has incompatible type "Callable[[Callable[[], R], VarArg(object), DefaultNamedArg(str, 'backend')], R]"; expected "Callable[[Callable[[], Result], int], Result]" + run, # E: Argument 1 to "submit" has incompatible type "(() -> R, object, backend: str) -> R"; expected "(() -> Result, int) -> Result" run_portal, backend=int(), ) @@ -2153,7 +2153,7 @@ class SomeClass: pass # Error message is confusing, but this is a known issue, see #4530. -@smoke_testable(name=42, size="bad", flt=0.5) # E: Argument 1 has incompatible type "Type[OtherClass]"; expected "Callable[[int, str, float], OtherClass]" +@smoke_testable(name=42, size="bad", flt=0.5) # E: Argument 1 has incompatible type "Type[OtherClass]"; expected "(int, str, float) -> OtherClass" class OtherClass: def __init__(self, size: int, name: str, flt: float) -> None: pass diff --git a/test-data/unit/check-plugin-attrs.test b/test-data/unit/check-plugin-attrs.test index 0c653d608187..24db5806af72 100644 --- a/test-data/unit/check-plugin-attrs.test +++ b/test-data/unit/check-plugin-attrs.test @@ -892,9 +892,9 @@ class A: reveal_type(A) [out] main:16: error: Cannot determine __init__ type from converter -main:16: error: Argument "converter" has incompatible type "Callable[[], str]"; expected "Callable[[Any], str]" +main:16: error: Argument "converter" has incompatible type "() -> str"; expected "(Any) -> str" main:17: error: Cannot determine __init__ type from converter -main:17: error: Argument "converter" has incompatible type overloaded function; expected "Callable[[Any], int]" +main:17: error: Argument "converter" has incompatible type overloaded function; expected "(Any) -> int" main:18: note: Revealed type is "def (bad: Any, bad_overloaded: Any) -> __main__.A" [builtins fixtures/list.pyi] @@ -920,9 +920,9 @@ class A: reveal_type(A) [out] main:17: error: Cannot determine __init__ type from converter -main:17: error: Argument "converter" has incompatible type "Callable[[], str]"; expected "Callable[[Any], str]" +main:17: error: Argument "converter" has incompatible type "() -> str"; expected "(Any) -> str" main:18: error: Cannot determine __init__ type from converter -main:18: error: Argument "converter" has incompatible type overloaded function; expected "Callable[[Any], int]" +main:18: error: Argument "converter" has incompatible type overloaded function; expected "(Any) -> int" main:19: note: Revealed type is "def (bad: Any, bad_overloaded: Any) -> __main__.A" [builtins fixtures/list.pyi] diff --git a/test-data/unit/check-protocols.test b/test-data/unit/check-protocols.test index dd19eb1f21d6..eb9a3714d22d 100644 --- a/test-data/unit/check-protocols.test +++ b/test-data/unit/check-protocols.test @@ -256,7 +256,7 @@ class C: meth: int x: P = C() # E: Incompatible types in assignment (expression has type "C", variable has type "P") \ # N: Following member(s) of "C" have conflicts: \ - # N: meth: expected "Callable[[], int]", got "int" + # N: meth: expected "() -> int", got "int" [case testProtocolMethodVsAttributeErrors2] from typing import Protocol @@ -270,7 +270,7 @@ class C: pass x: P = C() # E: Incompatible types in assignment (expression has type "C", variable has type "P") \ # N: Following member(s) of "C" have conflicts: \ - # N: meth: expected "int", got "Callable[[], int]" + # N: meth: expected "int", got "() -> int" [builtins fixtures/property.pyi] [case testCannotAssignNormalToProtocol] @@ -321,7 +321,7 @@ class C: var: MyHashable = C() # E: Incompatible types in assignment (expression has type "C", variable has type "MyHashable") \ # N: Following member(s) of "C" have conflicts: \ - # N: __my_hash__: expected "Callable[[], int]", got "None" + # N: __my_hash__: expected "() -> int", got "None" [case testNoneDisablesProtocolSubclassingWithStrictOptional] from typing import Protocol @@ -332,7 +332,7 @@ class MyHashable(Protocol): class C(MyHashable): __my_hash__ = None # E: Incompatible types in assignment \ -(expression has type "None", base class "MyHashable" defined the type as "Callable[[MyHashable], int]") +(expression has type "None", base class "MyHashable" defined the type as "(MyHashable) -> int") [case testProtocolsWithNoneAndStrictOptional] from typing import Protocol @@ -1892,8 +1892,8 @@ def apply_gen(f: Callable[[T], T]) -> T: reveal_type(apply_gen(Add5())) # N: Revealed type is "builtins.int" def apply_str(f: Callable[[str], int], x: str) -> int: return f(x) -apply_str(Add5(), 'a') # E: Argument 1 to "apply_str" has incompatible type "Add5"; expected "Callable[[str], int]" \ - # N: "Add5.__call__" has type "Callable[[Arg(int, 'x')], int]" +apply_str(Add5(), 'a') # E: Argument 1 to "apply_str" has incompatible type "Add5"; expected "(str) -> int" \ + # N: "Add5.__call__" has type "(x: int) -> int" [builtins fixtures/isinstancelist.pyi] [case testMoreComplexCallableStructuralSubtyping] @@ -1909,10 +1909,10 @@ class Bad1: class Bad2: def __call__(self, y: int, *rest: str) -> int: pass call_soon(Good()) -call_soon(Bad1()) # E: Argument 1 to "call_soon" has incompatible type "Bad1"; expected "Callable[[int, VarArg(str)], int]" \ - # N: "Bad1.__call__" has type "Callable[[Arg(int, 'x'), VarArg(int)], int]" -call_soon(Bad2()) # E: Argument 1 to "call_soon" has incompatible type "Bad2"; expected "Callable[[int, VarArg(str)], int]" \ - # N: "Bad2.__call__" has type "Callable[[Arg(int, 'y'), VarArg(str)], int]" +call_soon(Bad1()) # E: Argument 1 to "call_soon" has incompatible type "Bad1"; expected "(int, str) -> int" \ + # N: "Bad1.__call__" has type "(x: int, int) -> int" +call_soon(Bad2()) # E: Argument 1 to "call_soon" has incompatible type "Bad2"; expected "(int, str) -> int" \ + # N: "Bad2.__call__" has type "(y: int, str) -> int" [builtins fixtures/isinstancelist.pyi] [case testStructuralSupportForPartial] @@ -2473,8 +2473,8 @@ def func(caller: Caller) -> None: pass func(call) -func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[int, VarArg(str)], None]"; expected "Caller" \ - # N: "Caller.__call__" has type "Callable[[Arg(str, 'x'), VarArg(int)], None]" +func(bad) # E: Argument 1 to "func" has incompatible type "(int, str) -> None"; expected "Caller" \ + # N: "Caller.__call__" has type "(x: str, int) -> None" [builtins fixtures/tuple.pyi] [out] @@ -2511,8 +2511,8 @@ def func(caller: Caller) -> None: pass func(call) -func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[int], int]"; expected "Caller" \ - # N: "Caller.__call__" has type "Callable[[Arg(T, 'x')], T]" +func(bad) # E: Argument 1 to "func" has incompatible type "(int) -> int"; expected "Caller" \ + # N: "Caller.__call__" has type "(x: T) -> T" [builtins fixtures/tuple.pyi] [out] @@ -2532,8 +2532,8 @@ def func(caller: Caller) -> None: pass func(call) -func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[T], Tuple[T, T]]"; expected "Caller" \ - # N: "Caller.__call__" has type "Callable[[Arg(int, 'x')], int]" +func(bad) # E: Argument 1 to "func" has incompatible type "(T) -> Tuple[T, T]"; expected "Caller" \ + # N: "Caller.__call__" has type "(x: int) -> int" [builtins fixtures/tuple.pyi] [out] @@ -2560,7 +2560,7 @@ def func(caller: Caller) -> None: pass func(call) -func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[Union[int, str]], Union[int, str]]"; expected "Caller" \ +func(bad) # E: Argument 1 to "func" has incompatible type "(Union[int, str]) -> Union[int, str]"; expected "Caller" \ # N: "Caller.__call__" has type overloaded function [out] @@ -2573,8 +2573,8 @@ class Caller(Protocol): def bad(x: int, *args: str) -> None: pass -cb: Caller = bad # E: Incompatible types in assignment (expression has type "Callable[[int, VarArg(str)], None]", variable has type "Caller") \ - # N: "Caller.__call__" has type "Callable[[Arg(str, 'x'), VarArg(int)], None]" +cb: Caller = bad # E: Incompatible types in assignment (expression has type "(int, str) -> None", variable has type "Caller") \ + # N: "Caller.__call__" has type "(x: str, int) -> None" [builtins fixtures/tuple.pyi] [out] @@ -2600,8 +2600,8 @@ def anon(caller: CallerAnon) -> None: func(call) -func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[str], None]"; expected "Caller" \ - # N: "Caller.__call__" has type "Callable[[Arg(str, 'x')], None]" +func(bad) # E: Argument 1 to "func" has incompatible type "(str) -> None"; expected "Caller" \ + # N: "Caller.__call__" has type "(x: str) -> None" anon(bad) [out] @@ -2625,7 +2625,7 @@ b: Bad func(a) func(b) # E: Argument 1 to "func" has incompatible type "Bad"; expected "One" \ - # N: "One.__call__" has type "Callable[[Arg(str, 'x')], None]" + # N: "One.__call__" has type "(x: str) -> None" [out] [case testJoinProtocolCallback] @@ -2692,12 +2692,12 @@ def f() -> str: ... reveal_type(f.__name__) # N: Revealed type is "builtins.str" a: A = f # OK -b1: B1 = f # E: Incompatible types in assignment (expression has type "Callable[[], str]", variable has type "B1") \ +b1: B1 = f # E: Incompatible types in assignment (expression has type "() -> str", variable has type "B1") \ # N: Following member(s) of "function" have conflicts: \ # N: __name__: expected "int", got "str" -b2: B2 = f # E: Incompatible types in assignment (expression has type "Callable[[], str]", variable has type "B2") \ - # N: "B2.__call__" has type "Callable[[], int]" -b3: B3 = f # E: Incompatible types in assignment (expression has type "Callable[[], str]", variable has type "B3") \ +b2: B2 = f # E: Incompatible types in assignment (expression has type "() -> str", variable has type "B2") \ + # N: "B2.__call__" has type "() -> int" +b3: B3 = f # E: Incompatible types in assignment (expression has type "() -> str", variable has type "B3") \ # N: "function" is missing following "B3" protocol member: \ # N: extra_stuff @@ -3346,7 +3346,7 @@ def test(arg: P) -> None: ... # TODO: skip type mismatch diagnostics in this case. test(B) # E: Argument 1 to "test" has incompatible type "Type[B]"; expected "P" \ # N: Following member(s) of "B" have conflicts: \ - # N: foo: expected "int", got "Callable[[B], int]" \ + # N: foo: expected "int", got "(B) -> int" \ # N: Only class variables allowed for class object access on protocols, foo is an instance variable of "B" test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ # N: Only class variables allowed for class object access on protocols, foo is an instance variable of "C" @@ -3596,7 +3596,7 @@ test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" # N: def __call__(x: int, y: int) -> Any \ # N: Got: \ # N: def __init__(x: int, y: str) -> C \ - # N: "P.__call__" has type "Callable[[Arg(int, 'x'), Arg(int, 'y')], Any]" + # N: "P.__call__" has type "(x: int, y: int) -> Any" [case testProtocolClassObjectPureCallback] from typing import Any, ClassVar, Protocol @@ -3618,7 +3618,7 @@ test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" # N: def __call__(x: int, y: int) -> Any \ # N: Got: \ # N: def __init__(x: int, y: str) -> C \ - # N: "P.__call__" has type "Callable[[Arg(int, 'x'), Arg(int, 'y')], Any]" + # N: "P.__call__" has type "(x: int, y: int) -> Any" [builtins fixtures/type.pyi] [case testProtocolClassObjectCallableError] @@ -3638,10 +3638,10 @@ class C: p: P = C # E: Incompatible types in assignment (expression has type "Type[C]", variable has type "P") \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ - # N: def __call__(app: int) -> Callable[[str], None] \ + # N: def __call__(app: int) -> (str) -> None \ # N: Got: \ # N: def __init__(app: str) -> C \ - # N: "P.__call__" has type "Callable[[Arg(int, 'app')], Callable[[str], None]]" + # N: "P.__call__" has type "(app: int) -> (str) -> None" [builtins fixtures/type.pyi] @@ -3799,8 +3799,8 @@ S = TypeVar("S") def f_good(t: S) -> S: return t -g: C = f_bad # E: Incompatible types in assignment (expression has type "Callable[[int], int]", variable has type "C") \ - # N: "C.__call__" has type "Callable[[Arg(T, 't')], T]" +g: C = f_bad # E: Incompatible types in assignment (expression has type "(int) -> int", variable has type "C") \ + # N: "C.__call__" has type "(t: T) -> T" g = f_good # OK [case testModuleAsProtocolImplementation] diff --git a/test-data/unit/check-python311.test b/test-data/unit/check-python311.test index 6f4c540572b0..b1d065e8e423 100644 --- a/test-data/unit/check-python311.test +++ b/test-data/unit/check-python311.test @@ -157,7 +157,7 @@ Alias1 = Callable[[*Ts], int] # E: Variable "__main__.Ts" is not valid as a typ x1: Alias1[int] # E: Bad number of arguments for type alias, expected 0, given 1 reveal_type(x1) # N: Revealed type is "def (*Any) -> builtins.int" x1 = good -x1 = bad # E: Incompatible types in assignment (expression has type "Callable[[VarArg(int), NamedArg(int, 'y')], int]", variable has type "Callable[[VarArg(Any)], int]") +x1 = bad # E: Incompatible types in assignment (expression has type "(int, y: int) -> int", variable has type "(Any) -> int") Alias2 = Callable[[*T], int] # E: "T" cannot be unpacked (must be tuple or TypeVarTuple) x2: Alias2[int] diff --git a/test-data/unit/check-redefine.test b/test-data/unit/check-redefine.test index b7642d30efc8..591618833623 100644 --- a/test-data/unit/check-redefine.test +++ b/test-data/unit/check-redefine.test @@ -251,7 +251,7 @@ def f() -> None: # flags: --allow-redefinition def f() -> None: def x(): pass - x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Callable[[], Any]") + x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "() -> Any") reveal_type(x) # N: Revealed type is "def () -> Any" y = 1 def y(): pass # E: Name "y" already defined on line 6 diff --git a/test-data/unit/check-selftype.test b/test-data/unit/check-selftype.test index fa853ac48e5a..1c87eea29293 100644 --- a/test-data/unit/check-selftype.test +++ b/test-data/unit/check-selftype.test @@ -697,7 +697,7 @@ class C(Generic[T]): i: C[int] s: C[str] -i.from_item() # E: Invalid self argument "C[int]" to attribute function "from_item" with type "Callable[[C[str]], None]" +i.from_item() # E: Invalid self argument "C[int]" to attribute function "from_item" with type "(C[str]) -> None" s.from_item() [case testSelfTypeRestrictedClassMethod] @@ -711,9 +711,9 @@ class C(Generic[T]): class DI(C[int]): ... class DS(C[str]): ... -DI().from_item() # E: Invalid self argument "Type[DI]" to class attribute function "from_item" with type "Callable[[Type[C[str]]], None]" +DI().from_item() # E: Invalid self argument "Type[DI]" to class attribute function "from_item" with type "(Type[C[str]]) -> None" DS().from_item() -DI.from_item() # E: Invalid self argument "Type[DI]" to attribute function "from_item" with type "Callable[[Type[C[str]]], None]" +DI.from_item() # E: Invalid self argument "Type[DI]" to attribute function "from_item" with type "(Type[C[str]]) -> None" DS.from_item() [builtins fixtures/classmethod.pyi] @@ -755,7 +755,7 @@ ci.from_item() # E: Missing positional argument "converter" in call to "from_it def conv(x: int) -> str: ... def bad(x: str) -> str: ... reveal_type(ci.from_item(conv)) # N: Revealed type is "builtins.str" -ci.from_item(bad) # E: Argument 1 to "from_item" of "C" has incompatible type "Callable[[str], str]"; expected "Callable[[int], str]" +ci.from_item(bad) # E: Argument 1 to "from_item" of "C" has incompatible type "(str) -> str"; expected "(int) -> str" [case testSelfTypeRestrictedMethodOverloadInit] from typing import TypeVar @@ -854,7 +854,7 @@ class Sub(Base[List[int]]): ... class BadSub(Base[int]): ... reveal_type(Sub().get_item()) # N: Revealed type is "builtins.int" -BadSub().get_item() # E: Invalid self argument "BadSub" to attribute function "get_item" with type "Callable[[Base[List[S]]], S]" +BadSub().get_item() # E: Invalid self argument "BadSub" to attribute function "get_item" with type "(Base[List[S]]) -> S" [builtins fixtures/list.pyi] [case testMixinAllowedWithProtocol] @@ -882,10 +882,10 @@ class Bad(AtomicClose, Copyable): f: File b: Bad f.atomic_close() # OK -b.atomic_close() # E: Invalid self argument "Bad" to attribute function "atomic_close" with type "Callable[[Resource], int]" +b.atomic_close() # E: Invalid self argument "Bad" to attribute function "atomic_close" with type "(Resource) -> int" reveal_type(f.copy()) # N: Revealed type is "__main__.File" -b.copy() # E: Invalid self argument "Bad" to attribute function "copy" with type "Callable[[T], T]" +b.copy() # E: Invalid self argument "Bad" to attribute function "copy" with type "(T) -> T" [builtins fixtures/tuple.pyi] [case testMixinProtocolSuper] @@ -924,7 +924,7 @@ class Test: def meth(self, x: str) -> int: ... reveal_type(Test().meth) # N: Revealed type is "def (x: builtins.str) -> builtins.int" -Test()._deco # E: Invalid self argument "Test" to attribute function "_deco" with type "Callable[[F], F]" +Test()._deco # E: Invalid self argument "Test" to attribute function "_deco" with type "(F) -> F" [builtins fixtures/tuple.pyi] [case testSelfTypeTrickyExample] @@ -985,9 +985,9 @@ T = TypeVar('T') class Foo(Generic[T]): def f1(self: Foo[str]) -> None: - self.f2() # E: Invalid self argument "Foo[str]" to attribute function "f2" with type "Callable[[Foo[int]], None]" + self.f2() # E: Invalid self argument "Foo[str]" to attribute function "f2" with type "(Foo[int]) -> None" def f2(self: Foo[int]) -> None: - self.f1() # E: Invalid self argument "Foo[int]" to attribute function "f1" with type "Callable[[Foo[str]], None]" + self.f1() # E: Invalid self argument "Foo[int]" to attribute function "f1" with type "(Foo[str]) -> None" [case testSelfTypeStructureMetaclassMatch] from typing import TypeVar, Type, Generic, cast @@ -1031,7 +1031,7 @@ class Bad(metaclass=Meta): pass Good.do_x() -Bad.do_x() # E: Invalid self argument "Type[Bad]" to attribute function "do_x" with type "Callable[[Type[T]], T]" +Bad.do_x() # E: Invalid self argument "Type[Bad]" to attribute function "do_x" with type "(Type[T]) -> T" [case testSelfTypeProtocolClassmethodMatch] from typing import Type, TypeVar, Protocol diff --git a/test-data/unit/check-serialize.test b/test-data/unit/check-serialize.test index 81da94c0591c..12f7f7dc8659 100644 --- a/test-data/unit/check-serialize.test +++ b/test-data/unit/check-serialize.test @@ -685,7 +685,7 @@ class A: pass def f() -> None: pass [builtins fixtures/tuple.pyi] [out2] -tmp/a.py:5: error: Incompatible types in assignment (expression has type "Callable[[], None]", variable has type "type") +tmp/a.py:5: error: Incompatible types in assignment (expression has type "() -> None", variable has type "type") [case testSerializeOverloadedVsTypeObjectDistinction] import a diff --git a/test-data/unit/check-singledispatch.test b/test-data/unit/check-singledispatch.test index e63d4c073e86..6b61080ae8fa 100644 --- a/test-data/unit/check-singledispatch.test +++ b/test-data/unit/check-singledispatch.test @@ -300,7 +300,7 @@ h('a', 1) # E: Argument 2 to "h" has incompatible type "int"; expected "str" [case testDontCrashWhenRegisteringAfterError] import functools -a = functools.singledispatch('a') # E: Need type annotation for "a" # E: Argument 1 to "singledispatch" has incompatible type "str"; expected "Callable[..., Never]" +a = functools.singledispatch('a') # E: Need type annotation for "a" # E: Argument 1 to "singledispatch" has incompatible type "str"; expected "(..., Never)" @a.register(int) def default(val) -> int: diff --git a/test-data/unit/check-statements.test b/test-data/unit/check-statements.test index 44880cf35204..0e7820952520 100644 --- a/test-data/unit/check-statements.test +++ b/test-data/unit/check-statements.test @@ -674,7 +674,7 @@ else: def f3() -> None: pass [builtins fixtures/exception.pyi] [out] -main:7: error: Incompatible redefinition (redefinition with type "Callable[[], str]", original type "Callable[[], None]") +main:7: error: Incompatible redefinition (redefinition with type "() -> str", original type "() -> None") [case testExceptWithoutType] import typing @@ -2345,7 +2345,7 @@ def f(): describe(CAny()) describe(C()) describe(CNone()) -describe(CWrong()) # E: Argument 1 to "describe" has incompatible type "CWrong"; expected "Callable[[], None]" \ - # N: "CWrong.__call__" has type "Callable[[Arg(int, 'x')], None]" +describe(CWrong()) # E: Argument 1 to "describe" has incompatible type "CWrong"; expected "() -> None" \ + # N: "CWrong.__call__" has type "(x: int) -> None" describe(f) [builtins fixtures/isinstancelist.pyi] diff --git a/test-data/unit/check-tuples.test b/test-data/unit/check-tuples.test index d675a35c4aae..a61a2929a5b1 100644 --- a/test-data/unit/check-tuples.test +++ b/test-data/unit/check-tuples.test @@ -531,7 +531,7 @@ def f(): pass a, b = None # E: "None" object is not iterable a, b = a # E: "A" object is not iterable -a, b = f # E: "Callable[[], Any]" object is not iterable +a, b = f # E: "() -> Any" object is not iterable class A: pass class B: pass diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index c7b9694a9188..4e284474fe23 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1145,7 +1145,7 @@ ParamAlias = TypeAliasType("ParamAlias", Callable[P, int], type_params=(P,)) def f(x: str, y: float) -> int: return 1 def g(x: int, y: float) -> int: return 1 xp1: ParamAlias[str, float] = f -xp2: ParamAlias[str, float] = g # E: Incompatible types in assignment (expression has type "Callable[[int, float], int]", variable has type "Callable[[str, float], int]") +xp2: ParamAlias[str, float] = g # E: Incompatible types in assignment (expression has type "(int, float) -> int", variable has type "(str, float) -> int") xp3: ParamAlias[str, float] = lambda x, y: 1 class G(Generic[P, T]): ... diff --git a/test-data/unit/check-typeguard.test b/test-data/unit/check-typeguard.test index e7a8eac4f043..e22602ce8a95 100644 --- a/test-data/unit/check-typeguard.test +++ b/test-data/unit/check-typeguard.test @@ -505,10 +505,10 @@ def with_typeguard(o: object) -> TypeGuard[bool]: pass def with_bool(o: object) -> bool: pass accepts_typeguard(with_typeguard) -accepts_typeguard(with_bool) # E: Argument 1 to "accepts_typeguard" has incompatible type "Callable[[object], bool]"; expected "Callable[[object], TypeGuard[bool]]" +accepts_typeguard(with_bool) # E: Argument 1 to "accepts_typeguard" has incompatible type "(object) -> bool"; expected "(object) -> TypeGuard[bool]" -different_typeguard(with_typeguard) # E: Argument 1 to "different_typeguard" has incompatible type "Callable[[object], TypeGuard[bool]]"; expected "Callable[[object], TypeGuard[str]]" -different_typeguard(with_bool) # E: Argument 1 to "different_typeguard" has incompatible type "Callable[[object], bool]"; expected "Callable[[object], TypeGuard[str]]" +different_typeguard(with_typeguard) # E: Argument 1 to "different_typeguard" has incompatible type "(object) -> TypeGuard[bool]"; expected "(object) -> TypeGuard[str]" +different_typeguard(with_bool) # E: Argument 1 to "different_typeguard" has incompatible type "(object) -> bool"; expected "(object) -> TypeGuard[str]" [builtins fixtures/tuple.pyi] [case testTypeGuardAsGenericFunctionArg] @@ -525,7 +525,7 @@ def with_bool(o: object) -> bool: pass accepts_typeguard(with_bool_typeguard) accepts_typeguard(with_str_typeguard) -accepts_typeguard(with_bool) # E: Argument 1 to "accepts_typeguard" has incompatible type "Callable[[object], bool]"; expected "Callable[[object], TypeGuard[Never]]" +accepts_typeguard(with_bool) # E: Argument 1 to "accepts_typeguard" has incompatible type "(object) -> bool"; expected "(object) -> TypeGuard[Never]" [builtins fixtures/tuple.pyi] [case testTypeGuardAsOverloadedFunctionArg] @@ -563,7 +563,7 @@ def with_typeguard_a(o: object) -> TypeGuard[A]: pass def with_typeguard_b(o: object) -> TypeGuard[B]: pass def with_typeguard_c(o: object) -> TypeGuard[C]: pass -accepts_typeguard(with_typeguard_a) # E: Argument 1 to "accepts_typeguard" has incompatible type "Callable[[object], TypeGuard[A]]"; expected "Callable[[object], TypeGuard[B]]" +accepts_typeguard(with_typeguard_a) # E: Argument 1 to "accepts_typeguard" has incompatible type "(object) -> TypeGuard[A]"; expected "(object) -> TypeGuard[B]" accepts_typeguard(with_typeguard_b) accepts_typeguard(with_typeguard_c) [builtins fixtures/tuple.pyi] diff --git a/test-data/unit/check-typeis.test b/test-data/unit/check-typeis.test index 2372f990fda1..8064f2067c10 100644 --- a/test-data/unit/check-typeis.test +++ b/test-data/unit/check-typeis.test @@ -508,10 +508,10 @@ def with_typeis(o: object) -> TypeIs[bool]: pass def with_bool(o: object) -> bool: pass accepts_typeis(with_typeis) -accepts_typeis(with_bool) # E: Argument 1 to "accepts_typeis" has incompatible type "Callable[[object], bool]"; expected "Callable[[object], TypeIs[bool]]" +accepts_typeis(with_bool) # E: Argument 1 to "accepts_typeis" has incompatible type "(object) -> bool"; expected "(object) -> TypeIs[bool]" -different_typeis(with_typeis) # E: Argument 1 to "different_typeis" has incompatible type "Callable[[object], TypeIs[bool]]"; expected "Callable[[object], TypeIs[str]]" -different_typeis(with_bool) # E: Argument 1 to "different_typeis" has incompatible type "Callable[[object], bool]"; expected "Callable[[object], TypeIs[str]]" +different_typeis(with_typeis) # E: Argument 1 to "different_typeis" has incompatible type "(object) -> TypeIs[bool]"; expected "(object) -> TypeIs[str]" +different_typeis(with_bool) # E: Argument 1 to "different_typeis" has incompatible type "(object) -> bool"; expected "(object) -> TypeIs[str]" [builtins fixtures/tuple.pyi] [case testTypeIsAsGenericFunctionArg] @@ -528,7 +528,7 @@ def with_bool(o: object) -> bool: pass accepts_typeis(with_bool_typeis) accepts_typeis(with_str_typeis) -accepts_typeis(with_bool) # E: Argument 1 to "accepts_typeis" has incompatible type "Callable[[object], bool]"; expected "Callable[[object], TypeIs[Never]]" +accepts_typeis(with_bool) # E: Argument 1 to "accepts_typeis" has incompatible type "(object) -> bool"; expected "(object) -> TypeIs[Never]" [builtins fixtures/tuple.pyi] [case testTypeIsAsOverloadedFunctionArg] @@ -566,9 +566,9 @@ def with_typeis_a(o: object) -> TypeIs[A]: pass def with_typeis_b(o: object) -> TypeIs[B]: pass def with_typeis_c(o: object) -> TypeIs[C]: pass -accepts_typeis(with_typeis_a) # E: Argument 1 to "accepts_typeis" has incompatible type "Callable[[object], TypeIs[A]]"; expected "Callable[[object], TypeIs[B]]" +accepts_typeis(with_typeis_a) # E: Argument 1 to "accepts_typeis" has incompatible type "(object) -> TypeIs[A]"; expected "(object) -> TypeIs[B]" accepts_typeis(with_typeis_b) -accepts_typeis(with_typeis_c) # E: Argument 1 to "accepts_typeis" has incompatible type "Callable[[object], TypeIs[C]]"; expected "Callable[[object], TypeIs[B]]" +accepts_typeis(with_typeis_c) # E: Argument 1 to "accepts_typeis" has incompatible type "(object) -> TypeIs[C]"; expected "(object) -> TypeIs[B]" [builtins fixtures/tuple.pyi] [case testTypeIsWithIdentityGeneric] @@ -812,8 +812,8 @@ def typeguard(x: object) -> TypeGuard[str]: pass accept_typeis(typeis) -accept_typeis(typeguard) # E: Argument 1 to "accept_typeis" has incompatible type "Callable[[object], TypeGuard[str]]"; expected "Callable[[object], TypeIs[str]]" -accept_typeguard(typeis) # E: Argument 1 to "accept_typeguard" has incompatible type "Callable[[object], TypeIs[str]]"; expected "Callable[[object], TypeGuard[str]]" +accept_typeis(typeguard) # E: Argument 1 to "accept_typeis" has incompatible type "(object) -> TypeGuard[str]"; expected "(object) -> TypeIs[str]" +accept_typeguard(typeis) # E: Argument 1 to "accept_typeguard" has incompatible type "(object) -> TypeIs[str]"; expected "(object) -> TypeGuard[str]" accept_typeguard(typeguard) [builtins fixtures/tuple.pyi] diff --git a/test-data/unit/check-typevar-tuple.test b/test-data/unit/check-typevar-tuple.test index f49e1b3c6613..6742398d9d92 100644 --- a/test-data/unit/check-typevar-tuple.test +++ b/test-data/unit/check-typevar-tuple.test @@ -515,18 +515,18 @@ vargs: Tuple[int, ...] vargs_str: Tuple[str, ...] call(target=func, args=(0, 'foo')) -call(target=func, args=('bar', 'foo')) # E: Argument "target" to "call" has incompatible type "Callable[[int, str], None]"; expected "Callable[[str, str], None]" -call(target=func, args=(True, 'foo', 0)) # E: Argument "target" to "call" has incompatible type "Callable[[int, str], None]"; expected "Callable[[bool, str, int], None]" -call(target=func, args=(0, 0, 'foo')) # E: Argument "target" to "call" has incompatible type "Callable[[int, str], None]"; expected "Callable[[int, int, str], None]" -call(target=func, args=vargs) # E: Argument "target" to "call" has incompatible type "Callable[[int, str], None]"; expected "Callable[[VarArg(int)], None]" +call(target=func, args=('bar', 'foo')) # E: Argument "target" to "call" has incompatible type "(int, str) -> None"; expected "(str, str) -> None" +call(target=func, args=(True, 'foo', 0)) # E: Argument "target" to "call" has incompatible type "(int, str) -> None"; expected "(bool, str, int) -> None" +call(target=func, args=(0, 0, 'foo')) # E: Argument "target" to "call" has incompatible type "(int, str) -> None"; expected "(int, int, str) -> None" +call(target=func, args=vargs) # E: Argument "target" to "call" has incompatible type "(int, str) -> None"; expected "(int) -> None" # NOTE: This behavior may be a bit contentious, it is maybe inconsistent with our handling of # PEP646 but consistent with our handling of callable constraints. -call(target=func2, args=vargs) # E: Argument "target" to "call" has incompatible type "Callable[[int, int], None]"; expected "Callable[[VarArg(int)], None]" +call(target=func2, args=vargs) # E: Argument "target" to "call" has incompatible type "(int, int) -> None"; expected "(int) -> None" call(target=func3, args=vargs) call(target=func3, args=(0,1)) -call(target=func3, args=(0,'foo')) # E: Argument "target" to "call" has incompatible type "Callable[[VarArg(int)], None]"; expected "Callable[[int, str], None]" -call(target=func3, args=vargs_str) # E: Argument "target" to "call" has incompatible type "Callable[[VarArg(int)], None]"; expected "Callable[[VarArg(str)], None]" +call(target=func3, args=(0,'foo')) # E: Argument "target" to "call" has incompatible type "(int) -> None"; expected "(int, str) -> None" +call(target=func3, args=vargs_str) # E: Argument "target" to "call" has incompatible type "(int) -> None"; expected "(str) -> None" [builtins fixtures/tuple.pyi] [case testTypeVarTuplePep646CallableWithPrefixSuffix] @@ -545,7 +545,7 @@ def func_prefix(arg0: bytes, arg1: int, arg2: str) -> None: ... def func2_prefix(arg0: str, arg1: int, arg2: str) -> None: ... call_prefix(target=func_prefix, args=(0, 'foo')) -call_prefix(target=func2_prefix, args=(0, 'foo')) # E: Argument "target" to "call_prefix" has incompatible type "Callable[[str, int, str], None]"; expected "Callable[[bytes, int, str], None]" +call_prefix(target=func2_prefix, args=(0, 'foo')) # E: Argument "target" to "call_prefix" has incompatible type "(str, int, str) -> None"; expected "(bytes, int, str) -> None" [builtins fixtures/tuple.pyi] [case testTypeVarTuplePep646CallableSuffixSyntax] @@ -640,11 +640,11 @@ class A: vargs: Tuple[int, ...] vargs_str: Tuple[str, ...] -call(A().func) # E: Argument 1 to "call" has incompatible type "Callable[[int, str], None]"; expected "Callable[[], None]" +call(A().func) # E: Argument 1 to "call" has incompatible type "(int, str) -> None"; expected "() -> None" call(A().func, 0, 'foo') -call(A().func, 0, 'foo', 0) # E: Argument 1 to "call" has incompatible type "Callable[[int, str], None]"; expected "Callable[[int, str, int], None]" -call(A().func, 0) # E: Argument 1 to "call" has incompatible type "Callable[[int, str], None]"; expected "Callable[[int], None]" -call(A().func, 0, 1) # E: Argument 1 to "call" has incompatible type "Callable[[int, str], None]"; expected "Callable[[int, int], None]" +call(A().func, 0, 'foo', 0) # E: Argument 1 to "call" has incompatible type "(int, str) -> None"; expected "(int, str, int) -> None" +call(A().func, 0) # E: Argument 1 to "call" has incompatible type "(int, str) -> None"; expected "(int) -> None" +call(A().func, 0, 1) # E: Argument 1 to "call" has incompatible type "(int, str) -> None"; expected "(int, int) -> None" call(A().func2, 0, 0) call(A().func3, 0, 1, 2) call(A().func3) @@ -1126,7 +1126,7 @@ nt = A(fn=test, val=42) reveal_type(nt) # N: Revealed type is "Tuple[def (builtins.int, builtins.str), builtins.int, fallback=__main__.A[builtins.int, builtins.str, builtins.int]]" def bad() -> int: ... -nt2 = A(fn=bad, val=42) # E: Argument "fn" to "A" has incompatible type "Callable[[], int]"; expected "Callable[[], None]" +nt2 = A(fn=bad, val=42) # E: Argument "fn" to "A" has incompatible type "() -> int"; expected "() -> None" [builtins fixtures/tuple.pyi] [case testVariadicTypedDict] @@ -1155,7 +1155,7 @@ td = A({"fn": test, "val": 42}) reveal_type(td) # N: Revealed type is "TypedDict('__main__.A', {'fn': def (builtins.int, builtins.str), 'val': builtins.int})" def bad() -> int: ... -td2 = A({"fn": bad, "val": 42}) # E: Incompatible types (expression has type "Callable[[], int]", TypedDict item "fn" has type "Callable[[], None]") +td2 = A({"fn": bad, "val": 42}) # E: Incompatible types (expression has type "() -> int", TypedDict item "fn" has type "() -> None") [builtins fixtures/tuple.pyi] [case testFixedUnpackWithRegularInstance] @@ -1903,7 +1903,7 @@ def foo3(func: Callable[[int, Unpack[Args2]], T], *args: Unpack[Args2]) -> T: return submit2(func, 1, *args) def foo_bad(func: Callable[[Unpack[Args2]], T], *args: Unpack[Args2]) -> T: - return submit2(func, 1, *args) # E: Argument 1 to "submit2" has incompatible type "Callable[[VarArg(Unpack[Args2])], T]"; expected "Callable[[int, VarArg(Unpack[Args2])], T]" + return submit2(func, 1, *args) # E: Argument 1 to "submit2" has incompatible type "(Unpack[Args2]) -> T"; expected "(int, Unpack[Args2]) -> T" [builtins fixtures/tuple.pyi] [case testTypeVarTupleParamSpecInteraction] @@ -2034,12 +2034,12 @@ class B(Generic[Unpack[Ts]]): def on_pair(self: B[T, S]) -> Tuple[T, S]: ... b1: B[int] -reveal_type(b1.on_pair()) # E: Invalid self argument "B[int]" to attribute function "on_pair" with type "Callable[[B[T, S]], Tuple[T, S]]" \ +reveal_type(b1.on_pair()) # E: Invalid self argument "B[int]" to attribute function "on_pair" with type "(B[T, S]) -> Tuple[T, S]" \ # N: Revealed type is "Tuple[Never, Never]" b2: B[int, str] reveal_type(b2.on_pair()) # N: Revealed type is "Tuple[builtins.int, builtins.str]" b3: B[int, str, int] -reveal_type(b3.on_pair()) # E: Invalid self argument "B[int, str, int]" to attribute function "on_pair" with type "Callable[[B[T, S]], Tuple[T, S]]" \ +reveal_type(b3.on_pair()) # E: Invalid self argument "B[int, str, int]" to attribute function "on_pair" with type "(B[T, S]) -> Tuple[T, S]" \ # N: Revealed type is "Tuple[Never, Never]" class C(B[T, S]): ... @@ -2313,10 +2313,10 @@ def bad4(**kwargs: None) -> None: ... higher_order(good1) higher_order(good2) -higher_order(bad1) # E: Argument 1 to "higher_order" has incompatible type "Callable[[str, int], None]"; expected "Callable[[VarArg(Any)], Any]" -higher_order(bad2) # E: Argument 1 to "higher_order" has incompatible type "Callable[[bytes, VarArg(int)], str]"; expected "Callable[[VarArg(Any)], Any]" -higher_order(bad3) # E: Argument 1 to "higher_order" has incompatible type "Callable[[NamedArg(str, 'd')], int]"; expected "Callable[[VarArg(Any)], Any]" -higher_order(bad4) # E: Argument 1 to "higher_order" has incompatible type "Callable[[KwArg(None)], None]"; expected "Callable[[VarArg(Any)], Any]" +higher_order(bad1) # E: Argument 1 to "higher_order" has incompatible type "(str, int) -> None"; expected "(Any) -> Any" +higher_order(bad2) # E: Argument 1 to "higher_order" has incompatible type "(bytes, int) -> str"; expected "(Any) -> Any" +higher_order(bad3) # E: Argument 1 to "higher_order" has incompatible type "(d: str) -> int"; expected "(Any) -> Any" +higher_order(bad4) # E: Argument 1 to "higher_order" has incompatible type "(None) -> None"; expected "(Any) -> Any" [builtins fixtures/tuple.pyi] [case testAliasToCallableWithUnpack2] @@ -2332,10 +2332,10 @@ def bad3(*, d: str) -> int: ... def bad4(**kwargs: None) -> None: ... higher_order(good) -higher_order(bad1) # E: Argument 1 to "higher_order" has incompatible type "Callable[[str, int], None]"; expected "Callable[[int, str, VarArg(Unpack[Tuple[Unpack[Tuple[Any, ...]], int]])], Any]" -higher_order(bad2) # E: Argument 1 to "higher_order" has incompatible type "Callable[[bytes, VarArg(int)], str]"; expected "Callable[[int, str, VarArg(Unpack[Tuple[Unpack[Tuple[Any, ...]], int]])], Any]" -higher_order(bad3) # E: Argument 1 to "higher_order" has incompatible type "Callable[[NamedArg(str, 'd')], int]"; expected "Callable[[int, str, VarArg(Unpack[Tuple[Unpack[Tuple[Any, ...]], int]])], Any]" -higher_order(bad4) # E: Argument 1 to "higher_order" has incompatible type "Callable[[KwArg(None)], None]"; expected "Callable[[int, str, VarArg(Unpack[Tuple[Unpack[Tuple[Any, ...]], int]])], Any]" +higher_order(bad1) # E: Argument 1 to "higher_order" has incompatible type "(str, int) -> None"; expected "(int, str, Unpack[Tuple[Unpack[Tuple[Any, ...]], int]]) -> Any" +higher_order(bad2) # E: Argument 1 to "higher_order" has incompatible type "(bytes, int) -> str"; expected "(int, str, Unpack[Tuple[Unpack[Tuple[Any, ...]], int]]) -> Any" +higher_order(bad3) # E: Argument 1 to "higher_order" has incompatible type "(d: str) -> int"; expected "(int, str, Unpack[Tuple[Unpack[Tuple[Any, ...]], int]]) -> Any" +higher_order(bad4) # E: Argument 1 to "higher_order" has incompatible type "(None) -> None"; expected "(int, str, Unpack[Tuple[Unpack[Tuple[Any, ...]], int]]) -> Any" [builtins fixtures/tuple.pyi] [case testAliasToCallableWithUnpackInvalid] @@ -2351,7 +2351,7 @@ Alias = Callable[[Unpack[T]], int] # E: "T" cannot be unpacked (must be tuple o x: Alias[int] reveal_type(x) # N: Revealed type is "def (*Any) -> builtins.int" x = good -x = bad # E: Incompatible types in assignment (expression has type "Callable[[VarArg(int), NamedArg(int, 'y')], int]", variable has type "Callable[[VarArg(Any)], int]") +x = bad # E: Incompatible types in assignment (expression has type "(int, y: int) -> int", variable has type "(Any) -> int") [builtins fixtures/tuple.pyi] [case testTypeVarTupleInvariant] @@ -2402,7 +2402,7 @@ reveal_type(C[int, str]) # N: Revealed type is "Overload(def (f: def (builtins. Alias = C[int, str] def f(x: int, y: int, z: int, t: int) -> str: ... -x = C(f, 0, 0, "hm") # E: Argument 1 to "C" has incompatible type "Callable[[int, int, int, int], str]"; expected "Callable[[int, int, str, int], str]" +x = C(f, 0, 0, "hm") # E: Argument 1 to "C" has incompatible type "(int, int, int, int) -> str"; expected "(int, int, str, int) -> str" reveal_type(x) # N: Revealed type is "__main__.C[builtins.str, builtins.int]" reveal_type(C(f)) # N: Revealed type is "__main__.C[builtins.str, builtins.int, builtins.int, builtins.int, builtins.int]" C[()] # E: At least 1 type argument(s) expected, none given @@ -2437,7 +2437,7 @@ class CM(Generic[R]): ... def cm(fn: Callable[P, List[R]]) -> Callable[P, CM[R]]: ... Ts = TypeVarTuple("Ts") -@cm # E: Argument 1 to "cm" has incompatible type "Callable[[VarArg(Unpack[Ts])], Tuple[Unpack[Ts]]]"; expected "Callable[[VarArg(Never)], List[Never]]" +@cm # E: Argument 1 to "cm" has incompatible type "(Unpack[Ts]) -> Tuple[Unpack[Ts]]"; expected "(Never) -> List[Never]" def test(*args: Unpack[Ts]) -> Tuple[Unpack[Ts]]: ... reveal_type(test) # N: Revealed type is "def (*args: Never) -> __main__.CM[Never]" diff --git a/test-data/unit/check-typevar-values.test b/test-data/unit/check-typevar-values.test index 8b961d88d23d..882a4b78d796 100644 --- a/test-data/unit/check-typevar-values.test +++ b/test-data/unit/check-typevar-values.test @@ -554,7 +554,7 @@ b = g if int(): b = g if int(): - b = f # E: Incompatible types in assignment (expression has type "Callable[[T], T]", variable has type "Callable[[U], U]") + b = f # E: Incompatible types in assignment (expression has type "(T) -> T", variable has type "(U) -> U") [case testInnerFunctionWithTypevarValues] from typing import TypeVar diff --git a/test-data/unit/check-varargs.test b/test-data/unit/check-varargs.test index bb0e80acee1e..f5cbb5dafb85 100644 --- a/test-data/unit/check-varargs.test +++ b/test-data/unit/check-varargs.test @@ -652,7 +652,7 @@ x: Callable[[int], None] def f(*x: int) -> None: pass def g(*x: str) -> None: pass x = f -x = g # E: Incompatible types in assignment (expression has type "Callable[[VarArg(str)], None]", variable has type "Callable[[int], None]") +x = g # E: Incompatible types in assignment (expression has type "(str) -> None", variable has type "(int) -> None") [builtins fixtures/list.pyi] [out] From 3dc01e13441295104ee6acefac73d756763d31e7 Mon Sep 17 00:00:00 2001 From: MechanicalConstruct Date: Fri, 6 Dec 2024 20:40:48 -0500 Subject: [PATCH 4/4] update for testRunParamSpecConcatenateInsufficientArgs --- test-data/unit/check-parameter-specification.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-data/unit/check-parameter-specification.test b/test-data/unit/check-parameter-specification.test index a334d278f9b4..ac90d7a4265f 100644 --- a/test-data/unit/check-parameter-specification.test +++ b/test-data/unit/check-parameter-specification.test @@ -2248,7 +2248,7 @@ def fn_args(x: int, y: str) -> None: ... def fn_posonly(x: int, /) -> None: ... def fn_posonly_args(x: int, /, y: str) -> None: ... -run(fn) # E: Argument 1 to "run" has incompatible type "Callable[[], None]"; expected "Callable[[int], None]" +run(fn) # E: Argument 1 to "run" has incompatible type "() -> None"; expected "(int) -> None" run(fn_args, 1, 'a') # E: Too many arguments for "run" \ # E: Argument 2 to "run" has incompatible type "int"; expected "str" run(fn_args, y='a')