From e3f6453e1b19be520878d8fd2179ad10050b04d5 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 30 May 2025 01:10:15 +0200 Subject: [PATCH 1/4] Remove force_uppercase_builtins default from test helpers --- mypy/test/helpers.py | 8 ++++---- mypy/test/testcheck.py | 2 -- mypy/test/testcmdline.py | 2 -- mypy/test/testmerge.py | 1 - mypy/test/testparse.py | 1 - mypy/test/testpythoneval.py | 1 - mypy/test/testsemanal.py | 1 - mypy/test/testtransform.py | 1 - mypy/test/testtypegen.py | 1 - 9 files changed, 4 insertions(+), 14 deletions(-) diff --git a/mypy/test/helpers.py b/mypy/test/helpers.py index fcec68094e51..2fc20f6ec6e7 100644 --- a/mypy/test/helpers.py +++ b/mypy/test/helpers.py @@ -258,9 +258,10 @@ def local_sys_path_set() -> Iterator[None]: def testfile_pyversion(path: str) -> tuple[int, int]: - m = re.search(r"python3([0-9]+)\.test$", path) - if m: - return 3, int(m.group(1)) + if m := re.search(r"python3([0-9]+)\.test$", path): + # For older unsupported version like python38, + # default to that earliest supported version. + return max((3, int(m.group(1))), defaults.PYTHON3_VERSION) else: return defaults.PYTHON3_VERSION @@ -353,7 +354,6 @@ def parse_options( options = Options() options.error_summary = False options.hide_error_codes = True - options.force_uppercase_builtins = True options.force_union_syntax = True # Allow custom python version to override testfile_pyversion. diff --git a/mypy/test/testcheck.py b/mypy/test/testcheck.py index e6415ddff906..fb2eb3a75b9b 100644 --- a/mypy/test/testcheck.py +++ b/mypy/test/testcheck.py @@ -136,8 +136,6 @@ def run_case_once( options.hide_error_codes = False if "abstract" not in testcase.file: options.allow_empty_bodies = not testcase.name.endswith("_no_empty") - if "lowercase" not in testcase.file: - options.force_uppercase_builtins = True if "union-error" not in testcase.file: options.force_union_syntax = True diff --git a/mypy/test/testcmdline.py b/mypy/test/testcmdline.py index 9bc02d319964..11d229042978 100644 --- a/mypy/test/testcmdline.py +++ b/mypy/test/testcmdline.py @@ -61,8 +61,6 @@ def test_python_cmdline(testcase: DataDrivenTestCase, step: int) -> None: args.append("--hide-error-codes") if "--disallow-empty-bodies" not in args: args.append("--allow-empty-bodies") - if "--no-force-uppercase-builtins" not in args: - args.append("--force-uppercase-builtins") if "--no-force-union-syntax" not in args: args.append("--force-union-syntax") # Type check the program. diff --git a/mypy/test/testmerge.py b/mypy/test/testmerge.py index 51a4ff39dd9a..c2c75f60be29 100644 --- a/mypy/test/testmerge.py +++ b/mypy/test/testmerge.py @@ -102,7 +102,6 @@ def build(self, source: str, testcase: DataDrivenTestCase) -> BuildResult | None options.export_types = True options.show_traceback = True options.allow_empty_bodies = True - options.force_uppercase_builtins = True main_path = os.path.join(test_temp_dir, "main") self.str_conv.options = options diff --git a/mypy/test/testparse.py b/mypy/test/testparse.py index 074ccfb379d0..027ca4dd2887 100644 --- a/mypy/test/testparse.py +++ b/mypy/test/testparse.py @@ -38,7 +38,6 @@ def test_parser(testcase: DataDrivenTestCase) -> None: The argument contains the description of the test case. """ options = Options() - options.force_uppercase_builtins = True options.hide_error_codes = True if testcase.file.endswith("python310.test"): diff --git a/mypy/test/testpythoneval.py b/mypy/test/testpythoneval.py index 32c07087292e..6d22aca07da7 100644 --- a/mypy/test/testpythoneval.py +++ b/mypy/test/testpythoneval.py @@ -52,7 +52,6 @@ def test_python_evaluation(testcase: DataDrivenTestCase, cache_dir: str) -> None "--no-error-summary", "--hide-error-codes", "--allow-empty-bodies", - "--force-uppercase-builtins", "--test-env", # Speeds up some checks ] interpreter = python3_path diff --git a/mypy/test/testsemanal.py b/mypy/test/testsemanal.py index a544e1f91829..741c03fc2dc2 100644 --- a/mypy/test/testsemanal.py +++ b/mypy/test/testsemanal.py @@ -44,7 +44,6 @@ def get_semanal_options(program_text: str, testcase: DataDrivenTestCase) -> Opti options.semantic_analysis_only = True options.show_traceback = True options.python_version = PYTHON3_VERSION - options.force_uppercase_builtins = True return options diff --git a/mypy/test/testtransform.py b/mypy/test/testtransform.py index 9388dca02c7a..48a3eeed2115 100644 --- a/mypy/test/testtransform.py +++ b/mypy/test/testtransform.py @@ -38,7 +38,6 @@ def test_transform(testcase: DataDrivenTestCase) -> None: options.use_builtins_fixtures = True options.semantic_analysis_only = True options.show_traceback = True - options.force_uppercase_builtins = True result = build.build( sources=[BuildSource("main", None, src)], options=options, alt_lib_path=test_temp_dir ) diff --git a/mypy/test/testtypegen.py b/mypy/test/testtypegen.py index 4933bd3522a0..42d831beeecc 100644 --- a/mypy/test/testtypegen.py +++ b/mypy/test/testtypegen.py @@ -35,7 +35,6 @@ def run_case(self, testcase: DataDrivenTestCase) -> None: options.export_types = True options.preserve_asts = True options.allow_empty_bodies = True - options.force_uppercase_builtins = True result = build.build( sources=[BuildSource("main", None, src)], options=options, From 832119f77c318b3ca2d5700b1d548c3f275d28c3 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 29 May 2025 19:37:17 +0200 Subject: [PATCH 2/4] Fix TupleType str test case --- mypy/test/testtypes.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/mypy/test/testtypes.py b/mypy/test/testtypes.py index 63d8840fa217..0fe41bc28ecd 100644 --- a/mypy/test/testtypes.py +++ b/mypy/test/testtypes.py @@ -23,7 +23,6 @@ Expression, NameExpr, ) -from mypy.options import Options from mypy.plugins.common import find_shallow_matching_overload_item from mypy.state import state from mypy.subtypes import is_more_precise, is_proper_subtype, is_same_type, is_subtype @@ -130,17 +129,13 @@ def test_callable_type_with_var_args(self) -> None: ) assert_equal(str(c3), "def (X? =, *Y?) -> Any") - def test_tuple_type_upper(self) -> None: - options = Options() - options.force_uppercase_builtins = True - assert_equal(TupleType([], self.fx.std_tuple).str_with_options(options), "Tuple[()]") - assert_equal(TupleType([self.x], self.fx.std_tuple).str_with_options(options), "Tuple[X?]") - assert_equal( - TupleType( - [self.x, AnyType(TypeOfAny.special_form)], self.fx.std_tuple - ).str_with_options(options), - "Tuple[X?, Any]", - ) + def test_tuple_type_str(self) -> None: + t1 = TupleType([], self.fx.std_tuple) + assert_equal(str(t1), "tuple[()]") + t2 = TupleType([self.x], self.fx.std_tuple) + assert_equal(str(t2), "tuple[X?]") + t3 = TupleType([self.x, AnyType(TypeOfAny.special_form)], self.fx.std_tuple) + assert_equal(str(t3), "tuple[X?, Any]") def test_type_variable_binding(self) -> None: assert_equal( From 2d53523e10ce6de5c8352f11a77150b591f382f5 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 29 May 2025 13:50:34 +0200 Subject: [PATCH 3/4] Update all other test cases --- test-data/unit/check-abstract.test | 18 +- test-data/unit/check-annotated.test | 2 +- test-data/unit/check-async-await.test | 10 +- test-data/unit/check-basic.test | 24 +- test-data/unit/check-class-namedtuple.test | 52 +-- test-data/unit/check-classes.test | 192 ++++++------ test-data/unit/check-columns.test | 18 +- test-data/unit/check-ctypes.test | 8 +- test-data/unit/check-custom-plugin.test | 2 +- test-data/unit/check-dataclass-transform.test | 12 +- test-data/unit/check-dataclasses.test | 32 +- test-data/unit/check-deprecated.test | 2 +- test-data/unit/check-dynamic-typing.test | 8 +- test-data/unit/check-enum.test | 20 +- test-data/unit/check-errorcodes.test | 10 +- test-data/unit/check-expressions.test | 52 +-- test-data/unit/check-final.test | 4 +- test-data/unit/check-flags.test | 54 ++-- test-data/unit/check-formatting.test | 4 +- test-data/unit/check-functions.test | 44 +-- test-data/unit/check-functools.test | 8 +- test-data/unit/check-generic-alias.test | 14 +- test-data/unit/check-generic-subtyping.test | 4 +- test-data/unit/check-generics.test | 72 ++--- test-data/unit/check-incremental.test | 18 +- test-data/unit/check-inference-context.test | 22 +- test-data/unit/check-inference.test | 200 ++++++------ test-data/unit/check-inline-config.test | 2 +- test-data/unit/check-isinstance.test | 142 ++++----- test-data/unit/check-kwargs.test | 26 +- test-data/unit/check-literal.test | 66 ++-- test-data/unit/check-modules.test | 8 +- test-data/unit/check-namedtuple.test | 142 ++++----- test-data/unit/check-narrowing.test | 220 ++++++------- test-data/unit/check-newsemanal.test | 64 ++-- test-data/unit/check-newsyntax.test | 2 +- test-data/unit/check-newtype.test | 4 +- test-data/unit/check-optional.test | 10 +- test-data/unit/check-overloading.test | 60 ++-- .../unit/check-parameter-specification.test | 26 +- test-data/unit/check-plugin-attrs.test | 62 ++-- test-data/unit/check-protocols.test | 84 ++--- test-data/unit/check-python310.test | 56 ++-- test-data/unit/check-python311.test | 16 +- test-data/unit/check-python312.test | 20 +- test-data/unit/check-python313.test | 8 +- test-data/unit/check-python38.test | 8 +- test-data/unit/check-recursive-types.test | 58 ++-- test-data/unit/check-redefine.test | 2 +- test-data/unit/check-redefine2.test | 4 +- test-data/unit/check-selftype.test | 88 +++--- test-data/unit/check-serialize.test | 36 +-- test-data/unit/check-statements.test | 6 +- test-data/unit/check-tuples.test | 216 ++++++------- test-data/unit/check-type-aliases.test | 48 +-- .../check-type-object-type-inference.test | 16 +- test-data/unit/check-typeddict.test | 66 ++-- test-data/unit/check-typeguard.test | 8 +- test-data/unit/check-typeis.test | 6 +- test-data/unit/check-typevar-defaults.test | 38 +-- test-data/unit/check-typevar-tuple.test | 296 +++++++++--------- test-data/unit/check-typevar-values.test | 2 +- test-data/unit/check-union-or-syntax.test | 4 +- test-data/unit/check-unions.test | 52 +-- test-data/unit/check-varargs.test | 84 ++--- test-data/unit/check-warnings.test | 2 +- test-data/unit/cmdline.test | 8 +- test-data/unit/fine-grained-inspect.test | 2 +- test-data/unit/fine-grained-python312.test | 4 +- test-data/unit/fine-grained.test | 66 ++-- test-data/unit/merge.test | 16 +- test-data/unit/parse.test | 8 +- test-data/unit/pythoneval.test | 78 ++--- test-data/unit/semanal-classes.test | 6 +- test-data/unit/semanal-namedtuple.test | 30 +- test-data/unit/semanal-typealiases.test | 8 +- test-data/unit/semanal-types.test | 10 +- test-data/unit/typexport-basic.test | 10 +- 78 files changed, 1605 insertions(+), 1605 deletions(-) diff --git a/test-data/unit/check-abstract.test b/test-data/unit/check-abstract.test index 455ee3c5265b..2fed3425c8d4 100644 --- a/test-data/unit/check-abstract.test +++ b/test-data/unit/check-abstract.test @@ -191,8 +191,8 @@ def f(cls: Type[A]) -> A: def g() -> A: return A() # E: Cannot instantiate abstract class "A" with abstract attribute "m" -f(A) # E: Only concrete class can be given where "Type[A]" is expected -f(B) # E: Only concrete class can be given where "Type[A]" is expected +f(A) # E: Only concrete class can be given where "type[A]" is expected +f(B) # E: Only concrete class can be given where "type[A]" is expected f(C) # OK x: Type[B] f(x) # OK @@ -207,7 +207,7 @@ class Class: def method(self) -> None: pass -my_dict_init: Dict[int, Type[Class]] = {0: Class} # E: Only concrete class can be given where "Tuple[int, Type[Class]]" is expected +my_dict_init: Dict[int, Type[Class]] = {0: Class} # E: Only concrete class can be given where "tuple[int, type[Class]]" is expected class Child(Class): def method(self) -> None: ... @@ -235,7 +235,7 @@ Alias = A GoodAlias = C Alias() # E: Cannot instantiate abstract class "A" with abstract attribute "m" GoodAlias() -f(Alias) # E: Only concrete class can be given where "Type[A]" is expected +f(Alias) # E: Only concrete class can be given where "type[A]" is expected f(GoodAlias) [out] @@ -255,18 +255,18 @@ class C(B): var: Type[A] var() if int(): - var = A # E: Can only assign concrete classes to a variable of type "Type[A]" + var = A # E: Can only assign concrete classes to a variable of type "type[A]" if int(): - var = B # E: Can only assign concrete classes to a variable of type "Type[A]" + var = B # E: Can only assign concrete classes to a variable of type "type[A]" if int(): var = C # OK var_old = None # type: Type[A] # Old syntax for variable annotations var_old() if int(): - var_old = A # E: Can only assign concrete classes to a variable of type "Type[A]" + var_old = A # E: Can only assign concrete classes to a variable of type "type[A]" if int(): - var_old = B # E: Can only assign concrete classes to a variable of type "Type[A]" + var_old = B # E: Can only assign concrete classes to a variable of type "type[A]" if int(): var_old = C # OK @@ -277,7 +277,7 @@ class D(A): def __new__(cls) -> "D": ... def __new__(cls, a=None) -> "D": ... if int(): - var = D # E: Can only assign concrete classes to a variable of type "Type[A]" + var = D # E: Can only assign concrete classes to a variable of type "type[A]" [out] [case testInstantiationAbstractsInTypeForClassMethods] diff --git a/test-data/unit/check-annotated.test b/test-data/unit/check-annotated.test index 54d9715a3897..24f4a1d945c6 100644 --- a/test-data/unit/check-annotated.test +++ b/test-data/unit/check-annotated.test @@ -105,7 +105,7 @@ from typing_extensions import Annotated T = TypeVar('T') Alias = Annotated[Tuple[T, T], ...] x: Alias[int] -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int]" [builtins fixtures/tuple.pyi] [case testAnnotatedAliasGenericUnion] diff --git a/test-data/unit/check-async-await.test b/test-data/unit/check-async-await.test index 0ef08e5a0775..979da62aca92 100644 --- a/test-data/unit/check-async-await.test +++ b/test-data/unit/check-async-await.test @@ -163,7 +163,7 @@ async def f() -> None: [builtins fixtures/async_await.pyi] [typing fixtures/typing-async.pyi] [out] -main:4: error: "List[int]" has no attribute "__aiter__" (not async iterable) +main:4: error: "list[int]" has no attribute "__aiter__" (not async iterable) [case testAsyncForErrorNote] @@ -502,7 +502,7 @@ async def gen() -> AsyncGenerator[int, str]: async def h() -> None: g = gen() - await g.asend(()) # E: Argument 1 to "asend" of "AsyncGenerator" has incompatible type "Tuple[()]"; expected "str" + await g.asend(()) # E: Argument 1 to "asend" of "AsyncGenerator" has incompatible type "tuple[()]"; expected "str" reveal_type(await g.asend('hello')) # N: Revealed type is "builtins.int" [builtins fixtures/dict.pyi] @@ -913,9 +913,9 @@ async def test(x: Sub[D], tx: Type[Sub[D]]) -> None: unknown2: Awaitable[Any] d: C = unknown2 # E: Incompatible types in assignment (expression has type "Awaitable[Any]", variable has type "C") - # The notes are not show for Type[...] (because awaiting them will not work) - tx.x # E: "Type[Sub[D]]" has no attribute "x" - a2: C = tx # E: Incompatible types in assignment (expression has type "Type[Sub[D]]", variable has type "C") + # The notes are not show for type[...] (because awaiting them will not work) + tx.x # E: "type[Sub[D]]" has no attribute "x" + a2: C = tx # E: Incompatible types in assignment (expression has type "type[Sub[D]]", variable has type "C") class F: def __await__(self: T) -> Generator[Any, Any, T]: ... diff --git a/test-data/unit/check-basic.test b/test-data/unit/check-basic.test index 3f2164bf5a24..07ed5fd77082 100644 --- a/test-data/unit/check-basic.test +++ b/test-data/unit/check-basic.test @@ -378,7 +378,7 @@ reveal_type(b) # N: Revealed type is "Literal[False]" from typing import List x: List[int] y: List[float] -y = x # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[float]") \ +y = x # E: Incompatible types in assignment (expression has type "list[int]", variable has type "list[float]") \ # N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \ # N: Consider using "Sequence" instead, which is covariant [builtins fixtures/list.pyi] @@ -387,7 +387,7 @@ y = x # E: Incompatible types in assignment (expression has type "List[int]", va from typing import Dict x: Dict[str, int] y: Dict[str, float] -y = x # E: Incompatible types in assignment (expression has type "Dict[str, int]", variable has type "Dict[str, float]") \ +y = x # E: Incompatible types in assignment (expression has type "dict[str, int]", variable has type "dict[str, float]") \ # N: "dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \ # N: Consider using "Mapping" instead, which is covariant in the value type [builtins fixtures/dict.pyi] @@ -420,7 +420,7 @@ def foo() -> Optional[A]: def bar() -> List[A]: l = [a.A()] - return l # E: Incompatible return value type (got "List[a.A]", expected "List[b.A]") + return l # E: Incompatible return value type (got "list[a.A]", expected "list[b.A]") def baz() -> Union[A, int]: b = True @@ -431,37 +431,37 @@ def spam() -> Optional[A]: def eggs() -> Sequence[A]: x = [a.A()] - return x # E: Incompatible return value type (got "List[a.A]", expected "Sequence[b.A]") + return x # E: Incompatible return value type (got "list[a.A]", expected "Sequence[b.A]") def eggs2() -> Sequence[N]: x = [a.N(0)] - return x # E: Incompatible return value type (got "List[a.N]", expected "Sequence[b.N]") + return x # E: Incompatible return value type (got "list[a.N]", expected "Sequence[b.N]") def asdf1() -> Sequence[Tuple[a.A, A]]: x = [(a.A(), a.A())] - return x # E: Incompatible return value type (got "List[Tuple[a.A, a.A]]", expected "Sequence[Tuple[a.A, b.A]]") + return x # E: Incompatible return value type (got "list[tuple[a.A, a.A]]", expected "Sequence[tuple[a.A, b.A]]") def asdf2() -> Sequence[Tuple[A, a.A]]: x = [(a.A(), a.A())] - return x # E: Incompatible return value type (got "List[Tuple[a.A, a.A]]", expected "Sequence[Tuple[b.A, a.A]]") + return x # E: Incompatible return value type (got "list[tuple[a.A, a.A]]", expected "Sequence[tuple[b.A, a.A]]") def arg() -> Tuple[A, A]: - return A() # E: Incompatible return value type (got "A", expected "Tuple[A, A]") + return A() # E: Incompatible return value type (got "A", expected "tuple[A, A]") def types() -> Sequence[Type[A]]: x = [a.A] - return x # E: Incompatible return value type (got "List[Type[a.A]]", expected "Sequence[Type[b.A]]") + return x # E: Incompatible return value type (got "list[type[a.A]]", expected "Sequence[type[b.A]]") def literal() -> Sequence[Literal[B.b]]: x = [a.B.b] # type: List[Literal[a.B.b]] - return x # E: Incompatible return value type (got "List[Literal[a.B.b]]", expected "Sequence[Literal[b.B.b]]") + return x # E: Incompatible return value type (got "list[Literal[a.B.b]]", expected "Sequence[Literal[b.B.b]]") def typeddict() -> Sequence[D]: x = [{'x': 0}] # type: List[a.D] - return x # E: Incompatible return value type (got "List[a.D]", expected "Sequence[b.D]") + return x # E: Incompatible return value type (got "list[a.D]", expected "Sequence[b.D]") a = (a.A(), A()) -a.x # E: "Tuple[a.A, b.A]" has no attribute "x" +a.x # E: "tuple[a.A, b.A]" has no attribute "x" [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] diff --git a/test-data/unit/check-class-namedtuple.test b/test-data/unit/check-class-namedtuple.test index fd564c7e96cb..fe8a1551f81b 100644 --- a/test-data/unit/check-class-namedtuple.test +++ b/test-data/unit/check-class-namedtuple.test @@ -187,9 +187,9 @@ t: Tuple[int, str] if int(): b = a # E: Incompatible types in assignment (expression has type "A", variable has type "B") if int(): - a = t # E: Incompatible types in assignment (expression has type "Tuple[int, str]", variable has type "A") + a = t # E: Incompatible types in assignment (expression has type "tuple[int, str]", variable has type "A") if int(): - b = t # E: Incompatible types in assignment (expression has type "Tuple[int, str]", variable has type "B") + b = t # E: Incompatible types in assignment (expression has type "tuple[int, str]", variable has type "B") if int(): t = a if int(): @@ -212,7 +212,7 @@ a = l[0] (i,) = l[0] i, i = l[0] # E: Need more than 1 value to unpack (2 expected) l = [A(1)] -a = (1,) # E: Incompatible types in assignment (expression has type "Tuple[int]", \ +a = (1,) # E: Incompatible types in assignment (expression has type "tuple[int]", \ variable has type "A") [builtins fixtures/list.pyi] @@ -223,7 +223,7 @@ class MyNamedTuple(NamedTuple): a: int b: str -MyNamedTuple.x # E: "Type[MyNamedTuple]" has no attribute "x" +MyNamedTuple.x # E: "type[MyNamedTuple]" has no attribute "x" [builtins fixtures/tuple.pyi] [case testNewNamedTupleEmptyItems] @@ -281,7 +281,7 @@ class X(NamedTuple): y: str x: X -reveal_type(x._replace()) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.X]" +reveal_type(x._replace()) # N: Revealed type is "tuple[builtins.int, builtins.str, fallback=__main__.X]" x._replace(x=5) x._replace(y=5) # E: Argument "y" to "_replace" of "X" has incompatible type "int"; expected "str" [builtins fixtures/tuple.pyi] @@ -293,7 +293,7 @@ class X(NamedTuple): x: int y: str -reveal_type(X._fields) # N: Revealed type is "Tuple[builtins.str, builtins.str]" +reveal_type(X._fields) # N: Revealed type is "tuple[builtins.str, builtins.str]" reveal_type(X._field_types) # N: Revealed type is "builtins.dict[builtins.str, Any]" reveal_type(X._field_defaults) # N: Revealed type is "builtins.dict[builtins.str, Any]" @@ -324,7 +324,7 @@ class Y(NamedTuple): x: int y: str -reveal_type([X(3, 'b'), Y(1, 'a')]) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.str]]" +reveal_type([X(3, 'b'), Y(1, 'a')]) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.str]]" [builtins fixtures/list.pyi] @@ -335,8 +335,8 @@ class X(NamedTuple): x: int y: str -reveal_type([(3, 'b'), X(1, 'a')]) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.str]]" -reveal_type([X(1, 'a'), (3, 'b')]) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.str]]" +reveal_type([(3, 'b'), X(1, 'a')]) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.str]]" +reveal_type([X(1, 'a'), (3, 'b')]) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.str]]" [builtins fixtures/list.pyi] @@ -386,8 +386,8 @@ class X(NamedTuple): x: int y: int = 2 -reveal_type(X(1)) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.X]" -reveal_type(X(1, 2)) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.X]" +reveal_type(X(1)) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.X]" +reveal_type(X(1, 2)) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.X]" X(1, 'a') # E: Argument 2 to "X" has incompatible type "str"; expected "int" X(1, z=3) # E: Unexpected keyword argument "z" for "X" @@ -396,14 +396,14 @@ class HasNone(NamedTuple): x: int y: Optional[int] = None -reveal_type(HasNone(1)) # N: Revealed type is "Tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]" +reveal_type(HasNone(1)) # N: Revealed type is "tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]" class Parameterized(NamedTuple): x: int y: List[int] = [1] + [2] z: List[int] = [] -reveal_type(Parameterized(1)) # N: Revealed type is "Tuple[builtins.int, builtins.list[builtins.int], builtins.list[builtins.int], fallback=__main__.Parameterized]" +reveal_type(Parameterized(1)) # N: Revealed type is "tuple[builtins.int, builtins.list[builtins.int], builtins.list[builtins.int], fallback=__main__.Parameterized]" Parameterized(1, ['not an int']) # E: List item 0 has incompatible type "str"; expected "int" class Default: @@ -412,8 +412,8 @@ class Default: class UserDefined(NamedTuple): x: Default = Default() -reveal_type(UserDefined()) # N: Revealed type is "Tuple[__main__.Default, fallback=__main__.UserDefined]" -reveal_type(UserDefined(Default())) # N: Revealed type is "Tuple[__main__.Default, fallback=__main__.UserDefined]" +reveal_type(UserDefined()) # N: Revealed type is "tuple[__main__.Default, fallback=__main__.UserDefined]" +reveal_type(UserDefined(Default())) # N: Revealed type is "tuple[__main__.Default, fallback=__main__.UserDefined]" UserDefined(1) # E: Argument 1 to "UserDefined" has incompatible type "int"; expected "Default" [builtins fixtures/list.pyi] @@ -425,7 +425,7 @@ class HasNone(NamedTuple): x: int y: Optional[int] = None -reveal_type(HasNone(1)) # N: Revealed type is "Tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]" +reveal_type(HasNone(1)) # N: Revealed type is "tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]" HasNone(None) # E: Argument 1 to "HasNone" has incompatible type "None"; expected "int" HasNone(1, y=None) HasNone(1, y=2) @@ -463,7 +463,7 @@ class Y(X): self.y return self.x -reveal_type(Y('a')) # N: Revealed type is "Tuple[builtins.str, builtins.int, fallback=__main__.Y]" +reveal_type(Y('a')) # N: Revealed type is "tuple[builtins.str, builtins.int, fallback=__main__.Y]" Y(y=1, x='1').method() class CallsBaseInit(X): @@ -511,7 +511,7 @@ class Overloader(NamedTuple): reveal_type(Overloader(1).method('string')) # N: Revealed type is "builtins.str" reveal_type(Overloader(1).method(1)) # N: Revealed type is "builtins.int" -Overloader(1).method(('tuple',)) # E: No overload variant of "method" of "Overloader" matches argument type "Tuple[str]" \ +Overloader(1).method(('tuple',)) # E: No overload variant of "method" of "Overloader" matches argument type "tuple[str]" \ # N: Possible overload variants: \ # N: def method(self, y: str) -> str \ # N: def method(self, y: int) -> int @@ -528,7 +528,7 @@ class Base(NamedTuple): reveal_type(self) # N: Revealed type is "T`-1" return self def good_override(self) -> int: - reveal_type(self) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.Base]" + reveal_type(self) # N: Revealed type is "tuple[builtins.int, fallback=__main__.Base]" reveal_type(self[0]) # N: Revealed type is "builtins.int" self[0] = 3 # E: Unsupported target for indexed assignment ("Base") reveal_type(self.x) # N: Revealed type is "builtins.int" @@ -538,14 +538,14 @@ class Base(NamedTuple): # E: No overload variant of "__getitem__" of "tuple" matches argument type "TypeVar" \ # N: Possible overload variants: \ # N: def __getitem__(self, int, /) -> int \ - # N: def __getitem__(self, slice, /) -> Tuple[int, ...] + # N: def __getitem__(self, slice, /) -> tuple[int, ...] return self.x def bad_override(self) -> int: return self.x class Child(Base): def new_method(self) -> int: - reveal_type(self) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.Child]" + reveal_type(self) # N: Revealed type is "tuple[builtins.int, fallback=__main__.Child]" reveal_type(self[0]) # N: Revealed type is "builtins.int" self[0] = 3 # E: Unsupported target for indexed assignment ("Child") reveal_type(self.x) # N: Revealed type is "builtins.int" @@ -560,8 +560,8 @@ class Child(Base): def takes_base(base: Base) -> int: return base.x -reveal_type(Base(1).copy()) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.Base]" -reveal_type(Child(1).copy()) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.Child]" +reveal_type(Base(1).copy()) # N: Revealed type is "tuple[builtins.int, fallback=__main__.Base]" +reveal_type(Child(1).copy()) # N: Revealed type is "tuple[builtins.int, fallback=__main__.Child]" reveal_type(Base(1).good_override()) # N: Revealed type is "builtins.int" reveal_type(Child(1).good_override()) # N: Revealed type is "builtins.int" reveal_type(Base(1).bad_override()) # N: Revealed type is "builtins.int" @@ -635,8 +635,8 @@ class HasClassMethod(NamedTuple): @classmethod def new(cls, f: str) -> 'HasClassMethod': - reveal_type(cls) # N: Revealed type is "Type[Tuple[builtins.str, fallback=__main__.HasClassMethod]]" - reveal_type(HasClassMethod) # N: Revealed type is "def (x: builtins.str) -> Tuple[builtins.str, fallback=__main__.HasClassMethod]" + reveal_type(cls) # N: Revealed type is "type[tuple[builtins.str, fallback=__main__.HasClassMethod]]" + reveal_type(HasClassMethod) # N: Revealed type is "def (x: builtins.str) -> tuple[builtins.str, fallback=__main__.HasClassMethod]" return cls(x=f) [builtins fixtures/classmethod.pyi] @@ -661,7 +661,7 @@ class HasStaticMethod(NamedTuple): @property def size(self) -> int: - reveal_type(self) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.HasStaticMethod]" + reveal_type(self) # N: Revealed type is "tuple[builtins.str, fallback=__main__.HasStaticMethod]" return 4 [builtins fixtures/property.pyi] diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index e0ea00aee361..93b575e25309 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -151,19 +151,19 @@ class Derived(Base): # This was crashing: https://github.com/python/mypy/issues/11686. class Base: def __init__(self, arg: int): - self.partial_type = [] # E: Need type annotation for "partial_type" (hint: "partial_type: List[] = ...") + self.partial_type = [] # E: Need type annotation for "partial_type" (hint: "partial_type: list[] = ...") self.force_deferral = [] # Force inference of the `force_deferral` attribute in `__init__` to be # deferred to a later pass by providing a definition in another context, # which means `partial_type` remains only partially inferred. - force_deferral = [] # E: Need type annotation for "force_deferral" (hint: "force_deferral: List[] = ...") + force_deferral = [] # E: Need type annotation for "force_deferral" (hint: "force_deferral: list[] = ...") class Derived(Base): def partial_type(self) -> int: # E: Signature of "partial_type" incompatible with supertype "Base" \ # N: Superclass: \ - # N: List[Any] \ + # N: list[Any] \ # N: Subclass: \ # N: def partial_type(self) -> int ... @@ -1162,7 +1162,7 @@ b = A.x # type: B # E: Incompatible types in assignment (expression has type "A" [case testAccessingUndefinedAttributeViaClass] import typing class A: pass -A.x # E: "Type[A]" has no attribute "x" +A.x # E: "type[A]" has no attribute "x" [case testAccessingUndefinedAttributeViaClassWithOverloadedInit] from foo import * @@ -1173,7 +1173,7 @@ class A: def __init__(self): pass @overload def __init__(self, x): pass -A.x # E: "Type[A]" has no attribute "x" +A.x # E: "type[A]" has no attribute "x" [case testAccessMethodOfClassWithOverloadedInit] from foo import * @@ -1227,7 +1227,7 @@ import typing class A: class B: pass A.B = None # E: Cannot assign to a type \ - # E: Incompatible types in assignment (expression has type "None", variable has type "Type[B]") + # E: Incompatible types in assignment (expression has type "None", variable has type "type[B]") [targets __main__] [case testAccessingClassAttributeWithTypeInferenceIssue] @@ -1243,7 +1243,7 @@ class C: x = C.x [builtins fixtures/list.pyi] [out] -main:2: error: Need type annotation for "x" (hint: "x: List[] = ...") +main:2: error: Need type annotation for "x" (hint: "x: list[] = ...") [case testAccessingGenericClassAttribute] from typing import Generic, TypeVar @@ -1510,7 +1510,7 @@ class C: cls(1) # E: Too many arguments for "C" cls.bar() cls.bar(1) # E: Too many arguments for "bar" of "C" - cls.bozo() # E: "Type[C]" has no attribute "bozo" + cls.bozo() # E: "type[C]" has no attribute "bozo" [builtins fixtures/classmethod.pyi] [out] @@ -1521,7 +1521,7 @@ class C: def foo(cls) -> None: pass C.foo() C.foo(1) # E: Too many arguments for "foo" of "C" -C.bozo() # E: "Type[C]" has no attribute "bozo" +C.bozo() # E: "type[C]" has no attribute "bozo" [builtins fixtures/classmethod.pyi] [case testClassMethodCalledOnInstance] @@ -1531,7 +1531,7 @@ class C: def foo(cls) -> None: pass C().foo() C().foo(1) # E: Too many arguments for "foo" of "C" -C.bozo() # E: "Type[C]" has no attribute "bozo" +C.bozo() # E: "type[C]" has no attribute "bozo" [builtins fixtures/classmethod.pyi] [case testClassMethodMayCallAbstractMethod] @@ -1791,12 +1791,12 @@ class D: def __get__(self, inst: Base, own: Type[Base]) -> str: pass [builtins fixtures/bool.pyi] [out] -main:4: error: Argument 2 to "__get__" of "D" has incompatible type "Type[A]"; expected "Type[Base]" +main:4: error: Argument 2 to "__get__" of "D" has incompatible type "type[A]"; expected "type[Base]" main:4: note: Revealed type is "d.D" -main:5: error: No overload variant of "__get__" of "D" matches argument types "A", "Type[A]" +main:5: error: No overload variant of "__get__" of "D" matches argument types "A", "type[A]" main:5: note: Possible overload variants: -main:5: note: def __get__(self, inst: None, own: Type[Base]) -> D -main:5: note: def __get__(self, inst: Base, own: Type[Base]) -> str +main:5: note: def __get__(self, inst: None, own: type[Base]) -> D +main:5: note: def __get__(self, inst: Base, own: type[Base]) -> str main:5: note: Revealed type is "Any" [case testAccessingGenericNonDataDescriptor] @@ -1890,10 +1890,10 @@ class D(Generic[T, V]): def __get__(self, inst: T, own: Type[T]) -> V: pass [builtins fixtures/bool.pyi] [out] -main:4: error: No overload variant of "__get__" of "D" matches argument types "None", "Type[A]" +main:4: error: No overload variant of "__get__" of "D" matches argument types "None", "type[A]" main:4: note: Possible overload variants: main:4: note: def __get__(self, inst: None, own: None) -> D[A, int] -main:4: note: def __get__(self, inst: A, own: Type[A]) -> int +main:4: note: def __get__(self, inst: A, own: type[A]) -> int main:4: note: Revealed type is "Any" [case testAccessingNonDataDescriptorSubclass] @@ -2052,7 +2052,7 @@ class D: def __get__(self, inst: Any, own: str) -> Any: pass class A: f = D() -A().f # E: Argument 2 to "__get__" of "D" has incompatible type "Type[A]"; expected "str" +A().f # E: Argument 2 to "__get__" of "D" has incompatible type "type[A]"; expected "str" [case testDescriptorGetSetDifferentTypes] from typing import Any @@ -2616,7 +2616,7 @@ from typing import TypeVar, Type class Real(type): def __add__(self, other: FractionChild) -> str: ... class Fraction(Real): - def __radd__(self, other: Type['A']) -> Real: ... # E: Signatures of "__radd__" of "Fraction" and "__add__" of "Type[A]" are unsafely overlapping + def __radd__(self, other: Type['A']) -> Real: ... # E: Signatures of "__radd__" of "Fraction" and "__add__" of "type[A]" are unsafely overlapping class FractionChild(Fraction): pass class A(metaclass=Real): pass @@ -3243,7 +3243,7 @@ class C: def f(x: type) -> None: pass def g(x: int) -> None: pass f(C) -g(C) # E: Argument 1 to "g" has incompatible type "Type[C]"; expected "int" +g(C) # E: Argument 1 to "g" has incompatible type "type[C]"; expected "int" [builtins fixtures/__new__.pyi] [case testClassWith__new__AndCompatibilityWithType2] @@ -3254,7 +3254,7 @@ class C: def f(x: type) -> None: pass def g(x: int) -> None: pass f(C) -g(C) # E: Argument 1 to "g" has incompatible type "Type[C]"; expected "int" +g(C) # E: Argument 1 to "g" has incompatible type "type[C]"; expected "int" [builtins fixtures/__new__.pyi] [case testGenericClassWith__new__] @@ -3339,7 +3339,7 @@ class B: [case testClassVsInstanceDisambiguation] class A: pass def f(x: A) -> None: pass -f(A) # E: Argument 1 to "f" has incompatible type "Type[A]"; expected "A" +f(A) # E: Argument 1 to "f" has incompatible type "type[A]"; expected "A" [out] -- TODO @@ -3393,7 +3393,7 @@ class A(Generic[T]): class B(Generic[T]): a: Type[A[T]] = A -reveal_type(B[int]().a) # N: Revealed type is "Type[__main__.A[builtins.int]]" +reveal_type(B[int]().a) # N: Revealed type is "type[__main__.A[builtins.int]]" B[int]().a('hi') # E: Argument 1 to "A" has incompatible type "str"; expected "int" class C(Generic[T]): @@ -3548,7 +3548,7 @@ class User: pass def new_user(user_class: Type[User]): return user_class() def foo(arg: Type[int]): - new_user(arg) # E: Argument 1 to "new_user" has incompatible type "Type[int]"; expected "Type[User]" + new_user(arg) # E: Argument 1 to "new_user" has incompatible type "type[int]"; expected "type[User]" [out] [case testTypeUsingTypeCUnionOverload] @@ -3587,8 +3587,8 @@ def foo(arg: Type[Any]): arg.new_member_name = 42 # Member access is ok and types as Any reveal_type(x) # N: Revealed type is "Any" - # But Type[Any] is distinct from Any - y: int = arg # E: Incompatible types in assignment (expression has type "Type[Any]", variable has type "int") + # But type[Any] is distinct from Any + y: int = arg # E: Incompatible types in assignment (expression has type "type[Any]", variable has type "int") [out] [case testTypeUsingTypeCTypeAnyMemberFallback] @@ -3629,7 +3629,7 @@ def process(cls: Type[User]): obj = cls() reveal_type(cls.bar(obj)) # N: Revealed type is "builtins.int" cls.mro() # Defined in class type - cls.error # E: "Type[User]" has no attribute "error" + cls.error # E: "type[User]" has no attribute "error" [builtins fixtures/classmethod.pyi] [out] @@ -3646,7 +3646,7 @@ def process(cls: Type[Union[BasicUser, ProUser]]): obj = cls() cls.bar(obj) cls.mro() # Defined in class type - cls.error # E: Item "type" of "Union[Type[BasicUser], Type[ProUser]]" has no attribute "error" + cls.error # E: Item "type" of "Union[type[BasicUser], type[ProUser]]" has no attribute "error" [builtins fixtures/classmethod.pyi] [out] @@ -3662,7 +3662,7 @@ def process(cls: Type[U]): obj = cls() reveal_type(cls.bar(obj)) # N: Revealed type is "builtins.int" cls.mro() # Defined in class type - cls.error # E: "Type[U]" has no attribute "error" + cls.error # E: "type[U]" has no attribute "error" [builtins fixtures/classmethod.pyi] [out] @@ -3681,14 +3681,14 @@ def process(cls: Type[U]): obj = cls() cls.bar(obj) cls.mro() # Defined in class type - cls.error # E: "Type[U]" has no attribute "error" + cls.error # E: "type[U]" has no attribute "error" [builtins fixtures/classmethod.pyi] [out] [case testTypeUsingTypeCErrorUnsupportedType] from typing import Type, Tuple def foo(arg: Type[Tuple[int]]): - arg() # E: Cannot instantiate type "Type[Tuple[int]]" + arg() # E: Cannot instantiate type "Type[tuple[int]]" [builtins fixtures/tuple.pyi] [case testTypeUsingTypeCOverloadedClass] @@ -3732,7 +3732,7 @@ def f(a: T): pass [case testTypeUsingTypeCTuple] from typing import Type, Tuple def f(a: Type[Tuple[int, int]]): - a() # E: Cannot instantiate type "Type[Tuple[int, int]]" + a() # E: Cannot instantiate type "Type[tuple[int, int]]" [builtins fixtures/tuple.pyi] [case testTypeUsingTypeCNamedTuple] @@ -3755,7 +3755,7 @@ def foo(c: Type[C], d: Type[D]) -> None: [builtins fixtures/list.pyi] [out] -main:7: note: Revealed type is "builtins.list[Type[__main__.B]]" +main:7: note: Revealed type is "builtins.list[type[__main__.B]]" [case testTypeEquivalentTypeAny] from typing import Type, Any @@ -3892,9 +3892,9 @@ def f(a: int) -> Type[User]: def f(a: str) -> User: return User() -reveal_type(f(User())) # N: Revealed type is "Type[foo.User]" +reveal_type(f(User())) # N: Revealed type is "type[foo.User]" reveal_type(f(User)) # N: Revealed type is "foo.User" -reveal_type(f(3)) # N: Revealed type is "Type[foo.User]" +reveal_type(f(3)) # N: Revealed type is "type[foo.User]" reveal_type(f("hi")) # N: Revealed type is "foo.User" [builtins fixtures/classmethod.pyi] [out] @@ -3934,7 +3934,7 @@ def f(a: type) -> None: pass f(3) # E: No overload variant of "f" matches argument type "int" \ # N: Possible overload variants: \ - # N: def f(a: Type[User]) -> None \ + # N: def f(a: type[User]) -> None \ # N: def f(a: type) -> None [builtins fixtures/classmethod.pyi] [out] @@ -3954,7 +3954,7 @@ def f(a: int) -> None: pass f(User) f(User()) # E: No overload variant of "f" matches argument type "User" \ # N: Possible overload variants: \ - # N: def f(a: Type[User]) -> None \ + # N: def f(a: type[User]) -> None \ # N: def f(a: int) -> None [builtins fixtures/classmethod.pyi] [out] @@ -3976,10 +3976,10 @@ def f(a: Type[B]) -> None: pass @overload def f(a: int) -> None: pass -f(A) # E: Argument 1 to "f" has incompatible type "Type[A]"; expected "Type[B]" +f(A) # E: Argument 1 to "f" has incompatible type "type[A]"; expected "type[B]" f(B) f(C) -f(AType) # E: Argument 1 to "f" has incompatible type "Type[A]"; expected "Type[B]" +f(AType) # E: Argument 1 to "f" has incompatible type "type[A]"; expected "type[B]" f(BType) f(CType) [builtins fixtures/classmethod.pyi] @@ -4208,7 +4208,7 @@ class User: u = User() -reveal_type(type(u)) # N: Revealed type is "Type[__main__.User]" +reveal_type(type(u)) # N: Revealed type is "type[__main__.User]" reveal_type(type(u).test_class_method()) # N: Revealed type is "builtins.int" reveal_type(type(u).test_static_method()) # N: Revealed type is "builtins.str" type(u).test_instance_method() # E: Missing positional argument "self" in call to "test_instance_method" of "User" @@ -4227,8 +4227,8 @@ def f2(func: A) -> A: u = User() -reveal_type(f1(u)) # N: Revealed type is "Type[__main__.User]" -reveal_type(f2(type)(u)) # N: Revealed type is "Type[__main__.User]" +reveal_type(f1(u)) # N: Revealed type is "type[__main__.User]" +reveal_type(f2(type)(u)) # N: Revealed type is "type[__main__.User]" [builtins fixtures/classmethod.pyi] [out] @@ -4240,7 +4240,7 @@ def fake1(a: object) -> type: def fake2(a: int) -> type: return User -reveal_type(type(User())) # N: Revealed type is "Type[__main__.User]" +reveal_type(type(User())) # N: Revealed type is "type[__main__.User]" reveal_type(fake1(User())) # N: Revealed type is "builtins.type" reveal_type(fake2(3)) # N: Revealed type is "builtins.type" [builtins fixtures/classmethod.pyi] @@ -4292,7 +4292,7 @@ int.__eq__(3, 4) [builtins fixtures/args.pyi] [out] main:33: error: Too few arguments for "__eq__" of "int" -main:33: error: Unsupported operand types for == ("int" and "Type[int]") +main:33: error: Unsupported operand types for == ("int" and "type[int]") [case testDupBaseClasses] class A: @@ -4694,7 +4694,7 @@ class M: class A(metaclass=M): pass # E: Metaclasses not inheriting from "type" are not supported -A.x # E: "Type[A]" has no attribute "x" +A.x # E: "type[A]" has no attribute "x" [case testMetaclassTypeReveal] from typing import Type @@ -4704,7 +4704,7 @@ class M(type): class A(metaclass=M): pass def f(TA: Type[A]): - reveal_type(TA) # N: Revealed type is "Type[__main__.A]" + reveal_type(TA) # N: Revealed type is "type[__main__.A]" reveal_type(TA.x) # N: Revealed type is "builtins.int" [case testMetaclassConflictingInstanceVars] @@ -4757,7 +4757,7 @@ class A(metaclass=M): pass class B(A): pass def f(TB: Type[B]): - reveal_type(TB) # N: Revealed type is "Type[__main__.B]" + reveal_type(TB) # N: Revealed type is "type[__main__.B]" reveal_type(TB.x) # N: Revealed type is "builtins.int" [case testMetaclassAsAny] @@ -4898,7 +4898,7 @@ class Concrete(metaclass=Meta): pass reveal_type(Concrete + X()) # N: Revealed type is "builtins.str" -Concrete + "hello" # E: Unsupported operand types for + ("Type[Concrete]" and "str") +Concrete + "hello" # E: Unsupported operand types for + ("type[Concrete]" and "str") [case testMetaclassOperatorTypeVar] from typing import Type, TypeVar @@ -5008,7 +5008,7 @@ class A(metaclass=M): # E: Invalid metaclass "M" class B(metaclass=MM): # E: Invalid metaclass "MM" y = 0 reveal_type(A.y) # N: Revealed type is "builtins.int" -A.x # E: "Type[A]" has no attribute "x" +A.x # E: "type[A]" has no attribute "x" [case testAnyAsBaseOfMetaclass] from typing import Any, Type @@ -5023,7 +5023,7 @@ class A(metaclass=MM): def h(a: Type[A], b: Type[object]) -> None: h(a, a) - h(b, a) # E: Argument 1 to "h" has incompatible type "Type[object]"; expected "Type[A]" + h(b, a) # E: Argument 1 to "h" has incompatible type "type[object]"; expected "type[A]" a.f(1) # E: Too many arguments for "f" of "A" reveal_type(a.y) # N: Revealed type is "builtins.int" @@ -5048,9 +5048,9 @@ TTA = TypeVar('TTA', bound='Type[A]') TM = TypeVar('TM', bound='M') class M(type): - def g1(cls: 'Type[A]') -> A: pass # E: The erased type of self "Type[__main__.A]" is not a supertype of its class "__main__.M" - def g2(cls: Type[TA]) -> TA: pass # E: The erased type of self "Type[__main__.A]" is not a supertype of its class "__main__.M" - def g3(cls: TTA) -> TTA: pass # E: The erased type of self "Type[__main__.A]" is not a supertype of its class "__main__.M" + def g1(cls: 'Type[A]') -> A: pass # E: The erased type of self "type[__main__.A]" is not a supertype of its class "__main__.M" + def g2(cls: Type[TA]) -> TA: pass # E: The erased type of self "type[__main__.A]" is not a supertype of its class "__main__.M" + def g3(cls: TTA) -> TTA: pass # E: The erased type of self "type[__main__.A]" is not a supertype of its class "__main__.M" def g4(cls: TM) -> TM: pass m: M @@ -5065,23 +5065,23 @@ 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 "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]" reveal_type(B.g4) # N: Revealed type is "def () -> def () -> __main__.B" # 4 examples of unsoundness - instantiation, classmethod, staticmethod and ClassVar: -ta: Type[A] = m # E: Incompatible types in assignment (expression has type "M", variable has type "Type[A]") +ta: Type[A] = m # E: Incompatible types in assignment (expression has type "M", variable has type "type[A]") a: A = ta() reveal_type(ta.g1) # N: Revealed type is "def () -> __main__.A" reveal_type(ta.g2) # N: Revealed type is "def () -> __main__.A" -reveal_type(ta.g3) # N: Revealed type is "def () -> Type[__main__.A]" -reveal_type(ta.g4) # N: Revealed type is "def () -> Type[__main__.A]" +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.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]" reveal_type(x.g4) # N: Revealed type is "def () -> __main__.M" @@ -5094,7 +5094,7 @@ class Class(metaclass=M): def f1(cls: Type[Class]) -> None: pass @classmethod def f2(cls: M) -> None: pass -cl: Type[Class] = m # E: Incompatible types in assignment (expression has type "M", variable has type "Type[Class]") +cl: Type[Class] = m # E: Incompatible types in assignment (expression has type "M", variable has type "type[Class]") reveal_type(cl.f1) # N: Revealed type is "def ()" reveal_type(cl.f2) # N: Revealed type is "def ()" x1: M = cl @@ -5102,14 +5102,14 @@ x1: M = cl class Static(metaclass=M): @staticmethod def f() -> None: pass -s: Type[Static] = m # E: Incompatible types in assignment (expression has type "M", variable has type "Type[Static]") +s: Type[Static] = m # E: Incompatible types in assignment (expression has type "M", variable has type "type[Static]") reveal_type(s.f) # N: Revealed type is "def ()" x2: M = s from typing import ClassVar class Cvar(metaclass=M): x = 1 # type: ClassVar[int] -cv: Type[Cvar] = m # E: Incompatible types in assignment (expression has type "M", variable has type "Type[Cvar]") +cv: Type[Cvar] = m # E: Incompatible types in assignment (expression has type "M", variable has type "type[Cvar]") cv.x x3: M = cv @@ -5178,7 +5178,7 @@ def test() -> None: N = NamedTuple('N', [('x', N)]) # E: Cannot resolve name "N" (possible cyclic definition) \ # N: Recursive types are not allowed at function scope n: N - reveal_type(n) # N: Revealed type is "Tuple[Any, fallback=__main__.N@4]" + reveal_type(n) # N: Revealed type is "tuple[Any, fallback=__main__.N@4]" [builtins fixtures/tuple.pyi] [case testCrashOnSelfRecursiveTypedDictVar] @@ -5231,7 +5231,7 @@ class NameInfo(NamedTuple): def parse_ast(name_dict: NameDict) -> None: if isinstance(name_dict[''], int): pass - reveal_type(name_dict['test']) # N: Revealed type is "Tuple[builtins.bool, fallback=__main__.NameInfo]" + reveal_type(name_dict['test']) # N: Revealed type is "tuple[builtins.bool, fallback=__main__.NameInfo]" [builtins fixtures/isinstancelist.pyi] [typing fixtures/typing-medium.pyi] @@ -5387,7 +5387,7 @@ class Bar(NamedTuple): def foo(node: Node) -> int: x = node - reveal_type(node) # N: Revealed type is "Union[Tuple[builtins.int, fallback=__main__.Foo], Tuple[builtins.int, fallback=__main__.Bar]]" + reveal_type(node) # N: Revealed type is "Union[tuple[builtins.int, fallback=__main__.Foo], tuple[builtins.int, fallback=__main__.Bar]]" return x.x [builtins fixtures/tuple.pyi] [out] @@ -5465,9 +5465,9 @@ ForwardUnion = Union['TP', int] class TP(NamedTuple('TP', [('x', int)])): pass def f(x: ForwardUnion) -> None: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, fallback=__main__.TP], builtins.int]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, fallback=__main__.TP], builtins.int]" if isinstance(x, TP): - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.TP]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, fallback=__main__.TP]" [builtins fixtures/isinstance.pyi] [out] @@ -5498,8 +5498,8 @@ y: NM y1 = NM(x=[]) reveal_type(x) # N: Revealed type is "TypedDict('__main__.TD', {'x': builtins.list[Any]})" reveal_type(x1) # N: Revealed type is "TypedDict('__main__.TD', {'x': builtins.list[Any]})" -reveal_type(y) # N: Revealed type is "Tuple[builtins.list[Any], fallback=__main__.NM]" -reveal_type(y1) # N: Revealed type is "Tuple[builtins.list[Any], fallback=__main__.NM]" +reveal_type(y) # N: Revealed type is "tuple[builtins.list[Any], fallback=__main__.NM]" +reveal_type(y1) # N: Revealed type is "tuple[builtins.list[Any], fallback=__main__.NM]" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] [out] @@ -5667,7 +5667,7 @@ class C1(six.with_metaclass(M), object): pass # E: Unsupported dynamic base cla class C2(C1, six.with_metaclass(M)): pass # E: Unsupported dynamic base class "six.with_metaclass" class C3(six.with_metaclass(A)): pass # E: Metaclasses not inheriting from "type" are not supported @six.add_metaclass(A) # E: Metaclasses not inheriting from "type" are not supported \ - # E: Argument 1 to "add_metaclass" has incompatible type "Type[A]"; expected "Type[type]" + # E: Argument 1 to "add_metaclass" has incompatible type "type[A]"; expected "type[type]" class D3(A): pass class C4(six.with_metaclass(M), metaclass=M): pass # E: Multiple metaclass definitions @@ -5886,7 +5886,7 @@ T = TypeVar('T') class C(Any): def bar(self: T) -> Type[T]: pass def foo(self) -> None: - reveal_type(self.bar()) # N: Revealed type is "Type[__main__.C]" + reveal_type(self.bar()) # N: Revealed type is "type[__main__.C]" reveal_type(self.bar().__name__) # N: Revealed type is "builtins.str" [builtins fixtures/type.pyi] [out] @@ -5904,7 +5904,7 @@ def decorate_forward_ref() -> Callable[[Type[A]], Type[A]]: @decorate(11) class A: pass -@decorate # E: Argument 1 to "decorate" has incompatible type "Type[A2]"; expected "int" +@decorate # E: Argument 1 to "decorate" has incompatible type "type[A2]"; expected "int" class A2: pass [case testClassDecoratorIncorrect] @@ -6076,7 +6076,7 @@ d: D reveal_type(d.normal) # N: Revealed type is "builtins.int" reveal_type(d.dynamic) # N: Revealed type is "__main__.Descr" reveal_type(D.other) # N: Revealed type is "builtins.int" -D.dynamic # E: "Type[D]" has no attribute "dynamic" +D.dynamic # E: "type[D]" has no attribute "dynamic" [out] [case testSelfDescriptorAssign] @@ -6463,7 +6463,7 @@ class Sub(a.Base): # N: Superclass: \ # N: int \ # N: Subclass: \ - # N: def x(*Any, **Any) -> Tuple[int, int] + # N: def x(*Any, **Any) -> tuple[int, int] [file a.py] import b @@ -6489,7 +6489,7 @@ class Sub(a.Base): # N: Superclass: \ # N: int \ # N: Subclass: \ - # N: def x(*Any, **Any) -> Tuple[int, int] + # N: def x(*Any, **Any) -> tuple[int, int] [file a.py] import b @@ -6570,7 +6570,7 @@ class A(b.B): @c.deco def meth(self) -> int: y = super().meth() - reveal_type(y) # N: Revealed type is "Tuple[builtins.int, builtins.int]" + reveal_type(y) # N: Revealed type is "tuple[builtins.int, builtins.int]" return 0 [file b.py] from a import A @@ -6629,7 +6629,7 @@ class A(b.B): @c.deco def meth(self) -> int: y = super().meth() - reveal_type(y) # N: Revealed type is "Tuple[builtins.int, builtins.int]" + reveal_type(y) # N: Revealed type is "tuple[builtins.int, builtins.int]" reveal_type(other.x) # N: Revealed type is "builtins.int" return 0 @@ -6878,7 +6878,7 @@ class C: ... x: Union[C, Type[C]] if isinstance(x, type) and issubclass(x, C): - reveal_type(x) # N: Revealed type is "Type[__main__.C]" + reveal_type(x) # N: Revealed type is "type[__main__.C]" [builtins fixtures/isinstancelist.pyi] [case testIsInstanceTypeByAssert] @@ -6902,11 +6902,11 @@ class C(Generic[T]): def meth(self, cls: Type[T]) -> None: if not issubclass(cls, Sub): return - reveal_type(cls) # N: Revealed type is "Type[__main__.Sub]" + reveal_type(cls) # N: Revealed type is "type[__main__.Sub]" def other(self, cls: Type[T]) -> None: if not issubclass(cls, Sub): return - reveal_type(cls) # N: Revealed type is "Type[__main__.Sub]" + reveal_type(cls) # N: Revealed type is "type[__main__.Sub]" [builtins fixtures/isinstancelist.pyi] @@ -6954,9 +6954,9 @@ class C(B): def __init__(self, a: int) -> None: self.c = a a = A(1) # E: Cannot instantiate abstract class "A" with abstract attribute "__init__" -A.c # E: "Type[A]" has no attribute "c" +A.c # E: "type[A]" has no attribute "c" b = B(2) # E: Cannot instantiate abstract class "B" with abstract attribute "__init__" -B.c # E: "Type[B]" has no attribute "c" +B.c # E: "type[B]" has no attribute "c" c = C(3) c.c C.c @@ -7159,7 +7159,7 @@ class A: N = NamedTuple('N', [('x', int)]) class B(A, N): pass -reveal_type(A()) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.B]" +reveal_type(A()) # N: Revealed type is "tuple[builtins.int, fallback=__main__.B]" [builtins fixtures/tuple.pyi] [case testNewReturnType8] @@ -7333,7 +7333,7 @@ class B(Generic[T]): class C(B[T]): def __init__(self) -> None: - self.x: List[T] # E: Incompatible types in assignment (expression has type "List[T]", base class "B" defined the type as "T") + self.x: List[T] # E: Incompatible types in assignment (expression has type "list[T]", base class "B" defined the type as "T") [builtins fixtures/list.pyi] [case testGenericOverrideGenericChained] @@ -7350,7 +7350,7 @@ class B(A[Tuple[T, S]]): ... class C(B[int, T]): def __init__(self) -> None: # TODO: error message could be better. - self.x: Tuple[str, T] # E: Incompatible types in assignment (expression has type "Tuple[str, T]", base class "A" defined the type as "Tuple[int, T]") + self.x: Tuple[str, T] # E: Incompatible types in assignment (expression has type "tuple[str, T]", base class "A" defined the type as "tuple[int, T]") [builtins fixtures/tuple.pyi] [case testInitSubclassWrongType] @@ -7489,7 +7489,7 @@ class C: def meth(cls): ... reveal_type(C.meth) # N: Revealed type is "def () -> Any" -reveal_type(C.__new__) # N: Revealed type is "def (cls: Type[__main__.C]) -> Any" +reveal_type(C.__new__) # N: Revealed type is "def (cls: type[__main__.C]) -> Any" [builtins fixtures/classmethod.pyi] [case testOverrideGenericSelfClassMethod] @@ -7532,7 +7532,7 @@ class Foo: @classmethod def bar(cls): - cls.baz() # E: "Type[Foo]" has no attribute "baz" + cls.baz() # E: "type[Foo]" has no attribute "baz" class C(Generic[T]): x: T @@ -7595,14 +7595,14 @@ TypeT1 = TypeVar("TypeT1", bound=Type[Base]) class C1: def method(self, other: type) -> int: if issubclass(other, Base): - reveal_type(other) # N: Revealed type is "Type[__main__.Base]" + reveal_type(other) # N: Revealed type is "type[__main__.Base]" return other.field return 0 class C2(Generic[TypeT]): def method(self, other: TypeT) -> int: if issubclass(other, Base): - reveal_type(other) # N: Revealed type is "Type[__main__.Base]" + reveal_type(other) # N: Revealed type is "type[__main__.Base]" return other.field return 0 @@ -7837,7 +7837,7 @@ class Foo: reveal_type(Foo.foo) # N: Revealed type is "builtins.int" reveal_type(Foo.bar) # N: Revealed type is "Any" -reveal_type(Foo.baz) # E: "Type[Foo]" has no attribute "baz" \ +reveal_type(Foo.baz) # E: "type[Foo]" has no attribute "baz" \ # N: Revealed type is "Any" [file mod.py] @@ -8070,9 +8070,9 @@ class C(Tuple[T, S]): def foo(self, arg: T) -> S: ... cis: C[int, str] -reveal_type(cis) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.C[builtins.int, builtins.str]]" +reveal_type(cis) # N: Revealed type is "tuple[builtins.int, builtins.str, fallback=__main__.C[builtins.int, builtins.str]]" cii = C(0, 1) -reveal_type(cii) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.C[builtins.int, builtins.int]]" +reveal_type(cii) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.C[builtins.int, builtins.int]]" reveal_type(cis.foo) # N: Revealed type is "def (arg: builtins.int) -> builtins.str" [builtins fixtures/tuple.pyi] @@ -8084,7 +8084,7 @@ class C(Tuple[T, T]): ... class D(C[List[T]]): ... di: D[int] -reveal_type(di) # N: Revealed type is "Tuple[builtins.list[builtins.int], builtins.list[builtins.int], fallback=__main__.D[builtins.int]]" +reveal_type(di) # N: Revealed type is "tuple[builtins.list[builtins.int], builtins.list[builtins.int], fallback=__main__.D[builtins.int]]" [builtins fixtures/tuple.pyi] [case testOverrideAttrWithSettableProperty] @@ -8473,7 +8473,7 @@ class C(B[List[T]]): ... a = C[str]() a.foo = ["foo", "bar"] reveal_type(a.foo) # N: Revealed type is "builtins.int" -a.foo = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "List[str]") +a.foo = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "list[str]") reveal_type(a.foo) # N: Revealed type is "builtins.int" [builtins fixtures/property.pyi] @@ -8566,7 +8566,7 @@ class C(B): c: C c.baz = "yes" # OK, because of untyped decorator -c.tricky = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "List[int]") +c.tricky = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "list[int]") T = TypeVar("T") def deco(fn: Callable[[T, int, int], None]) -> Callable[[T, int], None]: ... diff --git a/test-data/unit/check-columns.test b/test-data/unit/check-columns.test index 5d8f55ec598c..c822c7c44f41 100644 --- a/test-data/unit/check-columns.test +++ b/test-data/unit/check-columns.test @@ -47,13 +47,13 @@ aaa: str h(x=1, y=aaa, z=2) # E:10: Argument "y" to "h" has incompatible type "str"; expected "int" a: A ff(a.x) # E:4: Argument 1 to "ff" has incompatible type "str"; expected "int" -ff([1]) # E:4: Argument 1 to "ff" has incompatible type "List[int]"; expected "int" +ff([1]) # E:4: Argument 1 to "ff" has incompatible type "list[int]"; expected "int" # TODO: Different column in Python 3.8+ -#ff([1 for x in [1]]) # Argument 1 to "ff" has incompatible type "List[int]"; expected "int" -ff({1: 2}) # E:4: Argument 1 to "ff" has incompatible type "Dict[int, int]"; expected "int" +#ff([1 for x in [1]]) # Argument 1 to "ff" has incompatible type "list[int]"; expected "int" +ff({1: 2}) # E:4: Argument 1 to "ff" has incompatible type "dict[int, int]"; expected "int" ff(1.1) # E:4: Argument 1 to "ff" has incompatible type "float"; expected "int" # TODO: Different column in Python 3.8+ -#ff( ( 1, 1)) # Argument 1 to "ff" has incompatible type "Tuple[int, int]"; expected "int" +#ff( ( 1, 1)) # Argument 1 to "ff" has incompatible type "tuple[int, int]"; expected "int" ff(-a) # E:4: Argument 1 to "ff" has incompatible type "str"; expected "int" ff(a + 1) # E:4: Argument 1 to "ff" has incompatible type "str"; expected "int" ff(a < 1) # E:4: Argument 1 to "ff" has incompatible type "str"; expected "int" @@ -69,9 +69,9 @@ def f(*x: int) -> None: pass def g(**x: int) -> None: pass a = [''] -f(*a) # E:4: Argument 1 to "f" has incompatible type "*List[str]"; expected "int" +f(*a) # E:4: Argument 1 to "f" has incompatible type "*list[str]"; expected "int" b = {'x': 'y'} -g(**b) # E:5: Argument 1 to "g" has incompatible type "**Dict[str, str]"; expected "int" +g(**b) # E:5: Argument 1 to "g" has incompatible type "**dict[str, str]"; expected "int" [builtins fixtures/dict.pyi] [case testColumnsMultipleStatementsPerLine] @@ -183,7 +183,7 @@ if int(): [case testColumnNeedTypeAnnotation] if 1: - x = [] # E:5: Need type annotation for "x" (hint: "x: List[] = ...") + x = [] # E:5: Need type annotation for "x" (hint: "x: list[] = ...") [builtins fixtures/list.pyi] [case testColumnCallToUntypedFunction] @@ -216,7 +216,7 @@ x = None [case testColumnInvalidIndexing] from typing import List -([1]['']) # E:6: Invalid index type "str" for "List[int]"; expected type "int" +([1]['']) # E:6: Invalid index type "str" for "list[int]"; expected type "int" (1[1]) # E:2: Value of type "int" is not indexable def f() -> None: 1[1] = 1 # E:5: Unsupported target for indexed assignment ("int") @@ -264,7 +264,7 @@ class D(A): # flags: --disallow-any-generics from typing import List, Callable def f(x: List) -> None: pass # E:10: Missing type parameters for generic type "List" -def g(x: list) -> None: pass # E:10: Missing type parameters for generic type "List" +def g(x: list) -> None: pass # E:10: Missing type parameters for generic type "list" if int(): c: Callable # E:8: Missing type parameters for generic type "Callable" [builtins fixtures/list.pyi] diff --git a/test-data/unit/check-ctypes.test b/test-data/unit/check-ctypes.test index 1e58ebc77d0f..a0a5c44b2ba5 100644 --- a/test-data/unit/check-ctypes.test +++ b/test-data/unit/check-ctypes.test @@ -16,7 +16,7 @@ a[2] = MyCInt(42) a[3] = b"bytes" # E: No overload variant of "__setitem__" of "Array" matches argument types "int", "bytes" \ # N: Possible overload variants: \ # N: def __setitem__(self, int, Union[c_int, int], /) -> None \ - # N: def __setitem__(self, slice, List[Union[c_int, int]], /) -> None + # N: def __setitem__(self, slice, list[Union[c_int, int]], /) -> None for x in a: reveal_type(x) # N: Revealed type is "builtins.int" [builtins fixtures/floatdict.pyi] @@ -40,12 +40,12 @@ mya[0] = 42 mya[1] = ctypes.c_int(42) # E: No overload variant of "__setitem__" of "Array" matches argument types "int", "c_int" \ # N: Possible overload variants: \ # N: def __setitem__(self, int, Union[MyCInt, int], /) -> None \ - # N: def __setitem__(self, slice, List[Union[MyCInt, int]], /) -> None + # N: def __setitem__(self, slice, list[Union[MyCInt, int]], /) -> None mya[2] = MyCInt(42) mya[3] = b"bytes" # E: No overload variant of "__setitem__" of "Array" matches argument types "int", "bytes" \ # N: Possible overload variants: \ # N: def __setitem__(self, int, Union[MyCInt, int], /) -> None \ - # N: def __setitem__(self, slice, List[Union[MyCInt, int]], /) -> None + # N: def __setitem__(self, slice, list[Union[MyCInt, int]], /) -> None for myx in mya: reveal_type(myx) # N: Revealed type is "__main__.MyCInt" @@ -74,7 +74,7 @@ mya[2] = MyCInt(42) mya[3] = b"bytes" # E: No overload variant of "__setitem__" of "Array" matches argument types "int", "bytes" \ # N: Possible overload variants: \ # N: def __setitem__(self, int, Union[MyCInt, int, c_uint], /) -> None \ - # N: def __setitem__(self, slice, List[Union[MyCInt, int, c_uint]], /) -> None + # N: def __setitem__(self, slice, list[Union[MyCInt, int, c_uint]], /) -> None for myx in mya: reveal_type(myx) # N: Revealed type is "Union[__main__.MyCInt, builtins.int]" [builtins fixtures/floatdict.pyi] diff --git a/test-data/unit/check-custom-plugin.test b/test-data/unit/check-custom-plugin.test index 72b60c874656..0c157510cb34 100644 --- a/test-data/unit/check-custom-plugin.test +++ b/test-data/unit/check-custom-plugin.test @@ -752,7 +752,7 @@ plugins=/test-data/unit/plugins/common_api_incremental.py [out] [out2] tmp/a.py:3: note: Revealed type is "builtins.str" -tmp/a.py:4: error: "Type[Base]" has no attribute "__magic__" +tmp/a.py:4: error: "type[Base]" has no attribute "__magic__" [case testArgKindsMethod] # flags: --config-file tmp/mypy.ini diff --git a/test-data/unit/check-dataclass-transform.test b/test-data/unit/check-dataclass-transform.test index 8213f8df282a..7c534914aa2d 100644 --- a/test-data/unit/check-dataclass-transform.test +++ b/test-data/unit/check-dataclass-transform.test @@ -505,7 +505,7 @@ class FunctionModel: integer_: tuple FunctionModel(string_="abc", integer_=1) -FunctionModel(string_="abc", integer_=tuple()) # E: Argument "integer_" to "FunctionModel" has incompatible type "Tuple[Never, ...]"; expected "int" +FunctionModel(string_="abc", integer_=tuple()) # E: Argument "integer_" to "FunctionModel" has incompatible type "tuple[Never, ...]"; expected "int" [typing fixtures/typing-full.pyi] [builtins fixtures/dataclasses.pyi] @@ -528,7 +528,7 @@ class FunctionModel: integer_: int FunctionModel(string_="abc", integer_=1) -FunctionModel(string_="abc", integer_=tuple()) # E: Argument "integer_" to "FunctionModel" has incompatible type "Tuple[Never, ...]"; expected "int" +FunctionModel(string_="abc", integer_=tuple()) # E: Argument "integer_" to "FunctionModel" has incompatible type "tuple[Never, ...]"; expected "int" [typing fixtures/typing-full.pyi] [builtins fixtures/dataclasses.pyi] @@ -551,7 +551,7 @@ class BaseClassModel(ModelBase): integer_: tuple BaseClassModel(string_="abc", integer_=1) -BaseClassModel(string_="abc", integer_=tuple()) # E: Argument "integer_" to "BaseClassModel" has incompatible type "Tuple[Never, ...]"; expected "int" +BaseClassModel(string_="abc", integer_=tuple()) # E: Argument "integer_" to "BaseClassModel" has incompatible type "tuple[Never, ...]"; expected "int" [typing fixtures/typing-full.pyi] [builtins fixtures/dataclasses.pyi] @@ -573,7 +573,7 @@ class BaseClassModel(ModelBase): integer_: int BaseClassModel(string_="abc", integer_=1) -BaseClassModel(string_="abc", integer_=tuple()) # E: Argument "integer_" to "BaseClassModel" has incompatible type "Tuple[Never, ...]"; expected "int" +BaseClassModel(string_="abc", integer_=tuple()) # E: Argument "integer_" to "BaseClassModel" has incompatible type "tuple[Never, ...]"; expected "int" [typing fixtures/typing-full.pyi] [builtins fixtures/dataclasses.pyi] @@ -598,7 +598,7 @@ class MetaClassModel(ModelBaseWithMeta): integer_: tuple MetaClassModel(string_="abc", integer_=1) -MetaClassModel(string_="abc", integer_=tuple()) # E: Argument "integer_" to "MetaClassModel" has incompatible type "Tuple[Never, ...]"; expected "int" +MetaClassModel(string_="abc", integer_=tuple()) # E: Argument "integer_" to "MetaClassModel" has incompatible type "tuple[Never, ...]"; expected "int" [typing fixtures/typing-full.pyi] [builtins fixtures/dataclasses.pyi] @@ -623,7 +623,7 @@ class MetaClassModel(ModelBaseWithMeta): integer_: int MetaClassModel(string_="abc", integer_=1) -MetaClassModel(string_="abc", integer_=tuple()) # E: Argument "integer_" to "MetaClassModel" has incompatible type "Tuple[Never, ...]"; expected "int" +MetaClassModel(string_="abc", integer_=tuple()) # E: Argument "integer_" to "MetaClassModel" has incompatible type "tuple[Never, ...]"; expected "int" [typing fixtures/typing-full.pyi] [builtins fixtures/dataclasses.pyi] diff --git a/test-data/unit/check-dataclasses.test b/test-data/unit/check-dataclasses.test index a3f46292e712..8117e3a96938 100644 --- a/test-data/unit/check-dataclasses.test +++ b/test-data/unit/check-dataclasses.test @@ -549,7 +549,7 @@ class A: @classmethod def foo(cls, x: Union[int, str]) -> Union[int, str]: - reveal_type(cls) # N: Revealed type is "Type[__main__.A]" + reveal_type(cls) # N: Revealed type is "type[__main__.A]" reveal_type(cls.other()) # N: Revealed type is "builtins.str" return x @@ -700,7 +700,7 @@ class A(Generic[T]): return self.z[0] def problem(self) -> T: - return self.z # E: Incompatible return value type (got "List[T]", expected "T") + return self.z # E: Incompatible return value type (got "list[T]", expected "T") reveal_type(A) # N: Revealed type is "def [T] (x: T`1, y: T`1, z: builtins.list[T`1]) -> __main__.A[T`1]" A(1, 2, ["a", "b"]) # E: Cannot infer type argument 1 of "A" @@ -836,7 +836,7 @@ class A(Generic[T]): @classmethod def foo(cls) -> None: - reveal_type(cls) # N: Revealed type is "Type[__main__.A[T`1]]" + reveal_type(cls) # N: Revealed type is "type[__main__.A[T`1]]" cls.x # E: Access to generic instance variables via class is ambiguous @classmethod @@ -936,7 +936,7 @@ T = TypeVar('T', bound='A') class A: @classmethod def make(cls: Type[T]) -> T: - reveal_type(cls) # N: Revealed type is "Type[T`-1]" + reveal_type(cls) # N: Revealed type is "type[T`-1]" reveal_type(cls()) # N: Revealed type is "T`-1" return cls() [builtins fixtures/dataclasses.pyi] @@ -1386,7 +1386,7 @@ class Foo: bar: float = field(**{"repr": False}) [out] 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: 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 @@ -1520,14 +1520,14 @@ class Some: y: str z: bool -reveal_type(Some.__slots__) # N: Revealed type is "Tuple[builtins.str, builtins.str, builtins.str]" +reveal_type(Some.__slots__) # N: Revealed type is "tuple[builtins.str, builtins.str, builtins.str]" @dataclass(slots=True) class Other: x: int y: str -reveal_type(Other.__slots__) # N: Revealed type is "Tuple[builtins.str, builtins.str]" +reveal_type(Other.__slots__) # N: Revealed type is "tuple[builtins.str, builtins.str]" @dataclass @@ -1535,7 +1535,7 @@ class NoSlots: x: int y: str -NoSlots.__slots__ # E: "Type[NoSlots]" has no attribute "__slots__" +NoSlots.__slots__ # E: "type[NoSlots]" has no attribute "__slots__" [builtins fixtures/dataclasses.pyi] @@ -1834,17 +1834,17 @@ class One: bar: int baz: str o: One -reveal_type(o.__match_args__) # N: Revealed type is "Tuple[Literal['bar'], Literal['baz']]" +reveal_type(o.__match_args__) # N: Revealed type is "tuple[Literal['bar'], Literal['baz']]" @dataclass(match_args=True) class Two: bar: int t: Two -reveal_type(t.__match_args__) # N: Revealed type is "Tuple[Literal['bar']]" +reveal_type(t.__match_args__) # N: Revealed type is "tuple[Literal['bar']]" @dataclass class Empty: ... e: Empty -reveal_type(e.__match_args__) # N: Revealed type is "Tuple[()]" +reveal_type(e.__match_args__) # N: Revealed type is "tuple[()]" [builtins fixtures/dataclasses.pyi] [case testDataclassWithMatchArgsAndKwOnly] @@ -1854,13 +1854,13 @@ from dataclasses import dataclass, field class One: a: int b: str -reveal_type(One.__match_args__) # N: Revealed type is "Tuple[()]" +reveal_type(One.__match_args__) # N: Revealed type is "tuple[()]" @dataclass(kw_only=True) class Two: a: int = field(kw_only=False) b: str -reveal_type(Two.__match_args__) # N: Revealed type is "Tuple[Literal['a']]" +reveal_type(Two.__match_args__) # N: Revealed type is "tuple[Literal['a']]" [builtins fixtures/dataclasses.pyi] [case testDataclassWithoutMatchArgs] @@ -2097,7 +2097,7 @@ a_or_b: Union[A[int], B] _ = replace(a_or_b, x=42, y=True, init_var=42) _ = replace(a_or_b, x=42, y=True) # E: Missing named argument "init_var" for "replace" of "Union[A[int], B]" _ = replace(a_or_b, x=42, y=True, z='42', init_var=42) # E: Argument "z" to "replace" of "Union[A[int], B]" has incompatible type "str"; expected "Never" -_ = replace(a_or_b, x=42, y=True, w={}, init_var=42) # E: Argument "w" to "replace" of "Union[A[int], B]" has incompatible type "Dict[Never, Never]"; expected "Never" +_ = replace(a_or_b, x=42, y=True, w={}, init_var=42) # E: Argument "w" to "replace" of "Union[A[int], B]" has incompatible type "dict[Never, Never]"; expected "Never" _ = replace(a_or_b, y=42, init_var=42) # E: Argument "y" to "replace" of "Union[A[int], B]" has incompatible type "int"; expected "bool" [builtins fixtures/tuple.pyi] @@ -2202,7 +2202,7 @@ from dataclasses import is_dataclass, replace def f(x: object) -> None: _ = replace(x) # E: Value of type variable "_DataclassT" of "replace" cannot be "object" if is_dataclass(x): - _ = replace(x) # E: Value of type variable "_DataclassT" of "replace" cannot be "Union[DataclassInstance, Type[DataclassInstance]]" + _ = replace(x) # E: Value of type variable "_DataclassT" of "replace" cannot be "Union[DataclassInstance, type[DataclassInstance]]" if not isinstance(x, type): _ = replace(x) @@ -2423,7 +2423,7 @@ main:7: note: Superclass: main:7: note: def __post_init__(self: Test, y: str) -> None main:7: note: Subclass: main:7: note: @classmethod -main:7: note: def __post_init__(cls: Type[Test]) -> None +main:7: note: def __post_init__(cls: type[Test]) -> None [case testPostInitStaticMethod] from dataclasses import dataclass, InitVar diff --git a/test-data/unit/check-deprecated.test b/test-data/unit/check-deprecated.test index 6cc160fad81f..e1173ac425ba 100644 --- a/test-data/unit/check-deprecated.test +++ b/test-data/unit/check-deprecated.test @@ -113,7 +113,7 @@ class C: ... c: C # E: class __main__.C is deprecated: use C2 instead C() # E: class __main__.C is deprecated: use C2 instead C.missing() # E: class __main__.C is deprecated: use C2 instead \ - # E: "Type[C]" has no attribute "missing" + # E: "type[C]" has no attribute "missing" C.__init__(c) # E: class __main__.C is deprecated: use C2 instead C(1) # E: class __main__.C is deprecated: use C2 instead \ # E: Too many arguments for "C" diff --git a/test-data/unit/check-dynamic-typing.test b/test-data/unit/check-dynamic-typing.test index ffab5afeda3e..166073dd1553 100644 --- a/test-data/unit/check-dynamic-typing.test +++ b/test-data/unit/check-dynamic-typing.test @@ -279,7 +279,7 @@ t2: Tuple[A, A] d: Any if int(): - t2 = (d, d, d) # E: Incompatible types in assignment (expression has type "Tuple[Any, Any, Any]", variable has type "Tuple[A, A]") + t2 = (d, d, d) # E: Incompatible types in assignment (expression has type "tuple[Any, Any, Any]", variable has type "tuple[A, A]") if int(): t2 = (d, d) @@ -571,7 +571,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 "Callable[[A], A]") A(a, a) if int(): @@ -599,8 +599,8 @@ t5: Tuple[Any, Any, Any] def f(): t1, t2, t3, t4, t5 # Prevent redefinition -t3 = t5 # E: Incompatible types in assignment (expression has type "Tuple[Any, Any, Any]", variable has type "Tuple[Any, Any]") -t5 = t4 # E: Incompatible types in assignment (expression has type "Tuple[A, A]", variable has type "Tuple[Any, Any, Any]") +t3 = t5 # E: Incompatible types in assignment (expression has type "tuple[Any, Any, Any]", variable has type "tuple[Any, Any]") +t5 = t4 # E: Incompatible types in assignment (expression has type "tuple[A, A]", variable has type "tuple[Any, Any, Any]") t1 = t1 t1 = t2 diff --git a/test-data/unit/check-enum.test b/test-data/unit/check-enum.test index cc9048db18dc..1a07e4527527 100644 --- a/test-data/unit/check-enum.test +++ b/test-data/unit/check-enum.test @@ -601,10 +601,10 @@ T = Enum('T', keyword='a b') # E: Unexpected keyword argument "keyword" U = Enum('U', *['a']) # E: Unexpected arguments to Enum() V = Enum('U', **{'a': 1}) # E: Unexpected arguments to Enum() W = Enum('W', 'a b') -W.c # E: "Type[W]" has no attribute "c" +W.c # E: "type[W]" has no attribute "c" X = Enum('Something', 'a b') # E: String argument 1 "Something" to enum.Enum(...) does not match variable name "X" reveal_type(X.a) # N: Revealed type is "Literal[__main__.Something@23.a]?" -X.asdf # E: "Type[Something@23]" has no attribute "asdf" +X.asdf # E: "type[Something@23]" has no attribute "asdf" [builtins fixtures/tuple.pyi] [typing fixtures/typing-medium.pyi] @@ -931,7 +931,7 @@ class Foo(Enum): A = 1 B = 2 -Foo._order_ # E: "Type[Foo]" has no attribute "_order_" +Foo._order_ # E: "type[Foo]" has no attribute "_order_" x: Literal[Foo.A, Foo.B] if x is Foo.A: @@ -946,7 +946,7 @@ class Bar(Enum): A = 1 B = 2 -Bar.__order__ # E: "Type[Bar]" has no attribute "__order__" +Bar.__order__ # E: "type[Bar]" has no attribute "__order__" y: Literal[Bar.A, Bar.B] if y is Bar.A: @@ -2024,7 +2024,7 @@ class A(Enum): reveal_type(A.str.value) # N: Revealed type is "Literal['foo']?" reveal_type(A.int.value) # N: Revealed type is "Literal[1]?" reveal_type(A.bool.value) # N: Revealed type is "Literal[False]?" -reveal_type(A.tuple.value) # N: Revealed type is "Tuple[Literal[1]?]" +reveal_type(A.tuple.value) # N: Revealed type is "tuple[Literal[1]?]" [builtins fixtures/tuple.pyi] [case testFinalWithPrivateAssignment] @@ -2244,7 +2244,7 @@ from enum import Enum class C(Enum): _ignore_ = 'X' -C._ignore_ # E: "Type[C]" has no attribute "_ignore_" +C._ignore_ # E: "type[C]" has no attribute "_ignore_" [builtins fixtures/enum.pyi] [case testCanOverrideDunderAttributes] @@ -2302,7 +2302,7 @@ class A(Some, Enum): from enum import Enum class Mixed(Enum): - a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") b = None def check(self) -> None: @@ -2319,8 +2319,8 @@ class Mixed(Enum): pass class AllPartialList(Enum): - a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") - b = [] # E: Need type annotation for "b" (hint: "b: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") + b = [] # E: Need type annotation for "b" (hint: "b: list[] = ...") def check(self) -> None: reveal_type(self.value) # N: Revealed type is "builtins.list[Any]" @@ -2335,7 +2335,7 @@ class MyEnum(Enum): __my_dict = {A: "ham", B: "spam"} # TODO: change the next line to use MyEnum._MyEnum__my_dict when mypy implements name mangling -x: MyEnum = MyEnum.__my_dict # E: Incompatible types in assignment (expression has type "Dict[int, str]", variable has type "MyEnum") +x: MyEnum = MyEnum.__my_dict # E: Incompatible types in assignment (expression has type "dict[int, str]", variable has type "MyEnum") [builtins fixtures/enum.pyi] [case testEnumWithPrivateAttributeReachability] diff --git a/test-data/unit/check-errorcodes.test b/test-data/unit/check-errorcodes.test index c07a161823da..d6e3366401dd 100644 --- a/test-data/unit/check-errorcodes.test +++ b/test-data/unit/check-errorcodes.test @@ -272,7 +272,7 @@ from typing import TypeVar T = TypeVar('T') def f() -> T: pass # E: A function returning TypeVar should receive at least one argument containing the same TypeVar [type-var] x = f() # E: Need type annotation for "x" [var-annotated] -y = [] # E: Need type annotation for "y" (hint: "y: List[] = ...") [var-annotated] +y = [] # E: Need type annotation for "y" (hint: "y: list[] = ...") [var-annotated] [builtins fixtures/list.pyi] [case testErrorCodeBadOverride] @@ -344,7 +344,7 @@ a.x = '' # E: Incompatible types in assignment (expression has type "str", vari # flags: --disallow-any-generics from typing import List, TypeVar x: List # E: Missing type parameters for generic type "List" [type-arg] -y: list # E: Missing type parameters for generic type "List" [type-arg] +y: list # E: Missing type parameters for generic type "list" [type-arg] T = TypeVar('T') L = List[List[T]] z: L # E: Missing type parameters for generic type "L" [type-arg] @@ -397,7 +397,7 @@ def g(): [case testErrorCodeIndexing] from typing import Dict x: Dict[int, int] -x[''] # E: Invalid index type "str" for "Dict[int, int]"; expected type "int" [index] +x[''] # E: Invalid index type "str" for "dict[int, int]"; expected type "int" [index] 1[''] # E: Value of type "int" is not indexable [index] 1[''] = 1 # E: Unsupported target for indexed assignment ("int") [index] [builtins fixtures/dict.pyi] @@ -1071,12 +1071,12 @@ class C(abc.ABC): T = TypeVar("T") def test(tp: Type[T]) -> T: ... -test(C) # E: Only concrete class can be given where "Type[C]" is expected [type-abstract] +test(C) # E: Only concrete class can be given where "type[C]" is expected [type-abstract] class D(C): @abc.abstractmethod def bar(self) -> None: ... -cls: Type[C] = D # E: Can only assign concrete classes to a variable of type "Type[C]" [type-abstract] +cls: Type[C] = D # E: Can only assign concrete classes to a variable of type "type[C]" [type-abstract] [case testUncheckedAnnotationCodeShown] def f(): diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index a3b15a3b1da4..a0302fcd1943 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -750,17 +750,17 @@ i = 8 f = 8.0 d = Decimal(8) -reveal_type(divmod(i, i)) # N: Revealed type is "Tuple[builtins.int, builtins.int]" -reveal_type(divmod(f, i)) # N: Revealed type is "Tuple[builtins.float, builtins.float]" -reveal_type(divmod(d, i)) # N: Revealed type is "Tuple[__main__.Decimal, __main__.Decimal]" +reveal_type(divmod(i, i)) # N: Revealed type is "tuple[builtins.int, builtins.int]" +reveal_type(divmod(f, i)) # N: Revealed type is "tuple[builtins.float, builtins.float]" +reveal_type(divmod(d, i)) # N: Revealed type is "tuple[__main__.Decimal, __main__.Decimal]" -reveal_type(divmod(i, f)) # N: Revealed type is "Tuple[builtins.float, builtins.float]" -reveal_type(divmod(f, f)) # N: Revealed type is "Tuple[builtins.float, builtins.float]" +reveal_type(divmod(i, f)) # N: Revealed type is "tuple[builtins.float, builtins.float]" +reveal_type(divmod(f, f)) # N: Revealed type is "tuple[builtins.float, builtins.float]" divmod(d, f) # E: Unsupported operand types for divmod ("Decimal" and "float") -reveal_type(divmod(i, d)) # N: Revealed type is "Tuple[__main__.Decimal, __main__.Decimal]" +reveal_type(divmod(i, d)) # N: Revealed type is "tuple[__main__.Decimal, __main__.Decimal]" divmod(f, d) # E: Unsupported operand types for divmod ("float" and "Decimal") -reveal_type(divmod(d, d)) # N: Revealed type is "Tuple[__main__.Decimal, __main__.Decimal]" +reveal_type(divmod(d, d)) # N: Revealed type is "tuple[__main__.Decimal, __main__.Decimal]" # Now some bad calls divmod() # E: "divmod" expects 2 arguments \ @@ -1378,7 +1378,7 @@ class B: pass [out] main:5: error: Key expression in dictionary comprehension has incompatible type "A"; expected type "B" main:5: error: Value expression in dictionary comprehension has incompatible type "B"; expected type "A" -main:6: error: Incompatible types in assignment (expression has type "Dict[A, B]", variable has type "A") +main:6: error: Incompatible types in assignment (expression has type "dict[A, B]", variable has type "A") [case testDictionaryComprehensionWithNonDirectMapping] @@ -1661,13 +1661,13 @@ d1 = dict(a=1, b=2) # type: Dict[str, int] d2 = dict(a=1, b='') # type: Dict[str, int] # E: Dict entry 1 has incompatible type "str": "str"; expected "str": "int" d3 = dict(a=1) # type: Dict[int, int] # E: Dict entry 0 has incompatible type "str": "int"; expected "int": "int" d4 = dict(a=1, b=1) -d4.xyz # E: "Dict[str, int]" has no attribute "xyz" +d4.xyz # E: "dict[str, int]" has no attribute "xyz" d5 = dict(a=1, b='') # type: Dict[str, Any] [builtins fixtures/dict.pyi] [case testDictWithoutKeywordArgs] from typing import Dict -d = dict() # E: Need type annotation for "d" (hint: "d: Dict[, ] = ...") +d = dict() # E: Need type annotation for "d" (hint: "d: dict[, ] = ...") d2 = dict() # type: Dict[int, str] dict(undefined) # E: Name "undefined" is not defined [builtins fixtures/dict.pyi] @@ -1675,8 +1675,8 @@ dict(undefined) # E: Name "undefined" is not defined [case testDictFromList] from typing import Dict d = dict([(1, 'x'), (2, 'y')]) -d() # E: "Dict[int, str]" not callable -d2 = dict([(1, 'x')]) # type: Dict[str, str] # E: List item 0 has incompatible type "Tuple[int, str]"; expected "Tuple[str, str]" +d() # E: "dict[int, str]" not callable +d2 = dict([(1, 'x')]) # type: Dict[str, str] # E: List item 0 has incompatible type "tuple[int, str]"; expected "tuple[str, str]" [builtins fixtures/dict.pyi] [case testDictFromIterableAndKeywordArg] @@ -1684,10 +1684,10 @@ from typing import Dict it = [('x', 1)] d = dict(it, x=1) -d() # E: "Dict[str, int]" not callable +d() # E: "dict[str, int]" not callable d2 = dict(it, x='') -d2() # E: "Dict[str, object]" not callable +d2() # E: "dict[str, object]" not callable d3 = dict(it, x='') # type: Dict[str, int] # E: Argument "x" to "dict" has incompatible type "str"; expected "int" [builtins fixtures/dict.pyi] @@ -1699,7 +1699,7 @@ dict(it, x='y') # E: Keyword argument only valid with "str" key type in call to [case testDictFromIterableAndKeywordArg3] d = dict([], x=1) -d() # E: "Dict[str, int]" not callable +d() # E: "dict[str, int]" not callable [builtins fixtures/dict.pyi] [case testDictFromIterableAndStarStarArgs] @@ -1708,20 +1708,20 @@ it = [('x', 1)] kw = {'x': 1} d = dict(it, **kw) -d() # E: "Dict[str, int]" not callable +d() # E: "dict[str, int]" not callable kw2 = {'x': ''} d2 = dict(it, **kw2) -d2() # E: "Dict[str, object]" not callable +d2() # E: "dict[str, object]" not callable -d3 = dict(it, **kw2) # type: Dict[str, int] # E: Argument 2 to "dict" has incompatible type "**Dict[str, str]"; expected "int" +d3 = dict(it, **kw2) # type: Dict[str, int] # E: Argument 2 to "dict" has incompatible type "**dict[str, str]"; expected "int" [builtins fixtures/dict.pyi] [case testDictFromIterableAndStarStarArgs2] it = [(1, 'x')] kw = {'x': 'y'} d = dict(it, **kw) # E: Keyword argument only valid with "str" key type in call to "dict" -d() # E: "Dict[int, str]" not callable +d() # E: "dict[int, str]" not callable [builtins fixtures/dict.pyi] [case testUserDefinedClassNamedDict] @@ -1880,7 +1880,7 @@ c = {**b} d = {**a, **b, 'c': 3} e = {1: 'a', **a} # E: Cannot infer type argument 1 of \ # N: Try assigning the literal to a variable annotated as dict[, ] -f = {**b} # type: Dict[int, int] # E: Unpacked dict entry 0 has incompatible type "Dict[str, int]"; expected "SupportsKeysAndGetItem[int, int]" +f = {**b} # type: Dict[int, int] # E: Unpacked dict entry 0 has incompatible type "dict[str, int]"; expected "SupportsKeysAndGetItem[int, int]" g = {**Thing()} h = {**a, **Thing()} i = {**Thing()} # type: Dict[int, int] # E: Unpacked dict entry 0 has incompatible type "Thing"; expected "SupportsKeysAndGetItem[int, int]" \ @@ -1938,8 +1938,8 @@ class B: ... [builtins fixtures/dict.pyi] [case testTypeAnnotationNeededMultipleAssignment] -x, y = [], [] # E: Need type annotation for "x" (hint: "x: List[] = ...") \ - # E: Need type annotation for "y" (hint: "y: List[] = ...") +x, y = [], [] # E: Need type annotation for "x" (hint: "x: list[] = ...") \ + # E: Need type annotation for "y" (hint: "y: list[] = ...") [builtins fixtures/list.pyi] [case testStrictEqualityEq] @@ -2169,7 +2169,7 @@ class CustomMeta(type): class Normal: ... class Custom(metaclass=CustomMeta): ... -Normal == int() # E: Non-overlapping equality check (left operand type: "Type[Normal]", right operand type: "int") +Normal == int() # E: Non-overlapping equality check (left operand type: "type[Normal]", right operand type: "int") Normal == Normal Custom == int() [builtins fixtures/bool.pyi] @@ -2194,7 +2194,7 @@ class Bad: ... subclasses: List[Type[C]] object in subclasses D in subclasses -Bad in subclasses # E: Non-overlapping container check (element type: "Type[Bad]", container item type: "Type[C]") +Bad in subclasses # E: Non-overlapping container check (element type: "type[Bad]", container item type: "type[C]") [builtins fixtures/list.pyi] [typing fixtures/typing-full.pyi] @@ -2216,7 +2216,7 @@ exp: List[Meta] A in exp B in exp -C in exp # E: Non-overlapping container check (element type: "Type[C]", container item type: "Meta") +C in exp # E: Non-overlapping container check (element type: "type[C]", container item type: "Meta") o in exp a in exp @@ -2391,7 +2391,7 @@ assert a == b R2 = Dict[int, R2] c: R2 -assert a == c # E: Non-overlapping equality check (left operand type: "Dict[str, R]", right operand type: "Dict[int, R2]") +assert a == c # E: Non-overlapping equality check (left operand type: "dict[str, R]", right operand type: "dict[int, R2]") [builtins fixtures/dict.pyi] [typing fixtures/typing-full.pyi] diff --git a/test-data/unit/check-final.test b/test-data/unit/check-final.test index d78c2a8e57f2..d23199dc8b33 100644 --- a/test-data/unit/check-final.test +++ b/test-data/unit/check-final.test @@ -41,7 +41,7 @@ class C: def __init__(self, x: Tuple[int, Any]) -> None: self.x: Final = x self.y: Final[float] = 1 -reveal_type(C((1, 2)).x) # N: Revealed type is "Tuple[builtins.int, Any]" +reveal_type(C((1, 2)).x) # N: Revealed type is "tuple[builtins.int, Any]" reveal_type(C((1, 2)).y) # N: Revealed type is "builtins.float" [builtins fixtures/tuple.pyi] [out] @@ -251,7 +251,7 @@ class C(Generic[T]): self.x: Final = x self.y: Final = 1 -reveal_type(C((1, 2)).x) # N: Revealed type is "Tuple[builtins.int, builtins.int]" +reveal_type(C((1, 2)).x) # N: Revealed type is "tuple[builtins.int, builtins.int]" C.x # E: Cannot access final instance attribute "x" on class object \ # E: Access to generic instance variables via class is ambiguous C.y # E: Cannot access final instance attribute "y" on class object diff --git a/test-data/unit/check-flags.test b/test-data/unit/check-flags.test index ae126fb5e603..bb64bb44d282 100644 --- a/test-data/unit/check-flags.test +++ b/test-data/unit/check-flags.test @@ -979,9 +979,9 @@ def foo(l: List[Unchecked]) -> List[Unchecked]: return l [builtins fixtures/list.pyi] [out] -main:5: error: Return type becomes "List[Any]" due to an unfollowed import -main:5: error: Argument 1 to "foo" becomes "List[Any]" due to an unfollowed import -main:6: error: Type of variable becomes "List[Any]" due to an unfollowed import +main:5: error: Return type becomes "list[Any]" due to an unfollowed import +main:5: error: Argument 1 to "foo" becomes "list[Any]" due to an unfollowed import +main:6: error: Type of variable becomes "list[Any]" due to an unfollowed import [case testDisallowImplicitAnyInherit] # flags: --ignore-missing-imports --disallow-any-unimported @@ -991,7 +991,7 @@ from typing import List class C(Unchecked): # E: Base type Unchecked becomes "Any" due to an unfollowed import pass -class A(List[Unchecked]): # E: Base type becomes "List[Any]" due to an unfollowed import +class A(List[Unchecked]): # E: Base type becomes "list[Any]" due to an unfollowed import pass [builtins fixtures/list.pyi] @@ -1000,7 +1000,7 @@ class A(List[Unchecked]): # E: Base type becomes "List[Any]" due to an unfollowe from missing import Unchecked from typing import List -X = List[Unchecked] # E: Type alias target becomes "List[Any]" due to an unfollowed import +X = List[Unchecked] # E: Type alias target becomes "list[Any]" due to an unfollowed import def f(x: X) -> None: pass @@ -1013,7 +1013,7 @@ from typing import List, cast foo = [1, 2, 3] -cast(List[Unchecked], foo) # E: Target type of cast becomes "List[Any]" due to an unfollowed import +cast(List[Unchecked], foo) # E: Target type of cast becomes "list[Any]" due to an unfollowed import cast(Unchecked, foo) # E: Target type of cast becomes "Any" due to an unfollowed import [builtins fixtures/list.pyi] @@ -1026,7 +1026,7 @@ Point = NamedTuple('Point', [('x', List[Unchecked]), ('y', Unchecked)]) [builtins fixtures/list.pyi] [out] -main:5: error: NamedTuple type becomes "Tuple[List[Any], Any]" due to an unfollowed import +main:5: error: NamedTuple type becomes "tuple[list[Any], Any]" due to an unfollowed import [case testDisallowImplicitAnyTypeVarConstraints] # flags: --ignore-missing-imports --disallow-any-unimported @@ -1037,7 +1037,7 @@ T = TypeVar('T', Unchecked, List[Unchecked], str) [builtins fixtures/list.pyi] [out] main:5: error: Constraint 1 becomes "Any" due to an unfollowed import -main:5: error: Constraint 2 becomes "List[Any]" due to an unfollowed import +main:5: error: Constraint 2 becomes "list[Any]" due to an unfollowed import [case testDisallowImplicitAnyNewType] # flags: --ignore-missing-imports --disallow-any-unimported @@ -1045,7 +1045,7 @@ from typing import NewType, List from missing import Unchecked Baz = NewType('Baz', Unchecked) # E: Argument 2 to NewType(...) must be subclassable (got "Any") -Bar = NewType('Bar', List[Unchecked]) # E: Argument 2 to NewType(...) becomes "List[Any]" due to an unfollowed import +Bar = NewType('Bar', List[Unchecked]) # E: Argument 2 to NewType(...) becomes "list[Any]" due to an unfollowed import [builtins fixtures/list.pyi] @@ -1058,7 +1058,7 @@ def foo(f: Callable[[], Unchecked]) -> Tuple[Unchecked]: return f() [builtins fixtures/list.pyi] [out] -main:5: error: Return type becomes "Tuple[Any]" due to an unfollowed import +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 [case testDisallowImplicitAnySubclassingExplicitAny] @@ -1096,7 +1096,7 @@ def f(m: M) -> M: pass # no error from typing import List, TypedDict from x import Unchecked -M = TypedDict('M', {'x': str, 'y': List[Unchecked]}) # E: Type of a TypedDict key becomes "List[Any]" due to an unfollowed import +M = TypedDict('M', {'x': str, 'y': List[Unchecked]}) # E: Type of a TypedDict key becomes "list[Any]" due to an unfollowed import def f(m: M) -> M: pass # no error [builtins fixtures/dict.pyi] @@ -1170,10 +1170,10 @@ def d3(f) -> Callable[[Any], List[str]]: pass def f(i: int, s: str) -> None: # E: Type of decorated function contains type "Any" ("Callable[[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" ("Callable[[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" ("Callable[[Any], list[str]]") pass [builtins fixtures/list.pyi] @@ -1260,9 +1260,9 @@ def g(s: List[Any]) -> None: f(0) -# type of list below is inferred with expected type of "List[Any]", so that becomes it's type -# instead of List[str] -g(['']) # E: Expression type contains "Any" (has type "List[Any]") +# type of list below is inferred with expected type of "list[Any]", so that becomes it's type +# instead of list[str] +g(['']) # E: Expression type contains "Any" (has type "list[Any]") [builtins fixtures/list.pyi] [case testDisallowAnyExprAllowsAnyInCast] @@ -1293,8 +1293,8 @@ n = Foo().g # type: Any # E: Expression has type "Any" from typing import List l: List = [] -l.append(1) # E: Expression type contains "Any" (has type "List[Any]") -k = l[0] # E: Expression type contains "Any" (has type "List[Any]") # E: Expression has type "Any" +l.append(1) # E: Expression type contains "Any" (has type "list[Any]") +k = l[0] # E: Expression type contains "Any" (has type "list[Any]") # E: Expression has type "Any" [builtins fixtures/list.pyi] [case testDisallowAnyExprTypeVar] @@ -1531,19 +1531,19 @@ def f(t: tuple) -> None: pass # E: Missing type parameters for generic type "tu [case testDisallowAnyGenericsBuiltinList] # flags: --disallow-any-generics l = list([1, 2, 3]) -def f(t: list) -> None: pass # E: Missing type parameters for generic type "List" +def f(t: list) -> None: pass # E: Missing type parameters for generic type "list" [builtins fixtures/list.pyi] [case testDisallowAnyGenericsBuiltinSet] # flags: --disallow-any-generics l = set({1, 2, 3}) -def f(s: set) -> None: pass # E: Missing type parameters for generic type "Set" +def f(s: set) -> None: pass # E: Missing type parameters for generic type "set" [builtins fixtures/set.pyi] [case testDisallowAnyGenericsBuiltinDict] # flags: --disallow-any-generics l = dict([('a', 1)]) -def f(d: dict) -> None: pass # E: Missing type parameters for generic type "Dict" +def f(d: dict) -> None: pass # E: Missing type parameters for generic type "dict" [builtins fixtures/dict.pyi] [case testCheckDefaultAllowAnyGeneric] @@ -2012,7 +2012,7 @@ def h(l: List[List]) -> None: pass # E: Missing type parameters for generic ty def i(l: List[List[List[List]]]) -> None: pass # E: Missing type parameters for generic type "List" def j() -> List: pass # E: Missing type parameters for generic type "List" -x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") +x = [] # E: Need type annotation for "x" (hint: "x: list[] = ...") y: List = [] # E: Missing type parameters for generic type "List" [builtins fixtures/list.pyi] @@ -2270,7 +2270,7 @@ untyped_calls_exclude = foo, bar.A import tests.foo import bar [file bar.py] -x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") +x = [] # E: Need type annotation for "x" (hint: "x: list[] = ...") [file tests/__init__.py] [file tests/foo.py] x = [] # OK @@ -2450,13 +2450,13 @@ cb(fn) x: int = "" # E: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] list(1) # E: No overload variant of "list" matches argument type "int" [call-overload] \ # N: Possible overload variants: \ - # N: def [T] __init__(self) -> List[T] \ - # N: def [T] __init__(self, x: Iterable[T]) -> List[T] \ + # N: def [T] __init__(self) -> list[T] \ + # N: def [T] __init__(self, x: Iterable[T]) -> list[T] \ # N: See https://mypy.rtfd.io/en/stable/_refs.html#code-call-overload for more info list(2) # E: No overload variant of "list" matches argument type "int" [call-overload] \ # N: Possible overload variants: \ - # N: def [T] __init__(self) -> List[T] \ - # N: def [T] __init__(self, x: Iterable[T]) -> List[T] + # N: def [T] __init__(self) -> list[T] \ + # N: def [T] __init__(self, x: Iterable[T]) -> list[T] [builtins fixtures/list.pyi] [case testNestedGenericInAliasDisallow] diff --git a/test-data/unit/check-formatting.test b/test-data/unit/check-formatting.test index dce26b37dfc8..b5b37f8d2976 100644 --- a/test-data/unit/check-formatting.test +++ b/test-data/unit/check-formatting.test @@ -150,8 +150,8 @@ di: Dict[int, int] '%(a)' % 1 # E: Format requires a mapping (expression has type "int", expected type for mapping is "SupportsKeysAndGetItem[str, Any]") '%()d' % a '%()d' % ds -'%()d' % do # E: Format requires a mapping (expression has type "Dict[object, int]", expected type for mapping is "SupportsKeysAndGetItem[str, Any]") -b'%()d' % ds # E: Format requires a mapping (expression has type "Dict[str, int]", expected type for mapping is "SupportsKeysAndGetItem[bytes, Any]") +'%()d' % do # E: Format requires a mapping (expression has type "dict[object, int]", expected type for mapping is "SupportsKeysAndGetItem[str, Any]") +b'%()d' % ds # E: Format requires a mapping (expression has type "dict[str, int]", expected type for mapping is "SupportsKeysAndGetItem[bytes, Any]") '%()s' % StringThing() b'%()s' % BytesThing() [builtins fixtures/primitives.pyi] diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index fd4cd86d1a93..4ef8e47e763a 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -369,7 +369,7 @@ t: type a: A if int(): - a = A # E: Incompatible types in assignment (expression has type "Type[A]", variable has type "A") + 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") if int(): @@ -464,10 +464,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 "Callable[[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 "Callable[[Any], Any]" [builtins fixtures/list.pyi] [case testSubtypingTypeTypeAsCallable] @@ -483,7 +483,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 "Callable[..., A]", variable has type "type[A]") -- Default argument values -- ----------------------- @@ -945,7 +945,7 @@ def f(x): pass def faulty(c: Callable[[int], None]) -> Callable[[tuple[int, int]], None]: return lambda x: None -@faulty # E: Argument 1 to "faulty" has incompatible type "Callable[[Tuple[int, int]], None]"; expected "Callable[[int], None]" +@faulty # E: Argument 1 to "faulty" has incompatible type "Callable[[tuple[int, int]], None]"; expected "Callable[[int], None]" @faulty # E: Argument 1 to "faulty" has incompatible type "Callable[[str], None]"; expected "Callable[[int], None]" def g(x: str) -> None: return None @@ -1614,11 +1614,11 @@ if g(C()): def f(x: B) -> B: pass [case testRedefineFunctionDefinedAsVariableInitializedToEmptyList] -f = [] # E: Need type annotation for "f" (hint: "f: List[] = ...") +f = [] # E: Need type annotation for "f" (hint: "f: list[] = ...") if object(): def f(): pass # E: Incompatible redefinition -f() # E: "List[Any]" not callable -f(1) # E: "List[Any]" not callable +f() # E: "list[Any]" not callable +f(1) # E: "list[Any]" not callable [builtins fixtures/list.pyi] [case testDefineConditionallyAsImportedAndDecorated] @@ -2111,7 +2111,7 @@ f(x=1, y="hello", z=[]) from typing import Dict def f(x, **kwargs): # type: (...) -> None success_dict_type = kwargs # type: Dict[str, str] - failure_dict_type = kwargs # type: Dict[int, str] # E: Incompatible types in assignment (expression has type "Dict[str, Any]", variable has type "Dict[int, str]") + failure_dict_type = kwargs # type: Dict[int, str] # E: Incompatible types in assignment (expression has type "dict[str, Any]", variable has type "dict[int, str]") f(1, thing_in_kwargs=["hey"]) [builtins fixtures/dict.pyi] [out] @@ -2120,7 +2120,7 @@ f(1, thing_in_kwargs=["hey"]) from typing import Tuple, Any def f(x, *args): # type: (...) -> None success_tuple_type = args # type: Tuple[Any, ...] - fail_tuple_type = args # type: None # E: Incompatible types in assignment (expression has type "Tuple[Any, ...]", variable has type "None") + fail_tuple_type = args # type: None # E: Incompatible types in assignment (expression has type "tuple[Any, ...]", variable has type "None") f(1, "hello") [builtins fixtures/tuple.pyi] [out] @@ -2447,7 +2447,7 @@ def make_list() -> List[T]: pass l: List[int] = make_list() -bad = make_list() # E: Need type annotation for "bad" (hint: "bad: List[] = ...") +bad = make_list() # E: Need type annotation for "bad" (hint: "bad: list[] = ...") [builtins fixtures/list.pyi] [case testAnonymousArgumentError] @@ -2494,26 +2494,26 @@ def fn( from typing import Union, Dict, List def f() -> List[Union[str, int]]: x = ['a'] - return x # E: Incompatible return value type (got "List[str]", expected "List[Union[str, int]]") \ + return x # E: Incompatible return value type (got "list[str]", expected "list[Union[str, int]]") \ # N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \ # N: Consider using "Sequence" instead, which is covariant \ - # N: Perhaps you need a type annotation for "x"? Suggestion: "List[Union[str, int]]" + # N: Perhaps you need a type annotation for "x"? Suggestion: "list[Union[str, int]]" def g() -> Dict[str, Union[str, int]]: x = {'a': 'a'} - return x # E: Incompatible return value type (got "Dict[str, str]", expected "Dict[str, Union[str, int]]") \ + return x # E: Incompatible return value type (got "dict[str, str]", expected "dict[str, Union[str, int]]") \ # N: "dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \ # N: Consider using "Mapping" instead, which is covariant in the value type \ - # N: Perhaps you need a type annotation for "x"? Suggestion: "Dict[str, Union[str, int]]" + # N: Perhaps you need a type annotation for "x"? Suggestion: "dict[str, Union[str, int]]" def h() -> Dict[Union[str, int], str]: x = {'a': 'a'} - return x # E: Incompatible return value type (got "Dict[str, str]", expected "Dict[Union[str, int], str]") \ -# N: Perhaps you need a type annotation for "x"? Suggestion: "Dict[Union[str, int], str]" + return x # E: Incompatible return value type (got "dict[str, str]", expected "dict[Union[str, int], str]") \ +# N: Perhaps you need a type annotation for "x"? Suggestion: "dict[Union[str, int], str]" def i() -> List[Union[int, float]]: x: List[int] = [1] - return x # E: Incompatible return value type (got "List[int]", expected "List[Union[int, float]]") \ + return x # E: Incompatible return value type (got "list[int]", expected "list[Union[int, float]]") \ # N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \ # N: Consider using "Sequence" instead, which is covariant @@ -2523,11 +2523,11 @@ def i() -> List[Union[int, float]]: from typing import Union, List def f() -> List[Union[int, float]]: x = ['a'] - return x # E: Incompatible return value type (got "List[str]", expected "List[Union[int, float]]") + return x # E: Incompatible return value type (got "list[str]", expected "list[Union[int, float]]") def g() -> List[Union[str, int]]: x = ('a', 2) - return x # E: Incompatible return value type (got "Tuple[str, int]", expected "List[Union[str, int]]") + return x # E: Incompatible return value type (got "tuple[str, int]", expected "list[Union[str, int]]") [builtins fixtures/list.pyi] @@ -2535,7 +2535,7 @@ def g() -> List[Union[str, int]]: from typing import Union, Dict, List def f() -> Dict[str, Union[str, int]]: x = {'a': 'a', 'b': 2} - return x # E: Incompatible return value type (got "Dict[str, object]", expected "Dict[str, Union[str, int]]") + return x # E: Incompatible return value type (got "dict[str, object]", expected "dict[str, Union[str, int]]") def g() -> Dict[str, Union[str, int]]: x: Dict[str, Union[str, int]] = {'a': 'a', 'b': 2} @@ -2543,7 +2543,7 @@ def g() -> Dict[str, Union[str, int]]: def h() -> List[Union[str, int]]: x = ['a', 2] - return x # E: Incompatible return value type (got "List[object]", expected "List[Union[str, int]]") + return x # E: Incompatible return value type (got "list[object]", expected "list[Union[str, int]]") def i() -> List[Union[str, int]]: x: List[Union[str, int]] = ['a', 2] diff --git a/test-data/unit/check-functools.test b/test-data/unit/check-functools.test index 08f82fe78d73..ebfddf7d9562 100644 --- a/test-data/unit/check-functools.test +++ b/test-data/unit/check-functools.test @@ -213,8 +213,8 @@ functools.partial(foo, 1, "a", "b", "c", d="a") # E: Argument 3 to "foo" has in def bar(*a: bytes, **k: int): p1("a", 2, 3, 4, d="a", **k) p1("a", d="a", **k) - p1("a", **k) # E: Argument 2 to "foo" has incompatible type "**Dict[str, int]"; expected "str" - p1(**k) # E: Argument 1 to "foo" has incompatible type "**Dict[str, int]"; expected "str" + p1("a", **k) # E: Argument 2 to "foo" has incompatible type "**dict[str, int]"; expected "str" + p1(**k) # E: Argument 1 to "foo" has incompatible type "**dict[str, int]"; expected "str" p1(*a) # E: Expected iterable as variadic argument @@ -382,7 +382,7 @@ T = TypeVar("T") def generic(string: str, integer: int, resulting_type: Type[T]) -> T: ... 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]" +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]") \ @@ -531,7 +531,7 @@ reveal_type(first_kw(args=[1])) # N: Revealed type is "builtins.int" # TODO: this is indeed invalid, but the error is incomprehensible. first_kw([1]) # E: Too many positional arguments for "get" \ # E: Too few arguments for "get" \ - # E: Argument 1 to "get" has incompatible type "List[int]"; expected "int" + # E: Argument 1 to "get" has incompatible type "list[int]"; expected "int" [builtins fixtures/list.pyi] [case testFunctoolsPartialHigherOrder] diff --git a/test-data/unit/check-generic-alias.test b/test-data/unit/check-generic-alias.test index 14c7738f48ae..678950a1e18b 100644 --- a/test-data/unit/check-generic-alias.test +++ b/test-data/unit/check-generic-alias.test @@ -57,14 +57,14 @@ reveal_type(t2) # N: Revealed type is "builtins.list[builtins.int]" reveal_type(t3) # N: Revealed type is "builtins.list[builtins.str]" reveal_type(t4) # N: Revealed type is "builtins.tuple[Any, ...]" # TODO: ideally these would reveal builtins.tuple -reveal_type(t5) # N: Revealed type is "Tuple[builtins.int]" -reveal_type(t6) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(t5) # N: Revealed type is "tuple[builtins.int]" +reveal_type(t6) # N: Revealed type is "tuple[builtins.int, builtins.str]" # TODO: this is incorrect, see #9522 reveal_type(t7) # N: Revealed type is "builtins.tuple[builtins.int, ...]" reveal_type(t8) # N: Revealed type is "builtins.dict[Any, Any]" reveal_type(t9) # N: Revealed type is "builtins.dict[builtins.int, builtins.str]" reveal_type(t10) # N: Revealed type is "builtins.type" -reveal_type(t11) # N: Revealed type is "Type[builtins.int]" +reveal_type(t11) # N: Revealed type is "type[builtins.int]" [builtins fixtures/dict.pyi] @@ -184,11 +184,11 @@ t10: Tuple[int, ...] = t09 A = tuple[int, ...] a: A = () b: A = (1, 2, 3) -c: A = ('x', 'y') # E: Incompatible types in assignment (expression has type "Tuple[str, str]", variable has type "Tuple[int, ...]") +c: A = ('x', 'y') # E: Incompatible types in assignment (expression has type "tuple[str, str]", variable has type "tuple[int, ...]") B = tuple[int, str] x: B = (1, 'x') -y: B = ('x', 1) # E: Incompatible types in assignment (expression has type "Tuple[str, int]", variable has type "Tuple[int, str]") +y: B = ('x', 1) # E: Incompatible types in assignment (expression has type "tuple[str, int]", variable has type "tuple[int, str]") reveal_type(tuple[int, ...]()) # N: Revealed type is "builtins.tuple[builtins.int, ...]" [builtins fixtures/tuple.pyi] @@ -196,7 +196,7 @@ reveal_type(tuple[int, ...]()) # N: Revealed type is "builtins.tuple[builtins.i [case testTypeAliasWithBuiltinTupleInStub] import m reveal_type(m.a) # N: Revealed type is "builtins.tuple[builtins.int, ...]" -reveal_type(m.b) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(m.b) # N: Revealed type is "tuple[builtins.int, builtins.str]" [file m.pyi] A = tuple[int, ...] @@ -210,7 +210,7 @@ import m reveal_type(m.a) # N: Revealed type is "builtins.list[builtins.int]" reveal_type(m.b) # N: Revealed type is "builtins.list[builtins.list[builtins.int]]" m.C # has complex representation, ignored -reveal_type(m.d) # N: Revealed type is "Type[builtins.str]" +reveal_type(m.d) # N: Revealed type is "type[builtins.str]" [file m.pyi] A = list[int] diff --git a/test-data/unit/check-generic-subtyping.test b/test-data/unit/check-generic-subtyping.test index 89465869f09d..f65ef3975852 100644 --- a/test-data/unit/check-generic-subtyping.test +++ b/test-data/unit/check-generic-subtyping.test @@ -279,9 +279,9 @@ class C(A): [out] main:11: error: Signature of "f" incompatible with supertype "A" main:11: note: Superclass: -main:11: note: def [T, S] f(self, x: List[T], y: List[S]) -> None +main:11: note: def [T, S] f(self, x: list[T], y: list[S]) -> None main:11: note: Subclass: -main:11: note: def [T] f(self, x: List[T], y: List[T]) -> None +main:11: note: def [T] f(self, x: list[T], y: list[T]) -> None [case testOverrideGenericMethodInNonGenericClassGeneralize] from typing import TypeVar diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index af2217e32b63..89693a6a7be0 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -458,7 +458,7 @@ import types a: A class A: pass a[A]() # E: Value of type "A" is not indexable -A[A]() # E: The type "Type[A]" is not generic and not indexable +A[A]() # E: The type "type[A]" is not generic and not indexable [builtins fixtures/tuple.pyi] [typing fixtures/typing-full.pyi] @@ -729,7 +729,7 @@ l.meth().append(1) reveal_type(l.meth()) # N: Revealed type is "builtins.list[builtins.int]" l.meth().append('x') # E: Argument 1 to "append" of "list" has incompatible type "str"; expected "int" -ListedNode[str]([]).x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "List[str]") +ListedNode[str]([]).x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "list[str]") [builtins fixtures/list.pyi] @@ -751,10 +751,10 @@ def f_bad(x: T) -> D[T]: return D(1) # Error, see out L[int]().append(Node((1, 1))) -L[int]().append(5) # E: Argument 1 to "append" of "list" has incompatible type "int"; expected "Node[Tuple[int, int]]" +L[int]().append(5) # E: Argument 1 to "append" of "list" has incompatible type "int"; expected "Node[tuple[int, int]]" x = D((1, 1)) # type: D[int] -y = D(5) # type: D[int] # E: Argument 1 to "D" has incompatible type "int"; expected "Tuple[int, int]" +y = D(5) # type: D[int] # E: Argument 1 to "D" has incompatible type "int"; expected "tuple[int, int]" def f(x: T) -> D[T]: return D((x, x)) @@ -762,7 +762,7 @@ reveal_type(f('a')) # N: Revealed type is "__main__.D[builtins.str]" [builtins fixtures/list.pyi] [out] -main:15: error: Argument 1 to "D" has incompatible type "int"; expected "Tuple[T, T]" +main:15: error: Argument 1 to "D" has incompatible type "int"; expected "tuple[T, T]" [case testGenericTypeAliasesSubclassingBad] @@ -838,8 +838,8 @@ reveal_type(x) # N: Revealed type is "builtins.int" def f2(x: IntTP[T]) -> IntTP[T]: return x -f2((1, 2, 3)) # E: Argument 1 to "f2" has incompatible type "Tuple[int, int, int]"; expected "Tuple[int, Never]" -reveal_type(f2((1, 'x'))) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +f2((1, 2, 3)) # E: Argument 1 to "f2" has incompatible type "tuple[int, int, int]"; expected "tuple[int, Never]" +reveal_type(f2((1, 'x'))) # N: Revealed type is "tuple[builtins.int, builtins.str]" [builtins fixtures/for.pyi] @@ -878,8 +878,8 @@ T = TypeVar('T', int, bool) Vec = List[Tuple[T, T]] vec = [] # type: Vec[bool] -vec.append('x') # E: Argument 1 to "append" of "list" has incompatible type "str"; expected "Tuple[bool, bool]" -reveal_type(vec[0]) # N: Revealed type is "Tuple[builtins.bool, builtins.bool]" +vec.append('x') # E: Argument 1 to "append" of "list" has incompatible type "str"; expected "tuple[bool, bool]" +reveal_type(vec[0]) # N: Revealed type is "tuple[builtins.bool, builtins.bool]" def fun1(v: Vec[T]) -> T: return v[0][0] @@ -887,10 +887,10 @@ def fun2(v: Vec[T], scale: T) -> Vec[T]: return v reveal_type(fun1([(1, 1)])) # N: Revealed type is "builtins.int" -fun1(1) # E: Argument 1 to "fun1" has incompatible type "int"; expected "List[Tuple[bool, bool]]" +fun1(1) # E: Argument 1 to "fun1" has incompatible type "int"; expected "list[tuple[bool, bool]]" fun1([(1, 'x')]) # E: Cannot infer type argument 1 of "fun1" -reveal_type(fun2([(1, 1)], 1)) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.int]]" +reveal_type(fun2([(1, 1)], 1)) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.int]]" fun2([('x', 'x')], 'x') # E: Value of type variable "T" of "fun2" cannot be "str" [builtins fixtures/list.pyi] @@ -903,7 +903,7 @@ T = TypeVar('T') n: TupledNode[int] n.x = 1 n.y = (1, 1) -n.y = 'x' # E: Incompatible types in assignment (expression has type "str", variable has type "Tuple[int, int]") +n.y = 'x' # E: Incompatible types in assignment (expression has type "str", variable has type "tuple[int, int]") def f(x: Node[T, T]) -> TupledNode[T]: return Node(x.x, (x.x, x.x)) @@ -935,7 +935,7 @@ def int_tf(m: int) -> Transform[int, str]: return transform var: Transform[int, str] -reveal_type(var) # N: Revealed type is "def (builtins.int, builtins.int) -> Tuple[builtins.int, builtins.str]" +reveal_type(var) # N: Revealed type is "def (builtins.int, builtins.int) -> tuple[builtins.int, builtins.str]" [file lib.py] from typing import Callable, TypeVar, Tuple @@ -966,9 +966,9 @@ NewAlias = Alias[int, int, S, S] class C: pass x: NewAlias[str] -reveal_type(x) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.int, builtins.str, builtins.str]]" +reveal_type(x) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.int, builtins.str, builtins.str]]" y: Alias[int, str, C, C] -reveal_type(y) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.str, __main__.C, __main__.C]]" +reveal_type(y) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.str, __main__.C, __main__.C]]" [file mod.py] from typing import TypeVar, List, Tuple @@ -1223,7 +1223,7 @@ class C(A[S, B[T, int]], B[U, A[int, T]]): pass c = C[object, int, str]() -reveal_type(c.m()) # N: Revealed type is "Tuple[builtins.str, __main__.A[builtins.int, builtins.int]]" +reveal_type(c.m()) # N: Revealed type is "tuple[builtins.str, __main__.A[builtins.int, builtins.int]]" [builtins fixtures/tuple.pyi] [out] @@ -1770,7 +1770,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[T]]", variable has type "Callable[[], int]") +y = C # type: Callable[[], int] # E: Incompatible types in assignment (expression has type "type[C[T]]", variable has type "Callable[[], int]") -- Special cases -- ------------- @@ -1964,8 +1964,8 @@ class C(Generic[T]): class D(C[Tuple[T, T]]): ... class E(D[str]): ... -reveal_type(E.get()) # N: Revealed type is "Tuple[builtins.str, builtins.str]" -reveal_type(E().get()) # N: Revealed type is "Tuple[builtins.str, builtins.str]" +reveal_type(E.get()) # N: Revealed type is "tuple[builtins.str, builtins.str]" +reveal_type(E().get()) # N: Revealed type is "tuple[builtins.str, builtins.str]" [builtins fixtures/classmethod.pyi] [case testGenericClassMethodExpansionReplacingTypeVar] @@ -2013,10 +2013,10 @@ class C(Generic[T]): class D(C[Tuple[T, S]]): ... class E(D[S, str]): ... -reveal_type(D.make_one) # N: Revealed type is "def [T, S] (x: Tuple[T`1, S`2]) -> __main__.C[Tuple[T`1, S`2]]" -reveal_type(D[int, str].make_one) # N: Revealed type is "def (x: Tuple[builtins.int, builtins.str]) -> __main__.C[Tuple[builtins.int, builtins.str]]" -reveal_type(E.make_one) # N: Revealed type is "def [S] (x: Tuple[S`1, builtins.str]) -> __main__.C[Tuple[S`1, builtins.str]]" -reveal_type(E[int].make_one) # N: Revealed type is "def (x: Tuple[builtins.int, builtins.str]) -> __main__.C[Tuple[builtins.int, builtins.str]]" +reveal_type(D.make_one) # N: Revealed type is "def [T, S] (x: tuple[T`1, S`2]) -> __main__.C[tuple[T`1, S`2]]" +reveal_type(D[int, str].make_one) # N: Revealed type is "def (x: tuple[builtins.int, builtins.str]) -> __main__.C[tuple[builtins.int, builtins.str]]" +reveal_type(E.make_one) # N: Revealed type is "def [S] (x: tuple[S`1, builtins.str]) -> __main__.C[tuple[S`1, builtins.str]]" +reveal_type(E[int].make_one) # N: Revealed type is "def (x: tuple[builtins.int, builtins.str]) -> __main__.C[tuple[builtins.int, builtins.str]]" [builtins fixtures/classmethod.pyi] [case testGenericClassClsNonGeneric] @@ -2161,7 +2161,7 @@ class Sub(Base[str]): ... Sub.make_some(1) # E: No overload variant of "make_some" of "Base" matches argument type "int" \ # N: Possible overload variants: \ # N: def make_some(cls, item: str) -> Sub \ - # N: def make_some(cls, item: str, n: int) -> Tuple[Sub, ...] + # N: def make_some(cls, item: str, n: int) -> tuple[Sub, ...] [builtins fixtures/classmethod.pyi] [case testNoGenericAccessOnImplicitAttributes] @@ -2191,11 +2191,11 @@ class A(Generic[T]): class B(A[T], Generic[T, S]): def meth(self) -> None: - reveal_type(A[T].foo) # N: Revealed type is "def () -> Tuple[T`1, __main__.A[T`1]]" + reveal_type(A[T].foo) # N: Revealed type is "def () -> tuple[T`1, __main__.A[T`1]]" @classmethod def other(cls) -> None: - reveal_type(cls.foo) # N: Revealed type is "def () -> Tuple[T`1, __main__.B[T`1, S`2]]" -reveal_type(B.foo) # N: Revealed type is "def [T, S] () -> Tuple[T`1, __main__.B[T`1, S`2]]" + reveal_type(cls.foo) # N: Revealed type is "def () -> tuple[T`1, __main__.B[T`1, S`2]]" +reveal_type(B.foo) # N: Revealed type is "def [T, S] () -> tuple[T`1, __main__.B[T`1, S`2]]" [builtins fixtures/classmethod.pyi] [case testGenericClassAlternativeConstructorPrecise2] @@ -2211,7 +2211,7 @@ class Base(Generic[T]): class Sub(Base[T]): ... -reveal_type(Sub.make_pair('yes')) # N: Revealed type is "Tuple[__main__.Sub[builtins.str], __main__.Sub[builtins.str]]" +reveal_type(Sub.make_pair('yes')) # N: Revealed type is "tuple[__main__.Sub[builtins.str], __main__.Sub[builtins.str]]" Sub[int].make_pair('no') # E: Argument 1 to "make_pair" of "Base" has incompatible type "str"; expected "int" [builtins fixtures/classmethod.pyi] @@ -3029,7 +3029,7 @@ def dec(f: Callable[[T], S], g: Callable[[T], U]) -> Callable[[T], Tuple[S, U]]: def id(x: V) -> V: ... -reveal_type(dec(id, id)) # N: Revealed type is "def [T] (T`1) -> Tuple[T`1, T`1]" +reveal_type(dec(id, id)) # N: Revealed type is "def [T] (T`1) -> tuple[T`1, T`1]" [builtins fixtures/tuple.pyi] [case testInferenceAgainstGenericSecondary] @@ -3123,7 +3123,7 @@ reveal_type(dec1(lambda x: 1)) # N: Revealed type is "def (builtins.int) -> bui reveal_type(dec5(lambda x: x)) # N: Revealed type is "def (builtins.int) -> builtins.list[builtins.int]" reveal_type(dec3(lambda x: x)) # N: Revealed type is "def [S] (S`20) -> builtins.list[S`20]" reveal_type(dec4(lambda x: x)) # N: Revealed type is "def [T] (builtins.list[T`24]) -> T`24" -dec4_bound(lambda x: x) # E: Value of type variable "I" of "dec4_bound" cannot be "List[T]" +dec4_bound(lambda x: x) # E: Value of type variable "I" of "dec4_bound" cannot be "list[T]" [builtins fixtures/list.pyi] [case testInferenceAgainstGenericParamSpecBasicInList] @@ -3142,7 +3142,7 @@ def either(x: U, y: U) -> U: ... def pair(x: U, y: V) -> Tuple[U, V]: ... reveal_type(dec(id)) # N: Revealed type is "def [T] (x: T`3) -> builtins.list[T`3]" reveal_type(dec(either)) # N: Revealed type is "def [T] (x: T`5, y: T`5) -> builtins.list[T`5]" -reveal_type(dec(pair)) # N: Revealed type is "def [U, V] (x: U`-1, y: V`-2) -> builtins.list[Tuple[U`-1, V`-2]]" +reveal_type(dec(pair)) # N: Revealed type is "def [U, V] (x: U`-1, y: V`-2) -> builtins.list[tuple[U`-1, V`-2]]" [builtins fixtures/list.pyi] [case testInferenceAgainstGenericParamSpecBasicDeList] @@ -3179,7 +3179,7 @@ def either(x: U, y: U) -> U: ... def pair(x: U, y: V) -> Tuple[U, V]: ... reveal_type(dec(id)) # N: Revealed type is "def () -> def [T] (T`2) -> T`2" reveal_type(dec(either)) # N: Revealed type is "def [T] (y: T`5) -> def (T`5) -> T`5" -reveal_type(dec(pair)) # N: Revealed type is "def [V] (y: V`-2) -> def [T] (T`8) -> Tuple[T`8, V`-2]" +reveal_type(dec(pair)) # N: Revealed type is "def [V] (y: V`-2) -> def [T] (T`8) -> tuple[T`8, V`-2]" reveal_type(dec(dec)) # N: Revealed type is "def () -> def [T, P, S] (def (T`-1, *P.args, **P.kwargs) -> S`-3) -> def (*P.args, **P.kwargs) -> def (T`-1) -> S`-3" [builtins fixtures/list.pyi] @@ -3200,7 +3200,7 @@ def either(x: U) -> Callable[[U], U]: ... def pair(x: U) -> Callable[[V], Tuple[V, U]]: ... reveal_type(dec(id)) # N: Revealed type is "def [T] (T`3) -> T`3" reveal_type(dec(either)) # N: Revealed type is "def [T] (T`6, x: T`6) -> T`6" -reveal_type(dec(pair)) # N: Revealed type is "def [T, U] (T`9, x: U`-1) -> Tuple[T`9, U`-1]" +reveal_type(dec(pair)) # N: Revealed type is "def [T, U] (T`9, x: U`-1) -> tuple[T`9, U`-1]" # This is counter-intuitive but looks correct, dec matches itself only if P can be empty reveal_type(dec(dec)) # N: Revealed type is "def [T, S] (T`13, f: def () -> def (T`13) -> S`14) -> S`14" [builtins fixtures/list.pyi] @@ -3337,7 +3337,7 @@ def pair(x: U, y: V) -> Tuple[U, V]: ... reveal_type(dec(id)) # N: Revealed type is "def [T] (T`3) -> builtins.list[T`3]" reveal_type(dec(either)) # N: Revealed type is "def [T] (T`5, T`5) -> builtins.list[T`5]" -reveal_type(dec(pair)) # N: Revealed type is "def [U, V] (U`-1, V`-2) -> builtins.list[Tuple[U`-1, V`-2]]" +reveal_type(dec(pair)) # N: Revealed type is "def [U, V] (U`-1, V`-2) -> builtins.list[tuple[U`-1, V`-2]]" [builtins fixtures/tuple.pyi] [case testInferenceAgainstGenericVariadicBasicDeList] @@ -3376,7 +3376,7 @@ def pair(x: U, y: V) -> Tuple[U, V]: ... reveal_type(dec(id)) # N: Revealed type is "def () -> def [T] (T`2) -> T`2" reveal_type(dec(either)) # N: Revealed type is "def [T] (T`5) -> def (T`5) -> T`5" -reveal_type(dec(pair)) # N: Revealed type is "def [V] (V`-2) -> def [T] (T`8) -> Tuple[T`8, V`-2]" +reveal_type(dec(pair)) # N: Revealed type is "def [V] (V`-2) -> def [T] (T`8) -> tuple[T`8, V`-2]" reveal_type(dec(dec)) # N: Revealed type is "def () -> def [T, Ts, S] (def (T`-1, *Unpack[Ts`-2]) -> S`-3) -> def (*Unpack[Ts`-2]) -> def (T`-1) -> S`-3" [builtins fixtures/list.pyi] @@ -3398,7 +3398,7 @@ def pair(x: U) -> Callable[[V], Tuple[V, U]]: ... reveal_type(dec(id)) # N: Revealed type is "def [T] (T`3) -> T`3" reveal_type(dec(either)) # N: Revealed type is "def [T] (T`6, T`6) -> T`6" -reveal_type(dec(pair)) # N: Revealed type is "def [T, U] (T`9, U`-1) -> Tuple[T`9, U`-1]" +reveal_type(dec(pair)) # N: Revealed type is "def [T, U] (T`9, U`-1) -> tuple[T`9, U`-1]" # This is counter-intuitive but looks correct, dec matches itself only if Ts is empty reveal_type(dec(dec)) # N: Revealed type is "def [T, S] (T`13, def () -> def (T`13) -> S`14) -> S`14" [builtins fixtures/list.pyi] diff --git a/test-data/unit/check-incremental.test b/test-data/unit/check-incremental.test index 9d5902246ae5..a8116d9cf78a 100644 --- a/test-data/unit/check-incremental.test +++ b/test-data/unit/check-incremental.test @@ -3517,7 +3517,7 @@ class M(type): y: int [out] [out2] -tmp/a.py:2: error: "Type[B]" has no attribute "x" +tmp/a.py:2: error: "type[B]" has no attribute "x" [case testIncrementalLotsOfInheritance] import a @@ -4654,7 +4654,7 @@ B = TypedDict('B', {'x': A}) [typing fixtures/typing-typeddict.pyi] [out] [out2] -tmp/a.py:3: note: Revealed type is "Tuple[TypedDict('other.B', {'x': Tuple[..., fallback=lib.A]}), fallback=lib.A]" +tmp/a.py:3: note: Revealed type is "tuple[TypedDict('other.B', {'x': tuple[..., fallback=lib.A]}), fallback=lib.A]" [case testFollowImportSkipNotInvalidatedOnPresent] # flags: --follow-imports=skip @@ -5123,7 +5123,7 @@ NT = NamedTuple('BadName', [('x', int)]) tmp/b.py:2: error: First argument to namedtuple() should be "NT", not "BadName" [out2] tmp/b.py:2: error: First argument to namedtuple() should be "NT", not "BadName" -tmp/a.py:3: note: Revealed type is "Tuple[builtins.int, fallback=b.NT]" +tmp/a.py:3: note: Revealed type is "tuple[builtins.int, fallback=b.NT]" [case testNewAnalyzerIncrementalBrokenNamedTupleNested] @@ -5164,7 +5164,7 @@ class C: [builtins fixtures/tuple.pyi] [out] [out2] -tmp/a.py:3: note: Revealed type is "Tuple[builtins.int, fallback=b.C.Hidden@5]" +tmp/a.py:3: note: Revealed type is "tuple[builtins.int, fallback=b.C.Hidden@5]" [case testIncrementalNodeCreatedFromGetattr] import a @@ -5314,7 +5314,7 @@ reveal_type(Foo().x) [builtins fixtures/isinstance.pyi] [out] [out2] -tmp/b.py:2: note: Revealed type is "a." +tmp/b.py:2: note: Revealed type is "a." [case testIsInstanceAdHocIntersectionIncrementalIsInstanceChange] import c @@ -5845,9 +5845,9 @@ reveal_type(a.n) [out] [out2] [out3] -tmp/c.py:4: note: Revealed type is "Tuple[Union[Tuple[Union[..., None], builtins.int, fallback=b.M], None], builtins.int, fallback=a.N]" +tmp/c.py:4: note: Revealed type is "tuple[Union[tuple[Union[..., None], builtins.int, fallback=b.M], None], builtins.int, fallback=a.N]" tmp/c.py:5: error: Incompatible types in assignment (expression has type "Optional[N]", variable has type "int") -tmp/c.py:7: note: Revealed type is "Tuple[Union[Tuple[Union[..., None], builtins.int, fallback=b.M], None], builtins.int, fallback=a.N]" +tmp/c.py:7: note: Revealed type is "tuple[Union[tuple[Union[..., None], builtins.int, fallback=b.M], None], builtins.int, fallback=a.N]" [case testTupleTypeUpdateNonRecursiveToRecursiveCoarse] import c @@ -5878,7 +5878,7 @@ def f(x: a.N) -> None: [out] [out2] [out3] -tmp/c.py:4: note: Revealed type is "Tuple[Union[Tuple[Union[..., None], builtins.int, fallback=b.M], None], builtins.int, fallback=a.N]" +tmp/c.py:4: note: Revealed type is "tuple[Union[tuple[Union[..., None], builtins.int, fallback=b.M], None], builtins.int, fallback=a.N]" tmp/c.py:5: error: Incompatible types in assignment (expression has type "Optional[N]", variable has type "int") [case testTypeAliasUpdateNonRecursiveToRecursiveCoarse] @@ -5910,7 +5910,7 @@ def f(x: a.N) -> None: [out] [out2] [out3] -tmp/c.py:4: note: Revealed type is "Tuple[Union[Tuple[Union[..., None], builtins.int], None], builtins.int]" +tmp/c.py:4: note: Revealed type is "tuple[Union[tuple[Union[..., None], builtins.int], None], builtins.int]" tmp/c.py:5: error: Incompatible types in assignment (expression has type "Optional[N]", variable has type "int") [case testTypedDictUpdateNonRecursiveToRecursiveCoarse] diff --git a/test-data/unit/check-inference-context.test b/test-data/unit/check-inference-context.test index 20f534d60978..0aa67b2bf7f3 100644 --- a/test-data/unit/check-inference-context.test +++ b/test-data/unit/check-inference-context.test @@ -372,7 +372,7 @@ ao: List[object] a: A def f(): a, aa, ao # Prevent redefinition -a = [] # E: Incompatible types in assignment (expression has type "List[Never]", variable has type "A") +a = [] # E: Incompatible types in assignment (expression has type "list[Never]", variable has type "A") aa = [] ao = [] @@ -424,7 +424,7 @@ class B(A): pass [case testLocalVariableInferenceFromEmptyList] import typing def f() -> None: - a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") b = [None] c = [B()] if int(): @@ -437,14 +437,14 @@ class B: pass [case testNestedListExpressions] # flags: --no-strict-optional from typing import List -aao = None # type: List[List[object]] -aab = None # type: List[List[B]] -ab = None # type: List[B] +aao = None # type: list[list[object]] +aab = None # type: list[list[B]] +ab = None # type: list[B] b = None # type: B o = None # type: object def f(): aao, aab # Prevent redefinition -aao = [[o], ab] # E: List item 1 has incompatible type "List[B]"; expected "List[object]" +aao = [[o], ab] # E: List item 1 has incompatible type "list[B]"; expected "list[object]" aab = [[], [o]] # E: List item 0 has incompatible type "object"; expected "B" aao = [[None], [b], [], [o]] @@ -733,7 +733,7 @@ class B: pass m = map(g, [A()]) b = m # type: List[B] -a = m # type: List[A] # E: Incompatible types in assignment (expression has type "List[B]", variable has type "List[A]") +a = m # type: List[A] # E: Incompatible types in assignment (expression has type "list[B]", variable has type "list[A]") [builtins fixtures/list.pyi] @@ -756,9 +756,9 @@ if int(): if int(): b = b or [C()] if int(): - a = a or b # E: Incompatible types in assignment (expression has type "Union[List[A], List[B]]", variable has type "List[A]") + a = a or b # E: Incompatible types in assignment (expression has type "Union[list[A], list[B]]", variable has type "list[A]") if int(): - b = b or c # E: Incompatible types in assignment (expression has type "Union[List[B], List[C]]", variable has type "List[B]") + b = b or c # E: Incompatible types in assignment (expression has type "Union[list[B], list[C]]", variable has type "list[B]") [builtins fixtures/list.pyi] @@ -814,7 +814,7 @@ s: List[str] if int(): i = i = [] if int(): - i = s = [] # E: Incompatible types in assignment (expression has type "List[str]", variable has type "List[int]") + i = s = [] # E: Incompatible types in assignment (expression has type "list[str]", variable has type "list[int]") [builtins fixtures/list.pyi] [case testContextForAttributeDeclaredInInit] @@ -842,7 +842,7 @@ T = TypeVar('T') def f(x: Union[List[T], str]) -> None: pass f([1]) f('') -f(1) # E: Argument 1 to "f" has incompatible type "int"; expected "Union[List[Never], str]" +f(1) # E: Argument 1 to "f" has incompatible type "int"; expected "Union[list[Never], str]" [builtins fixtures/isinstancelist.pyi] [case testIgnoringInferenceContext] diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index 25565946158e..a98597e6e320 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -275,14 +275,14 @@ from typing import Type class Foo: ... A: Type[Foo] = Foo -a, b = Foo # E: "Type[Foo]" object is not iterable -c, d = A # E: "Type[Foo]" object is not iterable +a, b = Foo # E: "type[Foo]" object is not iterable +c, d = A # E: "type[Foo]" object is not iterable class Meta(type): ... class Bar(metaclass=Meta): ... B: Type[Bar] = Bar -e, f = Bar # E: "Type[Bar]" object is not iterable -g, h = B # E: "Type[Bar]" object is not iterable +e, f = Bar # E: "type[Bar]" object is not iterable +g, h = B # E: "type[Bar]" object is not iterable reveal_type(a) # E: Cannot determine type of "a" # N: Revealed type is "Any" reveal_type(b) # E: Cannot determine type of "b" # N: Revealed type is "Any" @@ -330,8 +330,8 @@ a, b, c = Foo d, e, f = A g, h, i = B j, k, l = C -m, n, o = D # E: "Type[Baz]" object is not iterable -p, q, r = E # E: "Type[Spam]" object is not iterable +m, n, o = D # E: "type[Baz]" object is not iterable +p, q, r = E # E: "type[Spam]" object is not iterable s, t, u = Eggs v, w, x = F y, z, aa = G @@ -553,7 +553,7 @@ if int(): b = id(a) # E: Incompatible types in assignment (expression has type "A", variable has type "B") a = id(b) # E: Incompatible types in assignment (expression has type "B", variable has type "A") if int(): - a = id(c) # E: Incompatible types in assignment (expression has type "Tuple[A, object]", variable has type "A") + a = id(c) # E: Incompatible types in assignment (expression has type "tuple[A, object]", variable has type "A") if int(): a = id(a) @@ -843,7 +843,7 @@ if int(): l = [A()] lb = [b] if int(): - l = lb # E: Incompatible types in assignment (expression has type "List[bool]", variable has type "List[A]") + l = lb # E: Incompatible types in assignment (expression has type "list[bool]", variable has type "list[A]") [builtins fixtures/for.pyi] [case testGenericFunctionWithTypeTypeAsCallable] @@ -871,15 +871,15 @@ f(1, 1)() # E: "int" not callable def g(x: Union[T, List[T]]) -> List[T]: pass def h(x: List[str]) -> None: pass -g('a')() # E: "List[str]" not callable +g('a')() # E: "list[str]" not callable # The next line is a case where there are multiple ways to satisfy a constraint -# involving a Union. Either T = List[str] or T = str would turn out to be valid, +# involving a Union. Either T = list[str] or T = str would turn out to be valid, # but mypy doesn't know how to branch on these two options (and potentially have # to backtrack later) and defaults to T = Never. The result is an # awkward error message. Either a better error message, or simply accepting the # call, would be preferable here. -g(['a']) # E: Argument 1 to "g" has incompatible type "List[str]"; expected "List[Never]" +g(['a']) # E: Argument 1 to "g" has incompatible type "list[str]"; expected "list[Never]" h(g(['a'])) @@ -888,7 +888,7 @@ a = [1] b = ['b'] i(a, a, b) i(b, a, b) -i(a, b, b) # E: Argument 1 to "i" has incompatible type "List[int]"; expected "List[str]" +i(a, b, b) # E: Argument 1 to "i" has incompatible type "list[int]"; expected "list[str]" [builtins fixtures/list.pyi] [case testCallableListJoinInference] @@ -972,7 +972,7 @@ from typing import TypeVar, Union, List T = TypeVar('T') def f() -> List[T]: pass d1 = f() # type: Union[List[int], str] -d2 = f() # type: Union[int, str] # E: Incompatible types in assignment (expression has type "List[Never]", variable has type "Union[int, str]") +d2 = f() # type: Union[int, str] # E: Incompatible types in assignment (expression has type "list[Never]", variable has type "Union[int, str]") def g(x: T) -> List[T]: pass d3 = g(1) # type: Union[List[int], List[str]] [builtins fixtures/list.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 "Callable[[int, list[T@k1]], list[Union[T@k1, int]]]", variable has type "Callable[[S, list[T@k2]], list[Union[T@k2, int]]]") b = k1 if int(): b = k1 @@ -1041,7 +1041,7 @@ d = {a:b} if int(): d = d_ab() if int(): - d = d_aa() # E: Incompatible types in assignment (expression has type "Dict[A, A]", variable has type "Dict[A, B]") + d = d_aa() # E: Incompatible types in assignment (expression has type "dict[A, A]", variable has type "dict[A, B]") [builtins fixtures/dict.pyi] [case testSetLiteral] @@ -1056,7 +1056,7 @@ if int(): if int(): s = s_i() if int(): - s = s_s() # E: Incompatible types in assignment (expression has type "Set[str]", variable has type "Set[int]") + s = s_s() # E: Incompatible types in assignment (expression has type "set[str]", variable has type "set[int]") [builtins fixtures/set.pyi] [case testSetWithStarExpr] @@ -1391,14 +1391,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 "Callable[[], list[int]]", variable has type "Callable[[], 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 "Callable[[], list[B]]", variable has type "Callable[[], list[A]]") class A: pass class B: pass @@ -1491,7 +1491,7 @@ o: List[object] a2 = a or [] if int(): a = a2 - a2 = o # E: Incompatible types in assignment (expression has type "List[object]", variable has type "List[A]") + a2 = o # E: Incompatible types in assignment (expression has type "list[object]", variable has type "list[A]") class A: pass [builtins fixtures/list.pyi] @@ -1535,7 +1535,7 @@ if int(): a = x2 if int(): a = x3 \ - # E: Incompatible types in assignment (expression has type "List[B]", variable has type "List[A]") \ + # E: Incompatible types in assignment (expression has type "list[B]", variable has type "list[A]") \ # N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \ # N: Consider using "Sequence" instead, which is covariant [builtins fixtures/list.pyi] @@ -1558,7 +1558,7 @@ if int(): a = x2 if int(): a = x3 \ - # E: Incompatible types in assignment (expression has type "List[B]", variable has type "List[A]") \ + # E: Incompatible types in assignment (expression has type "list[B]", variable has type "list[A]") \ # N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \ # N: Consider using "Sequence" instead, which is covariant [builtins fixtures/list.pyi] @@ -1582,28 +1582,28 @@ a.append(0) # E: Argument 1 to "append" of "list" has incompatible type "int"; [builtins fixtures/list.pyi] [case testInferListInitializedToEmptyAndNotAnnotated] -a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") +a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") [builtins fixtures/list.pyi] [case testInferListInitializedToEmptyAndReadBeforeAppend] -a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") +a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") if a: pass -a.xyz # E: "List[Any]" has no attribute "xyz" +a.xyz # E: "list[Any]" has no attribute "xyz" a.append('') [builtins fixtures/list.pyi] [case testInferListInitializedToEmptyAndIncompleteTypeInAppend] -a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") +a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") a.append([]) -a() # E: "List[Any]" not callable +a() # E: "list[Any]" not callable [builtins fixtures/list.pyi] [case testInferListInitializedToEmptyAndMultipleAssignment] a, b = [], [] a.append(1) b.append('') -a() # E: "List[int]" not callable -b() # E: "List[str]" not callable +a() # E: "list[int]" not callable +b() # E: "list[str]" not callable [builtins fixtures/list.pyi] [case testInferListInitializedToEmptyInFunction] @@ -1615,7 +1615,7 @@ def f() -> None: [case testInferListInitializedToEmptyAndNotAnnotatedInFunction] def f() -> None: - a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") def g() -> None: pass @@ -1625,9 +1625,9 @@ a.append(1) [case testInferListInitializedToEmptyAndReadBeforeAppendInFunction] def f() -> None: - a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") if a: pass - a.xyz # E: "List[Any]" has no attribute "xyz" + a.xyz # E: "list[Any]" has no attribute "xyz" a.append('') [builtins fixtures/list.pyi] @@ -1640,7 +1640,7 @@ class A: [case testInferListInitializedToEmptyAndNotAnnotatedInClassBody] class A: - a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") class B: a = [] @@ -1658,7 +1658,7 @@ class A: [case testInferListInitializedToEmptyAndNotAnnotatedInMethod] class A: def f(self) -> None: - a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") [builtins fixtures/list.pyi] [case testInferListInitializedToEmptyInMethodViaAttribute] @@ -1675,7 +1675,7 @@ from typing import List class A: def __init__(self) -> None: - self.x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") + self.x = [] # E: Need type annotation for "x" (hint: "x: list[] = ...") class B(A): @property @@ -1704,27 +1704,27 @@ a.add('') # E: Argument 1 to "add" of "set" has incompatible type "str"; expect [case testInferDictInitializedToEmpty] a = {} a[1] = '' -a() # E: "Dict[int, str]" not callable +a() # E: "dict[int, str]" not callable [builtins fixtures/dict.pyi] [case testInferDictInitializedToEmptyUsingUpdate] a = {} a.update({'': 42}) -a() # E: "Dict[str, int]" not callable +a() # E: "dict[str, int]" not callable [builtins fixtures/dict.pyi] [case testInferDictInitializedToEmptyUsingUpdateError] -a = {} # E: Need type annotation for "a" (hint: "a: Dict[, ] = ...") -a.update([1, 2]) # E: Argument 1 to "update" of "dict" has incompatible type "List[int]"; expected "SupportsKeysAndGetItem[Any, Any]" \ +a = {} # E: Need type annotation for "a" (hint: "a: dict[, ] = ...") +a.update([1, 2]) # E: Argument 1 to "update" of "dict" has incompatible type "list[int]"; expected "SupportsKeysAndGetItem[Any, Any]" \ # N: "list" is missing following "SupportsKeysAndGetItem" protocol member: \ # N: keys -a() # E: "Dict[Any, Any]" not callable +a() # E: "dict[Any, Any]" not callable [builtins fixtures/dict.pyi] [case testInferDictInitializedToEmptyAndIncompleteTypeInUpdate] -a = {} # E: Need type annotation for "a" (hint: "a: Dict[, ] = ...") +a = {} # E: Need type annotation for "a" (hint: "a: dict[, ] = ...") a[1] = {} -b = {} # E: Need type annotation for "b" (hint: "b: Dict[, ] = ...") +b = {} # E: Need type annotation for "b" (hint: "b: dict[, ] = ...") b[{}] = 1 [builtins fixtures/dict.pyi] @@ -1754,8 +1754,8 @@ def f(blocks: object): to_process = [] to_process = list(blocks) # E: No overload variant of "list" matches argument type "object" \ # N: Possible overload variants: \ - # N: def [T] __init__(self) -> List[T] \ - # N: def [T] __init__(self, x: Iterable[T]) -> List[T] + # N: def [T] __init__(self) -> list[T] \ + # N: def [T] __init__(self, x: Iterable[T]) -> list[T] [builtins fixtures/list.pyi] [case testInferListInitializedToEmptyAndAssigned] @@ -1776,9 +1776,9 @@ if bool(): d = {1: 'x'} reveal_type(d) # N: Revealed type is "builtins.dict[builtins.int, builtins.str]" -dd = {} # E: Need type annotation for "dd" (hint: "dd: Dict[, ] = ...") +dd = {} # E: Need type annotation for "dd" (hint: "dd: dict[, ] = ...") if bool(): - dd = [1] # E: Incompatible types in assignment (expression has type "List[int]", variable has type "Dict[Any, Any]") + dd = [1] # E: Incompatible types in assignment (expression has type "list[int]", variable has type "dict[Any, Any]") reveal_type(dd) # N: Revealed type is "builtins.dict[Any, Any]" [builtins fixtures/dict.pyi] @@ -1796,27 +1796,27 @@ reveal_type(oo) # N: Revealed type is "collections.OrderedDict[builtins.int, bui [builtins fixtures/dict.pyi] [case testEmptyCollectionAssignedToVariableTwiceIncremental] -x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") +x = [] # E: Need type annotation for "x" (hint: "x: list[] = ...") y = x x = [] reveal_type(x) # N: Revealed type is "builtins.list[Any]" -d = {} # E: Need type annotation for "d" (hint: "d: Dict[, ] = ...") +d = {} # E: Need type annotation for "d" (hint: "d: dict[, ] = ...") z = d d = {} reveal_type(d) # N: Revealed type is "builtins.dict[Any, Any]" [builtins fixtures/dict.pyi] [out2] -main:1: error: Need type annotation for "x" (hint: "x: List[] = ...") +main:1: error: Need type annotation for "x" (hint: "x: list[] = ...") main:4: note: Revealed type is "builtins.list[Any]" -main:5: error: Need type annotation for "d" (hint: "d: Dict[, ] = ...") +main:5: error: Need type annotation for "d" (hint: "d: dict[, ] = ...") main:8: note: Revealed type is "builtins.dict[Any, Any]" [case testEmptyCollectionAssignedToVariableTwiceNoReadIncremental] -x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") +x = [] # E: Need type annotation for "x" (hint: "x: list[] = ...") x = [] [builtins fixtures/list.pyi] [out2] -main:1: error: Need type annotation for "x" (hint: "x: List[] = ...") +main:1: error: Need type annotation for "x" (hint: "x: list[] = ...") [case testInferAttributeInitializedToEmptyAndAssigned] class C: @@ -1856,7 +1856,7 @@ reveal_type(C().a) # N: Revealed type is "Union[builtins.int, None]" [case testInferAttributeInitializedToEmptyNonSelf] class C: def __init__(self) -> None: - self.a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") + self.a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") if bool(): a = self a.a = [1] @@ -1867,7 +1867,7 @@ reveal_type(C().a) # N: Revealed type is "builtins.list[Any]" [case testInferAttributeInitializedToEmptyAndAssignedOtherMethod] class C: def __init__(self) -> None: - self.a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") + self.a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") def meth(self) -> None: self.a = [1] reveal_type(C().a) # N: Revealed type is "builtins.list[Any]" @@ -1876,7 +1876,7 @@ reveal_type(C().a) # N: Revealed type is "builtins.list[Any]" [case testInferAttributeInitializedToEmptyAndAppendedOtherMethod] class C: def __init__(self) -> None: - self.a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") + self.a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") def meth(self) -> None: self.a.append(1) reveal_type(C().a) # N: Revealed type is "builtins.list[Any]" @@ -1885,7 +1885,7 @@ reveal_type(C().a) # N: Revealed type is "builtins.list[Any]" [case testInferAttributeInitializedToEmptyAndAssignedItemOtherMethod] class C: def __init__(self) -> None: - self.a = {} # E: Need type annotation for "a" (hint: "a: Dict[, ] = ...") + self.a = {} # E: Need type annotation for "a" (hint: "a: dict[, ] = ...") def meth(self) -> None: self.a[0] = 'yes' reveal_type(C().a) # N: Revealed type is "builtins.dict[Any, Any]" @@ -1901,7 +1901,7 @@ reveal_type(C().a) # N: Revealed type is "None" [case testInferAttributeInitializedToEmptyAndAssignedClassBody] class C: - a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") def __init__(self) -> None: self.a = [1] reveal_type(C().a) # N: Revealed type is "builtins.list[Any]" @@ -1909,7 +1909,7 @@ reveal_type(C().a) # N: Revealed type is "builtins.list[Any]" [case testInferAttributeInitializedToEmptyAndAppendedClassBody] class C: - a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") def __init__(self) -> None: self.a.append(1) reveal_type(C().a) # N: Revealed type is "builtins.list[Any]" @@ -1917,7 +1917,7 @@ reveal_type(C().a) # N: Revealed type is "builtins.list[Any]" [case testInferAttributeInitializedToEmptyAndAssignedItemClassBody] class C: - a = {} # E: Need type annotation for "a" (hint: "a: Dict[, ] = ...") + a = {} # E: Need type annotation for "a" (hint: "a: dict[, ] = ...") def __init__(self) -> None: self.a[0] = 'yes' reveal_type(C().a) # N: Revealed type is "builtins.dict[Any, Any]" @@ -2042,7 +2042,7 @@ x.append('') # E: Argument 1 to "append" of "list" has incompatible type "str"; x = None if object(): # Promote from partial None to partial list. - x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") + x = [] # E: Need type annotation for "x" (hint: "x: list[] = ...") x [builtins fixtures/list.pyi] @@ -2051,7 +2051,7 @@ def f() -> None: x = None if object(): # Promote from partial None to partial list. - x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") + x = [] # E: Need type annotation for "x" (hint: "x: list[] = ...") [builtins fixtures/list.pyi] [out] @@ -2131,7 +2131,7 @@ class A: [case testPartialTypeErrorSpecialCase2] # This used to crash. class A: - x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") + x = [] # E: Need type annotation for "x" (hint: "x: list[] = ...") def f(self) -> None: for a in self.x: pass @@ -2257,7 +2257,7 @@ def g(d: Dict[str, int]) -> None: pass def f() -> None: x = {} x[1] = y - g(x) # E: Argument 1 to "g" has incompatible type "Dict[int, str]"; expected "Dict[str, int]" + g(x) # E: Argument 1 to "g" has incompatible type "dict[int, str]"; expected "dict[str, int]" x[1] = 1 # E: Incompatible types in assignment (expression has type "int", target has type "str") x[1] = '' y = '' @@ -2271,7 +2271,7 @@ def f() -> None: x = {} y x[1] = 1 - g(x) # E: Argument 1 to "g" has incompatible type "Dict[int, int]"; expected "Dict[str, int]" + g(x) # E: Argument 1 to "g" has incompatible type "dict[int, int]"; expected "dict[str, int]" y = '' [builtins fixtures/dict.pyi] [out] @@ -2290,7 +2290,7 @@ def f() -> None: y = o x = [] x.append(y) - x() # E: "List[int]" not callable + x() # E: "list[int]" not callable o = 1 [builtins fixtures/list.pyi] [out] @@ -2300,16 +2300,16 @@ def f() -> None: y = o x = {} x[''] = y - x() # E: "Dict[str, int]" not callable + x() # E: "dict[str, int]" not callable o = 1 [builtins fixtures/dict.pyi] [out] [case testMultipassAndPartialTypesSpecialCase3] def f() -> None: - x = {} # E: Need type annotation for "x" (hint: "x: Dict[, ] = ...") + x = {} # E: Need type annotation for "x" (hint: "x: dict[, ] = ...") y = o - z = {} # E: Need type annotation for "z" (hint: "z: Dict[, ] = ...") + z = {} # E: Need type annotation for "z" (hint: "z: dict[, ] = ...") o = 1 [builtins fixtures/dict.pyi] [out] @@ -2390,7 +2390,7 @@ b: Union[str, tuple] def f(): pass def g(x: Union[int, str]): pass c = a if f() else b -g(c) # E: Argument 1 to "g" has incompatible type "Union[int, str, Tuple[Any, ...]]"; expected "Union[int, str]" +g(c) # E: Argument 1 to "g" has incompatible type "Union[int, str, tuple[Any, ...]]"; expected "Union[int, str]" [builtins fixtures/tuple.pyi] [case testUnificationMultipleInheritance] @@ -2429,58 +2429,58 @@ a2.foo2() [case testUnificationEmptyListLeft] def f(): pass a = [] if f() else [0] -a() # E: "List[int]" not callable +a() # E: "list[int]" not callable [builtins fixtures/list.pyi] [case testUnificationEmptyListRight] def f(): pass a = [0] if f() else [] -a() # E: "List[int]" not callable +a() # E: "list[int]" not callable [builtins fixtures/list.pyi] [case testUnificationEmptyListLeftInContext] from typing import List def f(): pass -a = [] if f() else [0] # type: List[int] -a() # E: "List[int]" not callable +a = [] if f() else [0] # type: list[int] +a() # E: "list[int]" not callable [builtins fixtures/list.pyi] [case testUnificationEmptyListRightInContext] # TODO Find an example that really needs the context from typing import List def f(): pass -a = [0] if f() else [] # type: List[int] -a() # E: "List[int]" not callable +a = [0] if f() else [] # type: list[int] +a() # E: "list[int]" not callable [builtins fixtures/list.pyi] [case testUnificationEmptySetLeft] def f(): pass a = set() if f() else {0} -a() # E: "Set[int]" not callable +a() # E: "set[int]" not callable [builtins fixtures/set.pyi] [case testUnificationEmptyDictLeft] def f(): pass a = {} if f() else {0: 0} -a() # E: "Dict[int, int]" not callable +a() # E: "dict[int, int]" not callable [builtins fixtures/dict.pyi] [case testUnificationEmptyDictRight] def f(): pass a = {0: 0} if f() else {} -a() # E: "Dict[int, int]" not callable +a() # E: "dict[int, int]" not callable [builtins fixtures/dict.pyi] [case testUnificationDictWithEmptyListLeft] def f(): pass a = {0: []} if f() else {0: [0]} -a() # E: "Dict[int, List[int]]" not callable +a() # E: "dict[int, list[int]]" not callable [builtins fixtures/dict.pyi] [case testUnificationDictWithEmptyListRight] def f(): pass a = {0: [0]} if f() else {0: []} -a() # E: "Dict[int, List[int]]" not callable +a() # E: "dict[int, list[int]]" not callable [builtins fixtures/dict.pyi] [case testMisguidedSetItem] @@ -2489,7 +2489,7 @@ T = TypeVar('T') class C(Sequence[T], Generic[T]): pass C[0] = 0 [out] -main:4: error: Unsupported target for indexed assignment ("Type[C[T]]") +main:4: error: Unsupported target for indexed assignment ("type[C[T]]") main:4: error: Invalid type: try using Literal[0] instead? [case testNoCrashOnPartialMember] @@ -2497,7 +2497,7 @@ main:4: error: Invalid type: try using Literal[0] instead? class C: x = None def __init__(self) -> None: - self.x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") + self.x = [] # E: Need type annotation for "x" (hint: "x: list[] = ...") [builtins fixtures/list.pyi] [out] @@ -2676,7 +2676,7 @@ class A: [case testLocalPartialTypesWithClassAttributeInitializedToEmptyDict] # flags: --local-partial-types class A: - x = {} # E: Need type annotation for "x" (hint: "x: Dict[, ] = ...") + x = {} # E: Need type annotation for "x" (hint: "x: dict[, ] = ...") def f(self) -> None: self.x[0] = '' @@ -2699,7 +2699,7 @@ reveal_type(a) # N: Revealed type is "builtins.list[builtins.int]" [case testLocalPartialTypesWithGlobalInitializedToEmptyList2] # flags: --local-partial-types -a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") +a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") def f() -> None: a.append(1) @@ -2710,7 +2710,7 @@ reveal_type(a) # N: Revealed type is "builtins.list[Any]" [case testLocalPartialTypesWithGlobalInitializedToEmptyList3] # flags: --local-partial-types -a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") +a = [] # E: Need type annotation for "a" (hint: "a: list[] = ...") def f(): a.append(1) @@ -2732,7 +2732,7 @@ reveal_type(a) # N: Revealed type is "builtins.dict[builtins.int, builtins.str]" [case testLocalPartialTypesWithGlobalInitializedToEmptyDict2] # flags: --local-partial-types -a = {} # E: Need type annotation for "a" (hint: "a: Dict[, ] = ...") +a = {} # E: Need type annotation for "a" (hint: "a: dict[, ] = ...") def f() -> None: a[0] = '' @@ -2743,7 +2743,7 @@ reveal_type(a) # N: Revealed type is "builtins.dict[Any, Any]" [case testLocalPartialTypesWithGlobalInitializedToEmptyDict3] # flags: --local-partial-types -a = {} # E: Need type annotation for "a" (hint: "a: Dict[, ] = ...") +a = {} # E: Need type annotation for "a" (hint: "a: dict[, ] = ...") def f(): a[0] = '' @@ -3306,7 +3306,7 @@ class A: s = self s.y['x'].append(1) -x = {} # E: Need type annotation for "x" (hint: "x: Dict[, ] = ...") +x = {} # E: Need type annotation for "x" (hint: "x: dict[, ] = ...") x['x'].append(1) y = defaultdict(list) # E: Need type annotation for "y" @@ -3539,13 +3539,13 @@ class P: class M: x: List[str] class C(P, M): - x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") + x = [] # E: Need type annotation for "x" (hint: "x: list[] = ...") reveal_type(C.x) # N: Revealed type is "builtins.list[Any]" [builtins fixtures/list.pyi] [case testNoPartialInSupertypeAsContext] class A: - args = {} # E: Need type annotation for "args" (hint: "args: Dict[, ] = ...") + args = {} # E: Need type annotation for "args" (hint: "args: dict[, ] = ...") def f(self) -> None: value = {1: "Hello"} class B(A): @@ -3606,7 +3606,7 @@ S = TypeVar('S') def f(x: Callable[[T, S], None]) -> Tuple[T, S]: ... def g(*x: int) -> None: ... -reveal_type(f(g)) # N: Revealed type is "Tuple[builtins.int, builtins.int]" +reveal_type(f(g)) # N: Revealed type is "tuple[builtins.int, builtins.int]" [builtins fixtures/list.pyi] [case testCallableInferenceAgainstCallableStarVsPos] @@ -3620,7 +3620,7 @@ class Call(Protocol[T, S]): def f(x: Call[T, S]) -> Tuple[T, S]: ... def g(*x: int) -> None: ... -reveal_type(f(g)) # N: Revealed type is "Tuple[builtins.int, builtins.int]" +reveal_type(f(g)) # N: Revealed type is "tuple[builtins.int, builtins.int]" [builtins fixtures/list.pyi] [case testCallableInferenceAgainstCallableNamedVsStar] @@ -3634,7 +3634,7 @@ class Call(Protocol[T, S]): def f(x: Call[T, S]) -> Tuple[T, S]: ... def g(**kwargs: int) -> None: ... -reveal_type(f(g)) # N: Revealed type is "Tuple[builtins.int, builtins.int]" +reveal_type(f(g)) # N: Revealed type is "tuple[builtins.int, builtins.int]" [builtins fixtures/list.pyi] [case testCallableInferenceAgainstCallableStarVsNamed] @@ -3648,7 +3648,7 @@ class Call(Protocol[T, S]): def f(x: Call[T, S]) -> Tuple[T, S]: ... def g(**kwargs: int) -> None: pass -reveal_type(f(g)) # N: Revealed type is "Tuple[builtins.int, builtins.int]" +reveal_type(f(g)) # N: Revealed type is "tuple[builtins.int, builtins.int]" [builtins fixtures/list.pyi] [case testCallableInferenceAgainstCallableNamedVsNamed] @@ -3664,7 +3664,7 @@ def f(x: Call[T, S]) -> Tuple[T, S]: ... # Note: order of names is different w.r.t. protocol def g(*, y: int, x: str) -> None: pass -reveal_type(f(g)) # N: Revealed type is "Tuple[builtins.str, builtins.int]" +reveal_type(f(g)) # N: Revealed type is "tuple[builtins.str, builtins.int]" [builtins fixtures/list.pyi] [case testCallableInferenceAgainstCallablePosOnlyVsNamed] @@ -3679,7 +3679,7 @@ class Call(Protocol[T]): 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]" \ +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]" [builtins fixtures/list.pyi] @@ -3696,7 +3696,7 @@ class Call(Protocol[T]): 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]" \ +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]" [builtins fixtures/list.pyi] @@ -3713,7 +3713,7 @@ class Call(Protocol[T]): 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]" \ +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]" [builtins fixtures/list.pyi] @@ -3730,7 +3730,7 @@ class Call(Protocol[T]): 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]" \ +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]" [builtins fixtures/list.pyi] @@ -3873,7 +3873,7 @@ def a2(check: bool, a: B[str]) -> None: reveal_type(a if check else {}) # N: Revealed type is "builtins.dict[builtins.str, builtins.str]" def a3() -> None: - a = {} # E: Need type annotation for "a" (hint: "a: Dict[, ] = ...") + a = {} # E: Need type annotation for "a" (hint: "a: dict[, ] = ...") b = {1: {}} # E: Need type annotation for "b" c = {1: {}, 2: {"key": {}}} # E: Need type annotation for "c" reveal_type(a) # N: Revealed type is "builtins.dict[Any, Any]" @@ -3893,7 +3893,7 @@ foo = [ (1, ("a", "b")), (2, []), ] -reveal_type(foo) # N: Revealed type is "builtins.list[Tuple[builtins.int, typing.Sequence[builtins.str]]]" +reveal_type(foo) # N: Revealed type is "builtins.list[tuple[builtins.int, typing.Sequence[builtins.str]]]" [builtins fixtures/tuple.pyi] [case testForLoopIndexVaribaleNarrowing1] diff --git a/test-data/unit/check-inline-config.test b/test-data/unit/check-inline-config.test index c81dcac94afd..8a306b1dfac0 100644 --- a/test-data/unit/check-inline-config.test +++ b/test-data/unit/check-inline-config.test @@ -61,7 +61,7 @@ import a [file a.py] # mypy: allow-any-generics, disallow-untyped-globals -x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") +x = [] # E: Need type annotation for "x" (hint: "x: list[] = ...") from typing import List def foo() -> List: diff --git a/test-data/unit/check-isinstance.test b/test-data/unit/check-isinstance.test index 058db1ea8197..fe08d2cfc699 100644 --- a/test-data/unit/check-isinstance.test +++ b/test-data/unit/check-isinstance.test @@ -423,16 +423,16 @@ def f(x: Union[List[int], List[str], int]) -> None: # type of a? reveal_type(x) # N: Revealed type is "Union[builtins.list[builtins.int], builtins.list[builtins.str]]" - x + 1 # E: Unsupported operand types for + ("List[int]" and "int") \ - # E: Unsupported operand types for + ("List[str]" and "int") \ - # N: Left operand is of type "Union[List[int], List[str]]" + x + 1 # E: Unsupported operand types for + ("list[int]" and "int") \ + # E: Unsupported operand types for + ("list[str]" and "int") \ + # N: Left operand is of type "Union[list[int], list[str]]" else: x[0] # E: Value of type "int" is not indexable x + 1 - x[0] # E: Value of type "Union[List[int], List[str], int]" is not indexable - x + 1 # E: Unsupported operand types for + ("List[int]" and "int") \ - # E: Unsupported operand types for + ("List[str]" and "int") \ - # N: Left operand is of type "Union[List[int], List[str], int]" + x[0] # E: Value of type "Union[list[int], list[str], int]" is not indexable + x + 1 # E: Unsupported operand types for + ("list[int]" and "int") \ + # E: Unsupported operand types for + ("list[str]" and "int") \ + # N: Left operand is of type "Union[list[int], list[str], int]" [builtins fixtures/isinstancelist.pyi] [case testUnionListIsinstance2] @@ -696,12 +696,12 @@ while bool(): else: x + [1] x + 'a' # E: Unsupported operand types for + ("int" and "str") \ - # E: Unsupported operand types for + ("List[int]" and "str") \ - # N: Left operand is of type "Union[int, str, List[int]]" + # E: Unsupported operand types for + ("list[int]" and "str") \ + # N: Left operand is of type "Union[int, str, list[int]]" -x + [1] # E: Unsupported operand types for + ("int" and "List[int]") \ - # E: Unsupported operand types for + ("str" and "List[int]") \ - # N: Left operand is of type "Union[int, str, List[int]]" +x + [1] # E: Unsupported operand types for + ("int" and "list[int]") \ + # E: Unsupported operand types for + ("str" and "list[int]") \ + # N: Left operand is of type "Union[int, str, list[int]]" [builtins fixtures/isinstancelist.pyi] [case testIsInstanceThreeUnion2] @@ -715,10 +715,10 @@ while bool(): x + 'a' break x + [1] - x + 'a' # E: Unsupported operand types for + ("List[int]" and "str") -x + [1] # E: Unsupported operand types for + ("int" and "List[int]") \ - # E: Unsupported operand types for + ("str" and "List[int]") \ - # N: Left operand is of type "Union[int, str, List[int]]" + x + 'a' # E: Unsupported operand types for + ("list[int]" and "str") +x + [1] # E: Unsupported operand types for + ("int" and "list[int]") \ + # E: Unsupported operand types for + ("str" and "list[int]") \ + # N: Left operand is of type "Union[int, str, list[int]]" [builtins fixtures/isinstancelist.pyi] [case testIsInstanceThreeUnion3] @@ -736,9 +736,9 @@ while bool(): break x + [1] # These lines aren't reached because x was an int x + 'a' -x + [1] # E: Unsupported operand types for + ("int" and "List[int]") \ - # E: Unsupported operand types for + ("str" and "List[int]") \ - # N: Left operand is of type "Union[int, str, List[int]]" +x + [1] # E: Unsupported operand types for + ("int" and "list[int]") \ + # E: Unsupported operand types for + ("str" and "list[int]") \ + # N: Left operand is of type "Union[int, str, list[int]]" [builtins fixtures/isinstancelist.pyi] [case testRemovingTypeRepeatedly] @@ -1520,7 +1520,7 @@ class Z(X): pass a: Union[Type[Y], Type[Z]] if issubclass(a, X): - reveal_type(a) # N: Revealed type is "Union[Type[__main__.Y], Type[__main__.Z]]" + reveal_type(a) # N: Revealed type is "Union[type[__main__.Y], type[__main__.Z]]" else: reveal_type(a) # unreachable block [builtins fixtures/isinstancelist.pyi] @@ -1529,20 +1529,20 @@ else: from typing import Union, List, Tuple, Dict, Type def f(x: Union[Type[int], Type[str], Type[List]]) -> None: if issubclass(x, (str, (int,))): - reveal_type(x) # N: Revealed type is "Union[Type[builtins.int], Type[builtins.str]]" + reveal_type(x) # N: Revealed type is "Union[type[builtins.int], type[builtins.str]]" reveal_type(x()) # N: Revealed type is "Union[builtins.int, builtins.str]" x()[1] # E: Value of type "Union[int, str]" is not indexable else: - reveal_type(x) # N: Revealed type is "Type[builtins.list[Any]]" + reveal_type(x) # N: Revealed type is "type[builtins.list[Any]]" reveal_type(x()) # N: Revealed type is "builtins.list[Any]" x()[1] - reveal_type(x) # N: Revealed type is "Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]" + reveal_type(x) # N: Revealed type is "Union[type[builtins.int], type[builtins.str], type[builtins.list[Any]]]" reveal_type(x()) # N: Revealed type is "Union[builtins.int, builtins.str, builtins.list[Any]]" if issubclass(x, (str, (list,))): - reveal_type(x) # N: Revealed type is "Union[Type[builtins.str], Type[builtins.list[Any]]]" + reveal_type(x) # N: Revealed type is "Union[type[builtins.str], type[builtins.list[Any]]]" reveal_type(x()) # N: Revealed type is "Union[builtins.str, builtins.list[Any]]" x()[1] - reveal_type(x) # N: Revealed type is "Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]" + reveal_type(x) # N: Revealed type is "Union[type[builtins.int], type[builtins.str], type[builtins.list[Any]]]" reveal_type(x()) # N: Revealed type is "Union[builtins.int, builtins.str, builtins.list[Any]]" [builtins fixtures/isinstancelist.pyi] @@ -1551,20 +1551,20 @@ from typing import Union, List, Tuple, Dict, Type def f(x: Type[Union[int, str, List]]) -> None: if issubclass(x, (str, (int,))): - reveal_type(x) # N: Revealed type is "Union[Type[builtins.int], Type[builtins.str]]" + reveal_type(x) # N: Revealed type is "Union[type[builtins.int], type[builtins.str]]" reveal_type(x()) # N: Revealed type is "Union[builtins.int, builtins.str]" x()[1] # E: Value of type "Union[int, str]" is not indexable else: - reveal_type(x) # N: Revealed type is "Type[builtins.list[Any]]" + reveal_type(x) # N: Revealed type is "type[builtins.list[Any]]" reveal_type(x()) # N: Revealed type is "builtins.list[Any]" x()[1] - reveal_type(x) # N: Revealed type is "Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]" + reveal_type(x) # N: Revealed type is "Union[type[builtins.int], type[builtins.str], type[builtins.list[Any]]]" reveal_type(x()) # N: Revealed type is "Union[builtins.int, builtins.str, builtins.list[Any]]" if issubclass(x, (str, (list,))): - reveal_type(x) # N: Revealed type is "Union[Type[builtins.str], Type[builtins.list[Any]]]" + reveal_type(x) # N: Revealed type is "Union[type[builtins.str], type[builtins.list[Any]]]" reveal_type(x()) # N: Revealed type is "Union[builtins.str, builtins.list[Any]]" x()[1] - reveal_type(x) # N: Revealed type is "Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]" + reveal_type(x) # N: Revealed type is "Union[type[builtins.int], type[builtins.str], type[builtins.list[Any]]]" reveal_type(x()) # N: Revealed type is "Union[builtins.int, builtins.str, builtins.list[Any]]" [builtins fixtures/isinstancelist.pyi] @@ -1572,23 +1572,23 @@ def f(x: Type[Union[int, str, List]]) -> None: from typing import Union, List, Tuple, Dict, Type def f(x: Type[Union[int, str, List]]) -> None: - reveal_type(x) # N: Revealed type is "Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]" + reveal_type(x) # N: Revealed type is "Union[type[builtins.int], type[builtins.str], type[builtins.list[Any]]]" reveal_type(x()) # N: Revealed type is "Union[builtins.int, builtins.str, builtins.list[Any]]" if issubclass(x, (str, (int,))): - reveal_type(x) # N: Revealed type is "Union[Type[builtins.int], Type[builtins.str]]" + reveal_type(x) # N: Revealed type is "Union[type[builtins.int], type[builtins.str]]" reveal_type(x()) # N: Revealed type is "Union[builtins.int, builtins.str]" x()[1] # E: Value of type "Union[int, str]" is not indexable else: - reveal_type(x) # N: Revealed type is "Type[builtins.list[Any]]" + reveal_type(x) # N: Revealed type is "type[builtins.list[Any]]" reveal_type(x()) # N: Revealed type is "builtins.list[Any]" x()[1] - reveal_type(x) # N: Revealed type is "Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]" + reveal_type(x) # N: Revealed type is "Union[type[builtins.int], type[builtins.str], type[builtins.list[Any]]]" reveal_type(x()) # N: Revealed type is "Union[builtins.int, builtins.str, builtins.list[Any]]" if issubclass(x, (str, (list,))): - reveal_type(x) # N: Revealed type is "Union[Type[builtins.str], Type[builtins.list[Any]]]" + reveal_type(x) # N: Revealed type is "Union[type[builtins.str], type[builtins.list[Any]]]" reveal_type(x()) # N: Revealed type is "Union[builtins.str, builtins.list[Any]]" x()[1] - reveal_type(x) # N: Revealed type is "Union[Type[builtins.int], Type[builtins.str], Type[builtins.list[Any]]]" + reveal_type(x) # N: Revealed type is "Union[type[builtins.int], type[builtins.str], type[builtins.list[Any]]]" reveal_type(x()) # N: Revealed type is "Union[builtins.int, builtins.str, builtins.list[Any]]" [builtins fixtures/isinstancelist.pyi] @@ -1603,7 +1603,7 @@ class GoblinAmbusher(Goblin): def test_issubclass(cls: Type[Goblin]) -> None: if issubclass(cls, GoblinAmbusher): - reveal_type(cls) # N: Revealed type is "Type[__main__.GoblinAmbusher]" + reveal_type(cls) # N: Revealed type is "type[__main__.GoblinAmbusher]" cls.level cls.job ga = cls() @@ -1611,9 +1611,9 @@ def test_issubclass(cls: Type[Goblin]) -> None: ga.job ga.job = "Warrior" # E: Cannot assign to class variable "job" via instance else: - reveal_type(cls) # N: Revealed type is "Type[__main__.Goblin]" + reveal_type(cls) # N: Revealed type is "type[__main__.Goblin]" cls.level - cls.job # E: "Type[Goblin]" has no attribute "job" + cls.job # E: "type[Goblin]" has no attribute "job" g = cls() g.level = 15 g.job # E: "Goblin" has no attribute "job" @@ -1632,14 +1632,14 @@ class GoblinAmbusher(Goblin): def test_issubclass(cls: Type[Mob]) -> None: if issubclass(cls, Goblin): - reveal_type(cls) # N: Revealed type is "Type[__main__.Goblin]" + reveal_type(cls) # N: Revealed type is "type[__main__.Goblin]" cls.level - cls.job # E: "Type[Goblin]" has no attribute "job" + cls.job # E: "type[Goblin]" has no attribute "job" g = cls() g.level = 15 g.job # E: "Goblin" has no attribute "job" if issubclass(cls, GoblinAmbusher): - reveal_type(cls) # N: Revealed type is "Type[__main__.GoblinAmbusher]" + reveal_type(cls) # N: Revealed type is "type[__main__.GoblinAmbusher]" cls.level cls.job g = cls() @@ -1647,14 +1647,14 @@ def test_issubclass(cls: Type[Mob]) -> None: g.job g.job = 'Warrior' # E: Cannot assign to class variable "job" via instance else: - reveal_type(cls) # N: Revealed type is "Type[__main__.Mob]" - cls.job # E: "Type[Mob]" has no attribute "job" - cls.level # E: "Type[Mob]" has no attribute "level" + reveal_type(cls) # N: Revealed type is "type[__main__.Mob]" + cls.job # E: "type[Mob]" has no attribute "job" + cls.level # E: "type[Mob]" has no attribute "level" m = cls() m.level = 15 # E: "Mob" has no attribute "level" m.job # E: "Mob" has no attribute "job" if issubclass(cls, GoblinAmbusher): - reveal_type(cls) # N: Revealed type is "Type[__main__.GoblinAmbusher]" + reveal_type(cls) # N: Revealed type is "type[__main__.GoblinAmbusher]" cls.job cls.level ga = cls() @@ -1663,7 +1663,7 @@ def test_issubclass(cls: Type[Mob]) -> None: ga.job = 'Warrior' # E: Cannot assign to class variable "job" via instance if issubclass(cls, GoblinAmbusher): - reveal_type(cls) # N: Revealed type is "Type[__main__.GoblinAmbusher]" + reveal_type(cls) # N: Revealed type is "type[__main__.GoblinAmbusher]" cls.level cls.job ga = cls() @@ -1688,29 +1688,29 @@ class GoblinDigger(Goblin): def test_issubclass(cls: Type[Mob]) -> None: if issubclass(cls, (Goblin, GoblinAmbusher)): - reveal_type(cls) # N: Revealed type is "Type[__main__.Goblin]" + reveal_type(cls) # N: Revealed type is "type[__main__.Goblin]" cls.level - cls.job # E: "Type[Goblin]" has no attribute "job" + cls.job # E: "type[Goblin]" has no attribute "job" g = cls() g.level = 15 g.job # E: "Goblin" has no attribute "job" if issubclass(cls, GoblinAmbusher): cls.level - reveal_type(cls) # N: Revealed type is "Type[__main__.GoblinAmbusher]" + reveal_type(cls) # N: Revealed type is "type[__main__.GoblinAmbusher]" cls.job ga = cls() ga.level = 15 ga.job ga.job = "Warrior" # E: Cannot assign to class variable "job" via instance else: - reveal_type(cls) # N: Revealed type is "Type[__main__.Mob]" - cls.job # E: "Type[Mob]" has no attribute "job" - cls.level # E: "Type[Mob]" has no attribute "level" + reveal_type(cls) # N: Revealed type is "type[__main__.Mob]" + cls.job # E: "type[Mob]" has no attribute "job" + cls.level # E: "type[Mob]" has no attribute "level" m = cls() m.level = 15 # E: "Mob" has no attribute "level" m.job # E: "Mob" has no attribute "job" if issubclass(cls, GoblinAmbusher): - reveal_type(cls) # N: Revealed type is "Type[__main__.GoblinAmbusher]" + reveal_type(cls) # N: Revealed type is "type[__main__.GoblinAmbusher]" cls.job cls.level ga = cls() @@ -1719,7 +1719,7 @@ def test_issubclass(cls: Type[Mob]) -> None: ga.job = "Warrior" # E: Cannot assign to class variable "job" via instance if issubclass(cls, (GoblinDigger, GoblinAmbusher)): - reveal_type(cls) # N: Revealed type is "Union[Type[__main__.GoblinDigger], Type[__main__.GoblinAmbusher]]" + reveal_type(cls) # N: Revealed type is "Union[type[__main__.GoblinDigger], type[__main__.GoblinAmbusher]]" cls.level cls.job g = cls() @@ -1736,14 +1736,14 @@ class MyIntList(List[int]): pass def f(cls: Type[object]) -> None: if issubclass(cls, MyList): - reveal_type(cls) # N: Revealed type is "Type[__main__.MyList]" + reveal_type(cls) # N: Revealed type is "type[__main__.MyList]" cls()[0] else: - reveal_type(cls) # N: Revealed type is "Type[builtins.object]" + reveal_type(cls) # N: Revealed type is "type[builtins.object]" cls()[0] # E: Value of type "object" is not indexable if issubclass(cls, MyIntList): - reveal_type(cls) # N: Revealed type is "Type[__main__.MyIntList]" + reveal_type(cls) # N: Revealed type is "type[__main__.MyIntList]" cls()[0] + 1 [builtins fixtures/isinstancelist.pyi] @@ -1795,7 +1795,7 @@ class Bar: ... fm: FooMetaclass reveal_type(fm) # N: Revealed type is "__main__.FooMetaclass" if issubclass(fm, Foo): - reveal_type(fm) # N: Revealed type is "Type[__main__.Foo]" + reveal_type(fm) # N: Revealed type is "type[__main__.Foo]" if issubclass(fm, Bar): reveal_type(fm) # N: Revealed type is "None" [builtins fixtures/isinstance.pyi] @@ -1810,11 +1810,11 @@ class Baz: ... fm: FooMetaclass reveal_type(fm) # N: Revealed type is "__main__.FooMetaclass" if issubclass(fm, Foo): - reveal_type(fm) # N: Revealed type is "Type[__main__.Foo]" + reveal_type(fm) # N: Revealed type is "type[__main__.Foo]" if issubclass(fm, Bar): - reveal_type(fm) # N: Revealed type is "Type[__main__.Bar]" + reveal_type(fm) # N: Revealed type is "type[__main__.Bar]" if issubclass(fm, Baz): - reveal_type(fm) # N: Revealed type is "Type[__main__.Baz]" + reveal_type(fm) # N: Revealed type is "type[__main__.Baz]" [builtins fixtures/isinstance.pyi] [case testIsinstanceAndNarrowTypeVariable] @@ -1861,10 +1861,10 @@ def f(x: T) -> T: from typing import Type def f(x: Type[int]) -> None: if isinstance(x, type): - reveal_type(x) # N: Revealed type is "Type[builtins.int]" + reveal_type(x) # N: Revealed type is "type[builtins.int]" else: reveal_type(x) # Unreachable - reveal_type(x) # N: Revealed type is "Type[builtins.int]" + reveal_type(x) # N: Revealed type is "type[builtins.int]" [builtins fixtures/isinstance.pyi] [case testIsinstanceVariableSubstitution] @@ -1899,15 +1899,15 @@ from typing import Type issubclass() # E: Missing positional arguments "x", "t" in call to "issubclass" y: Type[object] if issubclass(): # E: Missing positional arguments "x", "t" in call to "issubclass" - reveal_type(y) # N: Revealed type is "Type[builtins.object]" + reveal_type(y) # N: Revealed type is "type[builtins.object]" if issubclass(y): # E: Missing positional argument "t" in call to "issubclass" - reveal_type(y) # N: Revealed type is "Type[builtins.object]" + reveal_type(y) # N: Revealed type is "type[builtins.object]" [builtins fixtures/isinstancelist.pyi] [case testIsInstanceTooManyArgs] isinstance(1, 1, 1) # E: Too many arguments for "isinstance" \ - # E: Argument 2 to "isinstance" has incompatible type "int"; expected "Union[type, Tuple[Any, ...]]" + # E: Argument 2 to "isinstance" has incompatible type "int"; expected "Union[type, tuple[Any, ...]]" x: object if isinstance(x, str, 1): # E: Too many arguments for "isinstance" reveal_type(x) # N: Revealed type is "builtins.object" @@ -2291,7 +2291,7 @@ def bar(x: Union[List[str], List[int], None]) -> None: from typing import Union, List, Tuple def f(var: Union[List[str], Tuple[str, str], str]) -> None: - reveal_type(var) # N: Revealed type is "Union[builtins.list[builtins.str], Tuple[builtins.str, builtins.str], builtins.str]" + reveal_type(var) # N: Revealed type is "Union[builtins.list[builtins.str], tuple[builtins.str, builtins.str], builtins.str]" if isinstance(var, (list, *(str, int))): reveal_type(var) # N: Revealed type is "Union[builtins.list[builtins.str], builtins.str]" [builtins fixtures/isinstancelist.pyi] @@ -2638,13 +2638,13 @@ class C: x: Type[A] if issubclass(x, B): - reveal_type(x) # N: Revealed type is "Type[__main__.]" + reveal_type(x) # N: Revealed type is "type[__main__.]" if issubclass(x, C): # E: Subclass of "A", "B", and "C" cannot exist: would have incompatible method signatures reveal_type(x) # E: Statement is unreachable else: - reveal_type(x) # N: Revealed type is "Type[__main__.]" + reveal_type(x) # N: Revealed type is "type[__main__.]" else: - reveal_type(x) # N: Revealed type is "Type[__main__.A]" + reveal_type(x) # N: Revealed type is "type[__main__.A]" [builtins fixtures/isinstance.pyi] [case testTypeEqualsCheck] diff --git a/test-data/unit/check-kwargs.test b/test-data/unit/check-kwargs.test index 1418f9c3d184..689553445e9d 100644 --- a/test-data/unit/check-kwargs.test +++ b/test-data/unit/check-kwargs.test @@ -263,8 +263,8 @@ f(A(), z=A()) # E: Unexpected keyword argument "z" for "f" from typing import Dict, Any def f( **kwargs: 'A') -> None: d1 = kwargs # type: Dict[str, A] - d2 = kwargs # type: Dict[A, Any] # E: Incompatible types in assignment (expression has type "Dict[str, A]", variable has type "Dict[A, Any]") - d3 = kwargs # type: Dict[Any, str] # E: Incompatible types in assignment (expression has type "Dict[str, A]", variable has type "Dict[Any, str]") + d2 = kwargs # type: Dict[A, Any] # E: Incompatible types in assignment (expression has type "dict[str, A]", variable has type "dict[A, Any]") + d3 = kwargs # type: Dict[Any, str] # E: Incompatible types in assignment (expression has type "dict[str, A]", variable has type "dict[Any, str]") class A: pass [builtins fixtures/dict.pyi] [out] @@ -274,7 +274,7 @@ from typing import Dict, Any def f(**kwargs) -> None: d1 = kwargs # type: Dict[str, A] d2 = kwargs # type: Dict[str, str] - d3 = kwargs # type: Dict[A, Any] # E: Incompatible types in assignment (expression has type "Dict[str, Any]", variable has type "Dict[A, Any]") + d3 = kwargs # type: Dict[A, Any] # E: Incompatible types in assignment (expression has type "dict[str, Any]", variable has type "dict[A, Any]") class A: pass [builtins fixtures/dict.pyi] [out] @@ -301,9 +301,9 @@ d: Dict[str, A] f(**d) f(x=A(), **d) d2: Dict[str, B] -f(**d2) # E: Argument 1 to "f" has incompatible type "**Dict[str, B]"; expected "A" -f(x=A(), **d2) # E: Argument 2 to "f" has incompatible type "**Dict[str, B]"; expected "A" -f(**{'x': B()}) # E: Argument 1 to "f" has incompatible type "**Dict[str, B]"; expected "A" +f(**d2) # E: Argument 1 to "f" has incompatible type "**dict[str, B]"; expected "A" +f(x=A(), **d2) # E: Argument 2 to "f" has incompatible type "**dict[str, B]"; expected "A" +f(**{'x': B()}) # E: Argument 1 to "f" has incompatible type "**dict[str, B]"; expected "A" [builtins fixtures/dict.pyi] [case testKwargsAllowedInDunderCall] @@ -369,7 +369,7 @@ def f(a: 'A', b: 'B') -> None: pass d: Dict[str, Any] f(**d) d2: Dict[str, A] -f(**d2) # E: Argument 1 to "f" has incompatible type "**Dict[str, A]"; expected "B" +f(**d2) # E: Argument 1 to "f" has incompatible type "**dict[str, A]"; expected "B" class A: pass class B: pass [builtins fixtures/dict.pyi] @@ -438,15 +438,15 @@ def f(a: int) -> None: pass s = ('',) -f(*s) # E: Argument 1 to "f" has incompatible type "*Tuple[str]"; expected "int" +f(*s) # E: Argument 1 to "f" has incompatible type "*tuple[str]"; expected "int" a = {'': 0} -f(a) # E: Argument 1 to "f" has incompatible type "Dict[str, int]"; expected "int" +f(a) # E: Argument 1 to "f" has incompatible type "dict[str, int]"; expected "int" f(**a) # okay b = {'': ''} -f(b) # E: Argument 1 to "f" has incompatible type "Dict[str, str]"; expected "int" -f(**b) # E: Argument 1 to "f" has incompatible type "**Dict[str, str]"; expected "int" +f(b) # E: Argument 1 to "f" has incompatible type "dict[str, str]"; expected "int" +f(**b) # E: Argument 1 to "f" has incompatible type "**dict[str, str]"; expected "int" c = {0: 0} f(**c) # E: Keywords must be strings @@ -491,7 +491,7 @@ def g(arg: int = 0, **kwargs: object) -> None: d = {} # type: Dict[str, object] f(**d) -g(**d) # E: Argument 1 to "g" has incompatible type "**Dict[str, object]"; expected "int" +g(**d) # E: Argument 1 to "g" has incompatible type "**dict[str, object]"; expected "int" m = {} # type: Mapping[str, object] f(**m) @@ -565,5 +565,5 @@ main:36: error: Argument 1 to "foo" has incompatible type "**A[str, str]"; expec main:37: error: Argument 1 to "foo" has incompatible type "**B[str, str]"; expected "float" main:38: error: Argument after ** must be a mapping, not "C[str, float]" main:39: error: Argument after ** must be a mapping, not "D" -main:41: error: Argument 1 to "foo" has incompatible type "**Dict[str, str]"; expected "float" +main:41: error: Argument 1 to "foo" has incompatible type "**dict[str, str]"; expected "float" [builtins fixtures/dict.pyi] diff --git a/test-data/unit/check-literal.test b/test-data/unit/check-literal.test index f36eff28f33f..d91b257b0096 100644 --- a/test-data/unit/check-literal.test +++ b/test-data/unit/check-literal.test @@ -70,9 +70,9 @@ def foo(x: Tuple[1]) -> None: ... # E: Invalid type: try using Literal[1] inst y: Tuple[Literal[2]] def bar(x: Tuple[Literal[2]]) -> None: ... -reveal_type(x) # N: Revealed type is "Tuple[Any]" -reveal_type(y) # N: Revealed type is "Tuple[Literal[2]]" -reveal_type(bar) # N: Revealed type is "def (x: Tuple[Literal[2]])" +reveal_type(x) # N: Revealed type is "tuple[Any]" +reveal_type(y) # N: Revealed type is "tuple[Literal[2]]" +reveal_type(bar) # N: Revealed type is "def (x: tuple[Literal[2]])" [builtins fixtures/tuple.pyi] [out] @@ -88,9 +88,9 @@ y = None # type: Optional[Tuple[Literal[2]]] def bar(x): # type: (Tuple[Literal[2]]) -> None pass -reveal_type(x) # N: Revealed type is "Union[Tuple[Any], None]" -reveal_type(y) # N: Revealed type is "Union[Tuple[Literal[2]], None]" -reveal_type(bar) # N: Revealed type is "def (x: Tuple[Literal[2]])" +reveal_type(x) # N: Revealed type is "Union[tuple[Any], None]" +reveal_type(y) # N: Revealed type is "Union[tuple[Literal[2]], None]" +reveal_type(bar) # N: Revealed type is "def (x: tuple[Literal[2]])" [builtins fixtures/tuple.pyi] [out] @@ -946,12 +946,12 @@ def bar(x: Sequence[Literal[1, 2]]) -> None: pass a: List[Literal[1]] b: List[Literal[1, 2, 3]] -foo(a) # E: Argument 1 to "foo" has incompatible type "List[Literal[1]]"; expected "List[Literal[1, 2]]" \ +foo(a) # E: Argument 1 to "foo" has incompatible type "list[Literal[1]]"; expected "list[Literal[1, 2]]" \ # N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \ # N: Consider using "Sequence" instead, which is covariant -foo(b) # E: Argument 1 to "foo" has incompatible type "List[Literal[1, 2, 3]]"; expected "List[Literal[1, 2]]" +foo(b) # E: Argument 1 to "foo" has incompatible type "list[Literal[1, 2, 3]]"; expected "list[Literal[1, 2]]" bar(a) -bar(b) # E: Argument 1 to "bar" has incompatible type "List[Literal[1, 2, 3]]"; expected "Sequence[Literal[1, 2]]" +bar(b) # E: Argument 1 to "bar" has incompatible type "list[Literal[1, 2, 3]]"; expected "Sequence[Literal[1, 2]]" [builtins fixtures/list.pyi] [out] @@ -1186,10 +1186,10 @@ from typing import Literal, Tuple a: Tuple[Literal[1], Literal[2]] = (1, 2) b: Tuple[int, Literal[1, 2], Literal[3], Tuple[Literal["foo"]]] = (1, 2, 3, ("foo",)) -c: Tuple[Literal[1], Literal[2]] = (2, 1) # E: Incompatible types in assignment (expression has type "Tuple[Literal[2], Literal[1]]", variable has type "Tuple[Literal[1], Literal[2]]") +c: Tuple[Literal[1], Literal[2]] = (2, 1) # E: Incompatible types in assignment (expression has type "tuple[Literal[2], Literal[1]]", variable has type "tuple[Literal[1], Literal[2]]") d = (1, 2) -reveal_type(d) # N: Revealed type is "Tuple[builtins.int, builtins.int]" +reveal_type(d) # N: Revealed type is "tuple[builtins.int, builtins.int]" [builtins fixtures/tuple.pyi] [out] @@ -1477,13 +1477,13 @@ Alias = Literal[3] isinstance(3, Literal[3]) # E: Cannot use isinstance() with Literal type isinstance(3, Alias) # E: Cannot use isinstance() with Literal type \ - # E: Argument 2 to "isinstance" has incompatible type ""; expected "Union[type, Tuple[Any, ...]]" + # E: Argument 2 to "isinstance" has incompatible type ""; expected "Union[type, tuple[Any, ...]]" isinstance(3, Renamed[3]) # E: Cannot use isinstance() with Literal type isinstance(3, indirect.Literal[3]) # E: Cannot use isinstance() with Literal type issubclass(int, Literal[3]) # E: Cannot use issubclass() with Literal type issubclass(int, Alias) # E: Cannot use issubclass() with Literal type \ - # E: Argument 2 to "issubclass" has incompatible type ""; expected "Union[type, Tuple[Any, ...]]" + # E: Argument 2 to "issubclass" has incompatible type ""; expected "Union[type, tuple[Any, ...]]" issubclass(int, Renamed[3]) # E: Cannot use issubclass() with Literal type issubclass(int, indirect.Literal[3]) # E: Cannot use issubclass() with Literal type [builtins fixtures/isinstancelist.pyi] @@ -1842,8 +1842,8 @@ reveal_type(tup1[idx3]) # N: Revealed type is "__main__.D" reveal_type(tup1[idx4]) # N: Revealed type is "__main__.E" reveal_type(tup1[idx_neg1]) # N: Revealed type is "__main__.E" tup1[idx5] # E: Tuple index out of range -reveal_type(tup1[idx2:idx4]) # N: Revealed type is "Tuple[Union[__main__.C, None], __main__.D]" -reveal_type(tup1[::idx2]) # N: Revealed type is "Tuple[__main__.A, Union[__main__.C, None], __main__.E]" +reveal_type(tup1[idx2:idx4]) # N: Revealed type is "tuple[Union[__main__.C, None], __main__.D]" +reveal_type(tup1[::idx2]) # N: Revealed type is "tuple[__main__.A, Union[__main__.C, None], __main__.E]" if tup1[idx2] is not None: reveal_type(tup1[idx2]) # N: Revealed type is "Union[__main__.C, None]" if tup1[idx_final] is not None: @@ -1858,9 +1858,9 @@ reveal_type(tup2[idx3]) # N: Revealed type is "__main__.D" reveal_type(tup2[idx4]) # N: Revealed type is "__main__.E" reveal_type(tup2[idx_neg1]) # N: Revealed type is "__main__.E" tup2[idx5] # E: Tuple index out of range -reveal_type(tup2[idx2:idx4]) # N: Revealed type is "Tuple[__main__.C, __main__.D]" -reveal_type(tup2[::idx2]) # N: Revealed type is "Tuple[__main__.A, __main__.C, __main__.E]" -tup3: Tup2Class = tup2[:] # E: Incompatible types in assignment (expression has type "Tuple[A, B, C, D, E]", variable has type "Tup2Class") +reveal_type(tup2[idx2:idx4]) # N: Revealed type is "tuple[__main__.C, __main__.D]" +reveal_type(tup2[::idx2]) # N: Revealed type is "tuple[__main__.A, __main__.C, __main__.E]" +tup3: Tup2Class = tup2[:] # E: Incompatible types in assignment (expression has type "tuple[A, B, C, D, E]", variable has type "Tup2Class") [builtins fixtures/slice.pyi] [case testLiteralIntelligentIndexingTypedDict] @@ -1956,13 +1956,13 @@ Tup2Class = NamedTuple('Tup2Class', [('a', A), ('b', B), ('c', C), ('d', D), ('e tup2: Tup2Class reveal_type(tup1[idx1]) # N: Revealed type is "Union[__main__.B, __main__.C]" -reveal_type(tup1[idx1:idx2]) # N: Revealed type is "Union[Tuple[__main__.B, __main__.C], Tuple[__main__.B, __main__.C, __main__.D], Tuple[__main__.C], Tuple[__main__.C, __main__.D]]" -reveal_type(tup1[0::idx1]) # N: Revealed type is "Union[Tuple[__main__.A, __main__.B, __main__.C, __main__.D, __main__.E], Tuple[__main__.A, __main__.C, __main__.E]]" +reveal_type(tup1[idx1:idx2]) # N: Revealed type is "Union[tuple[__main__.B, __main__.C], tuple[__main__.B, __main__.C, __main__.D], tuple[__main__.C], tuple[__main__.C, __main__.D]]" +reveal_type(tup1[0::idx1]) # N: Revealed type is "Union[tuple[__main__.A, __main__.B, __main__.C, __main__.D, __main__.E], tuple[__main__.A, __main__.C, __main__.E]]" tup1[idx_bad] # E: Tuple index out of range reveal_type(tup2[idx1]) # N: Revealed type is "Union[__main__.B, __main__.C]" -reveal_type(tup2[idx1:idx2]) # N: Revealed type is "Union[Tuple[__main__.B, __main__.C], Tuple[__main__.B, __main__.C, __main__.D], Tuple[__main__.C], Tuple[__main__.C, __main__.D]]" -reveal_type(tup2[0::idx1]) # N: Revealed type is "Union[Tuple[__main__.A, __main__.B, __main__.C, __main__.D, __main__.E], Tuple[__main__.A, __main__.C, __main__.E]]" +reveal_type(tup2[idx1:idx2]) # N: Revealed type is "Union[tuple[__main__.B, __main__.C], tuple[__main__.B, __main__.C, __main__.D], tuple[__main__.C], tuple[__main__.C, __main__.D]]" +reveal_type(tup2[0::idx1]) # N: Revealed type is "Union[tuple[__main__.A, __main__.B, __main__.C, __main__.D, __main__.E], tuple[__main__.A, __main__.C, __main__.E]]" tup2[idx_bad] # E: Tuple index out of range [builtins fixtures/slice.pyi] [out] @@ -2228,7 +2228,7 @@ var1: Final = [0, None] var2: Final = (0, None) reveal_type(var1) # N: Revealed type is "builtins.list[Union[builtins.int, None]]" -reveal_type(var2) # N: Revealed type is "Tuple[Literal[0]?, None]" +reveal_type(var2) # N: Revealed type is "tuple[Literal[0]?, None]" [builtins fixtures/tuple.pyi] [case testLiteralFinalErasureInMutableDatastructures2] @@ -2289,7 +2289,7 @@ def force1(x: Literal[1]) -> None: pass def force2(x: Tuple[Literal[1], Literal[2]]) -> None: pass reveal_type(a) # N: Revealed type is "Literal[1]?" -reveal_type(b) # N: Revealed type is "Tuple[Literal[1]?, Literal[2]?]" +reveal_type(b) # N: Revealed type is "tuple[Literal[1]?, Literal[2]?]" force1(a) # ok force2(b) # ok @@ -2308,7 +2308,7 @@ def force1(x: List[Literal[1]]) -> None: pass def force2(x: Literal[1]) -> None: pass reveal_type(implicit) # N: Revealed type is "builtins.list[builtins.int]" -force1(reveal_type(implicit)) # E: Argument 1 to "force1" has incompatible type "List[int]"; expected "List[Literal[1]]" \ +force1(reveal_type(implicit)) # E: Argument 1 to "force1" has incompatible type "list[int]"; expected "list[Literal[1]]" \ # N: Revealed type is "builtins.list[builtins.int]" force2(reveal_type(implicit[0])) # E: Argument 1 to "force2" has incompatible type "int"; expected "Literal[1]" \ # N: Revealed type is "builtins.int" @@ -2318,7 +2318,7 @@ force1(reveal_type(explicit)) # N: Revealed type is "builtins.list[Literal[1] force2(reveal_type(explicit[0])) # N: Revealed type is "Literal[1]" reveal_type(direct) # N: Revealed type is "builtins.list[builtins.int]" -force1(reveal_type(direct)) # E: Argument 1 to "force1" has incompatible type "List[int]"; expected "List[Literal[1]]" \ +force1(reveal_type(direct)) # E: Argument 1 to "force1" has incompatible type "list[int]"; expected "list[Literal[1]]" \ # N: Revealed type is "builtins.list[builtins.int]" force2(reveal_type(direct[0])) # E: Argument 1 to "force2" has incompatible type "int"; expected "Literal[1]" \ # N: Revealed type is "builtins.int" @@ -2876,7 +2876,7 @@ def f() -> Union[Tuple[Literal[True], int], Tuple[Literal[False], str]]: else: return (False, 'oops') -reveal_type(f()) # N: Revealed type is "Union[Tuple[Literal[True], builtins.int], Tuple[Literal[False], builtins.str]]" +reveal_type(f()) # N: Revealed type is "Union[tuple[Literal[True], builtins.int], tuple[Literal[False], builtins.str]]" def does_work() -> Tuple[Literal[1]]: x: Final = (1,) @@ -2888,23 +2888,23 @@ def also_works() -> Tuple[Literal[1]]: def invalid_literal_value() -> Tuple[Literal[1]]: x: Final = (2,) - return x # E: Incompatible return value type (got "Tuple[int]", expected "Tuple[Literal[1]]") + return x # E: Incompatible return value type (got "tuple[int]", expected "tuple[Literal[1]]") def invalid_literal_type() -> Tuple[Literal[1]]: x: Final = (True,) - return x # E: Incompatible return value type (got "Tuple[bool]", expected "Tuple[Literal[1]]") + return x # E: Incompatible return value type (got "tuple[bool]", expected "tuple[Literal[1]]") def incorrect_return1() -> Union[Tuple[Literal[True], int], Tuple[Literal[False], str]]: if x: - return (False, 5) # E: Incompatible return value type (got "Tuple[bool, int]", expected "Union[Tuple[Literal[True], int], Tuple[Literal[False], str]]") + return (False, 5) # E: Incompatible return value type (got "tuple[bool, int]", expected "Union[tuple[Literal[True], int], tuple[Literal[False], str]]") else: - return (True, 'oops') # E: Incompatible return value type (got "Tuple[bool, str]", expected "Union[Tuple[Literal[True], int], Tuple[Literal[False], str]]") + return (True, 'oops') # E: Incompatible return value type (got "tuple[bool, str]", expected "Union[tuple[Literal[True], int], tuple[Literal[False], str]]") def incorrect_return2() -> Union[Tuple[Literal[True], int], Tuple[Literal[False], str]]: if x: - return (bool(), 5) # E: Incompatible return value type (got "Tuple[bool, int]", expected "Union[Tuple[Literal[True], int], Tuple[Literal[False], str]]") + return (bool(), 5) # E: Incompatible return value type (got "tuple[bool, int]", expected "Union[tuple[Literal[True], int], tuple[Literal[False], str]]") else: - return (bool(), 'oops') # E: Incompatible return value type (got "Tuple[bool, str]", expected "Union[Tuple[Literal[True], int], Tuple[Literal[False], str]]") + return (bool(), 'oops') # E: Incompatible return value type (got "tuple[bool, str]", expected "Union[tuple[Literal[True], int], tuple[Literal[False], str]]") [builtins fixtures/bool.pyi] [case testLiteralSubtypeContext] diff --git a/test-data/unit/check-modules.test b/test-data/unit/check-modules.test index 000dae86131d..dcc64f0924c4 100644 --- a/test-data/unit/check-modules.test +++ b/test-data/unit/check-modules.test @@ -423,7 +423,7 @@ import typing __all__ = [1, 2, 3] [builtins fixtures/module_all.pyi] [out] -main:2: error: Type of __all__ must be "Sequence[str]", not "List[int]" +main:2: error: Type of __all__ must be "Sequence[str]", not "list[int]" [case testUnderscoreExportedValuesInImportAll] import typing @@ -666,9 +666,9 @@ import mod X: Type[mod.A] Y: Type[mod.B] from mod import B as X -from mod import A as Y # E: Incompatible import of "Y" (imported name has type "Type[A]", local name has type "Type[B]") +from mod import A as Y # E: Incompatible import of "Y" (imported name has type "type[A]", local name has type "type[B]") -import mod as X # E: Incompatible import of "X" (imported name has type "object", local name has type "Type[A]") +import mod as X # E: Incompatible import of "X" (imported name has type "object", local name has type "type[A]") [file mod.py] class A: ... @@ -1049,7 +1049,7 @@ 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 "z" (imported name has type "Type[b.z]", local name has type "Type[a.z]") +main:2: error: Incompatible import of "z" (imported name has type "type[b.z]", local name has type "type[a.z]") -- Misc diff --git a/test-data/unit/check-namedtuple.test b/test-data/unit/check-namedtuple.test index 13f977a1e463..45de2a9e50ae 100644 --- a/test-data/unit/check-namedtuple.test +++ b/test-data/unit/check-namedtuple.test @@ -305,9 +305,9 @@ t: Tuple[int, str] if int(): b = a # E: Incompatible types in assignment (expression has type "A", variable has type "B") if int(): - a = t # E: Incompatible types in assignment (expression has type "Tuple[int, str]", variable has type "A") + a = t # E: Incompatible types in assignment (expression has type "tuple[int, str]", variable has type "A") if int(): - b = t # E: Incompatible types in assignment (expression has type "Tuple[int, str]", variable has type "B") + b = t # E: Incompatible types in assignment (expression has type "tuple[int, str]", variable has type "B") if int(): t = a if int(): @@ -332,14 +332,14 @@ if int(): if int(): l = [A(1)] if int(): - a = (1,) # E: Incompatible types in assignment (expression has type "Tuple[int]", \ + a = (1,) # E: Incompatible types in assignment (expression has type "tuple[int]", \ variable has type "A") [builtins fixtures/list.pyi] [case testNamedTupleMissingClassAttribute] import collections MyNamedTuple = collections.namedtuple('MyNamedTuple', ['spam', 'eggs']) -MyNamedTuple.x # E: "Type[MyNamedTuple]" has no attribute "x" +MyNamedTuple.x # E: "type[MyNamedTuple]" has no attribute "x" [builtins fixtures/list.pyi] @@ -376,7 +376,7 @@ from collections import namedtuple X = namedtuple('X', ['x', 'y']) x: X -reveal_type(x._replace()) # N: Revealed type is "Tuple[Any, Any, fallback=__main__.X]" +reveal_type(x._replace()) # N: Revealed type is "tuple[Any, Any, fallback=__main__.X]" x._replace(y=5) x._replace(x=3) x._replace(x=3, y=5) @@ -401,7 +401,7 @@ from typing import NamedTuple X = NamedTuple('X', [('x', int), ('y', str)]) x: X -reveal_type(x._replace()) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.X]" +reveal_type(x._replace()) # N: Revealed type is "tuple[builtins.int, builtins.str, fallback=__main__.X]" x._replace(x=5) x._replace(y=5) # E: Argument "y" to "_replace" of "X" has incompatible type "int"; expected "str" [builtins fixtures/tuple.pyi] @@ -410,7 +410,7 @@ x._replace(y=5) # E: Argument "y" to "_replace" of "X" has incompatible type "i from typing import NamedTuple X = NamedTuple('X', [('x', int), ('y', str)]) -reveal_type(X._make([5, 'a'])) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.X]" +reveal_type(X._make([5, 'a'])) # N: Revealed type is "tuple[builtins.int, builtins.str, fallback=__main__.X]" X._make('a b') # E: Argument 1 to "_make" of "X" has incompatible type "str"; expected "Iterable[Any]" -- # FIX: not a proper class method @@ -424,7 +424,7 @@ X._make('a b') # E: Argument 1 to "_make" of "X" has incompatible type "str"; e from typing import NamedTuple X = NamedTuple('X', [('x', int), ('y', str)]) -reveal_type(X._fields) # N: Revealed type is "Tuple[builtins.str, builtins.str]" +reveal_type(X._fields) # N: Revealed type is "tuple[builtins.str, builtins.str]" [builtins fixtures/tuple.pyi] [case testNamedTupleSource] @@ -450,7 +450,7 @@ from typing import NamedTuple X = NamedTuple('X', [('x', int), ('y', str)]) Y = NamedTuple('Y', [('x', int), ('y', str)]) -reveal_type([X(3, 'b'), Y(1, 'a')]) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.str]]" +reveal_type([X(3, 'b'), Y(1, 'a')]) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.str]]" [builtins fixtures/list.pyi] @@ -458,8 +458,8 @@ reveal_type([X(3, 'b'), Y(1, 'a')]) # N: Revealed type is "builtins.list[Tuple[ from typing import NamedTuple, Tuple X = NamedTuple('X', [('x', int), ('y', str)]) -reveal_type([(3, 'b'), X(1, 'a')]) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.str]]" -reveal_type([X(1, 'a'), (3, 'b')]) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.str]]" +reveal_type([(3, 'b'), X(1, 'a')]) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.str]]" +reveal_type([X(1, 'a'), (3, 'b')]) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.str]]" [builtins fixtures/list.pyi] @@ -519,14 +519,14 @@ a = B('').member() [case testNamedTupleSelfTypeReplace] from typing import NamedTuple, TypeVar A = NamedTuple('A', [('x', str)]) -reveal_type(A('hello')._replace(x='')) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.A]" +reveal_type(A('hello')._replace(x='')) # N: Revealed type is "tuple[builtins.str, fallback=__main__.A]" a: A a = A('hello')._replace(x='') class B(A): pass -reveal_type(B('hello')._replace(x='')) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.B]" +reveal_type(B('hello')._replace(x='')) # N: Revealed type is "tuple[builtins.str, fallback=__main__.B]" b: B b = B('hello')._replace(x='') [builtins fixtures/tuple.pyi] @@ -534,13 +534,13 @@ b = B('hello')._replace(x='') [case testNamedTupleSelfTypeMake] from typing import NamedTuple, TypeVar A = NamedTuple('A', [('x', str)]) -reveal_type(A._make([''])) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.A]" +reveal_type(A._make([''])) # N: Revealed type is "tuple[builtins.str, fallback=__main__.A]" a = A._make(['']) # type: A class B(A): pass -reveal_type(B._make([''])) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.B]" +reveal_type(B._make([''])) # N: Revealed type is "tuple[builtins.str, fallback=__main__.B]" b = B._make(['']) # type: B [builtins fixtures/list.pyi] @@ -559,7 +559,7 @@ class C: A = NamedTuple('A', [('x', int)]) def g(self): A = NamedTuple('A', [('y', int)]) -C.A # E: "Type[C]" has no attribute "A" +C.A # E: "type[C]" has no attribute "A" [builtins fixtures/tuple.pyi] [case testNamedTupleInFunction] @@ -603,8 +603,8 @@ def f(x: a.X) -> None: reveal_type(x) [builtins fixtures/tuple.pyi] [out] -tmp/b.py:4: note: Revealed type is "Tuple[Any, fallback=a.X]" -tmp/b.py:6: note: Revealed type is "Tuple[Any, fallback=a.X]" +tmp/b.py:4: note: Revealed type is "tuple[Any, fallback=a.X]" +tmp/b.py:6: note: Revealed type is "tuple[Any, fallback=a.X]" [case testNamedTupleWithImportCycle2] import a @@ -623,8 +623,8 @@ def f(x: a.N) -> None: reveal_type(x) [builtins fixtures/tuple.pyi] [out] -tmp/b.py:4: note: Revealed type is "Tuple[Any, fallback=a.N]" -tmp/b.py:7: note: Revealed type is "Tuple[Any, fallback=a.N]" +tmp/b.py:4: note: Revealed type is "tuple[Any, fallback=a.N]" +tmp/b.py:7: note: Revealed type is "tuple[Any, fallback=a.N]" [case testSimpleSelfReferentialNamedTuple] from typing import NamedTuple @@ -676,7 +676,7 @@ def test() -> None: # N: Recursive types are not allowed at function scope ]) n: Node - reveal_type(n) # N: Revealed type is "Tuple[builtins.str, builtins.tuple[Any, ...], fallback=__main__.Node@4]" + reveal_type(n) # N: Revealed type is "tuple[builtins.str, builtins.tuple[Any, ...], fallback=__main__.Node@4]" [builtins fixtures/tuple.pyi] [case testSelfRefNT2] @@ -693,7 +693,7 @@ def test() -> None: y: int n: A - reveal_type(n) # N: Revealed type is "Tuple[builtins.str, builtins.tuple[Any, ...], fallback=__main__.A@4]" + reveal_type(n) # N: Revealed type is "tuple[builtins.str, builtins.tuple[Any, ...], fallback=__main__.A@4]" [builtins fixtures/tuple.pyi] [case testSelfRefNT3] @@ -711,10 +711,10 @@ def test() -> None: ]) n: B m: A - reveal_type(n.x) # N: Revealed type is "Tuple[Any, builtins.int]" + reveal_type(n.x) # N: Revealed type is "tuple[Any, builtins.int]" reveal_type(m[0]) # N: Revealed type is "builtins.str" lst = [m, n] - reveal_type(lst[0]) # N: Revealed type is "Tuple[builtins.object, builtins.object]" + reveal_type(lst[0]) # N: Revealed type is "tuple[builtins.object, builtins.object]" [builtins fixtures/tuple.pyi] [case testSelfRefNT4] @@ -739,7 +739,7 @@ from typing import NamedTuple def test() -> None: B = NamedTuple('B', [ - ('x', A), # E: Cannot resolve name "A" (possible cyclic definition) \ + ('x', A), # E: Cannot resolve name "A" (possible cyclic definition) \ # N: Recursive types are not allowed at function scope \ # E: Name "A" is used before definition ('y', int), @@ -750,8 +750,8 @@ def test() -> None: ]) n: A def f(m: B) -> None: pass - reveal_type(n) # N: Revealed type is "Tuple[builtins.str, Tuple[Any, builtins.int, fallback=__main__.B@4], fallback=__main__.A@8]" - reveal_type(f) # N: Revealed type is "def (m: Tuple[Any, builtins.int, fallback=__main__.B@4])" + reveal_type(n) # N: Revealed type is "tuple[builtins.str, tuple[Any, builtins.int, fallback=__main__.B@4], fallback=__main__.A@8]" + reveal_type(f) # N: Revealed type is "def (m: tuple[Any, builtins.int, fallback=__main__.B@4])" [builtins fixtures/tuple.pyi] [case testRecursiveNamedTupleInBases] @@ -765,13 +765,13 @@ def test() -> None: class B(NamedTuple('B', [('val', object)])): pass exp: Exp - reveal_type(exp) # N: Revealed type is "Union[Any, Tuple[builtins.object, fallback=__main__.B@6]]" + reveal_type(exp) # N: Revealed type is "Union[Any, tuple[builtins.object, fallback=__main__.B@6]]" if isinstance(exp, A): - reveal_type(exp[0][0]) # N: Revealed type is "Union[Any, Tuple[builtins.object, fallback=__main__.B@6]]" - reveal_type(exp.attr[0]) # N: Revealed type is "Union[Any, Tuple[builtins.object, fallback=__main__.B@6]]" + reveal_type(exp[0][0]) # N: Revealed type is "Union[Any, tuple[builtins.object, fallback=__main__.B@6]]" + reveal_type(exp.attr[0]) # N: Revealed type is "Union[Any, tuple[builtins.object, fallback=__main__.B@6]]" if isinstance(exp, B): reveal_type(exp.val) # N: Revealed type is "builtins.object" - reveal_type(A([B(1), B(2)])) # N: Revealed type is "Tuple[builtins.list[Union[Any, Tuple[builtins.object, fallback=__main__.B@6]]], fallback=__main__.A@5]" + reveal_type(A([B(1), B(2)])) # N: Revealed type is "tuple[builtins.list[Union[Any, tuple[builtins.object, fallback=__main__.B@6]]], fallback=__main__.A@5]" [builtins fixtures/isinstancelist.pyi] [out] @@ -786,7 +786,7 @@ from b import tp x: tp reveal_type(x.x) # N: Revealed type is "builtins.int" -reveal_type(tp) # N: Revealed type is "def (x: builtins.int) -> Tuple[builtins.int, fallback=b.tp]" +reveal_type(tp) # N: Revealed type is "def (x: builtins.int) -> tuple[builtins.int, fallback=b.tp]" tp('x') # E: Argument 1 to "tp" has incompatible type "str"; expected "int" [file b.py] @@ -809,7 +809,7 @@ def test() -> None: pass hc = HelpCommand(subcommands=[]) - reveal_type(hc) # N: Revealed type is "Tuple[builtins.list[Any], fallback=__main__.HelpCommand@7]" + reveal_type(hc) # N: Revealed type is "tuple[builtins.list[Any], fallback=__main__.HelpCommand@7]" [builtins fixtures/list.pyi] [out] @@ -840,7 +840,7 @@ class D(NamedTuple): def f(cls) -> None: pass d: Type[D] -d.g() # E: "Type[D]" has no attribute "g" +d.g() # E: "type[D]" has no attribute "g" d.f() [builtins fixtures/classmethod.pyi] @@ -902,7 +902,7 @@ class Parent(NamedTuple): class Child(Parent): pass -reveal_type(Child.class_method()) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.Child]" +reveal_type(Child.class_method()) # N: Revealed type is "tuple[builtins.str, fallback=__main__.Child]" [builtins fixtures/classmethod.pyi] [case testNamedTupleAsConditionalStrictOptionalDisabled] @@ -942,10 +942,10 @@ class MyTupleB(NamedTuple): field_2: MyBaseTuple u: MyTupleUnion -reveal_type(u.field_1) # N: Revealed type is "typing.Mapping[Tuple[builtins.int, builtins.int, fallback=__main__.MyBaseTuple], builtins.int]" -reveal_type(u.field_2) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.MyBaseTuple]" -reveal_type(u[0]) # N: Revealed type is "typing.Mapping[Tuple[builtins.int, builtins.int, fallback=__main__.MyBaseTuple], builtins.int]" -reveal_type(u[1]) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.MyBaseTuple]" +reveal_type(u.field_1) # N: Revealed type is "typing.Mapping[tuple[builtins.int, builtins.int, fallback=__main__.MyBaseTuple], builtins.int]" +reveal_type(u.field_2) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.MyBaseTuple]" +reveal_type(u[0]) # N: Revealed type is "typing.Mapping[tuple[builtins.int, builtins.int, fallback=__main__.MyBaseTuple], builtins.int]" +reveal_type(u[1]) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.MyBaseTuple]" [builtins fixtures/tuple.pyi] [case testAssignNamedTupleAsAttribute] @@ -965,8 +965,8 @@ from typing import NamedTuple N = NamedTuple('N', []) n: N -reveal_type(N) # N: Revealed type is "def () -> Tuple[(), fallback=__main__.N]" -reveal_type(n) # N: Revealed type is "Tuple[(), fallback=__main__.N]" +reveal_type(N) # N: Revealed type is "def () -> tuple[(), fallback=__main__.N]" +reveal_type(n) # N: Revealed type is "tuple[(), fallback=__main__.N]" [builtins fixtures/tuple.pyi] [case testNamedTupleWrongfile] @@ -1027,11 +1027,11 @@ print_namedtuple(b5) # ok print_namedtuple(b6) # ok print_namedtuple(1) # E: Argument 1 to "print_namedtuple" has incompatible type "int"; expected "NamedTuple" -print_namedtuple(('bar',)) # E: Argument 1 to "print_namedtuple" has incompatible type "Tuple[str]"; expected "NamedTuple" -print_namedtuple((1, 2)) # E: Argument 1 to "print_namedtuple" has incompatible type "Tuple[int, int]"; expected "NamedTuple" -print_namedtuple((b1,)) # E: Argument 1 to "print_namedtuple" has incompatible type "Tuple[Bar]"; expected "NamedTuple" +print_namedtuple(('bar',)) # E: Argument 1 to "print_namedtuple" has incompatible type "tuple[str]"; expected "NamedTuple" +print_namedtuple((1, 2)) # E: Argument 1 to "print_namedtuple" has incompatible type "tuple[int, int]"; expected "NamedTuple" +print_namedtuple((b1,)) # E: Argument 1 to "print_namedtuple" has incompatible type "tuple[Bar]"; expected "NamedTuple" t: Tuple[str, ...] -print_namedtuple(t) # E: Argument 1 to "print_namedtuple" has incompatible type "Tuple[str, ...]"; expected "NamedTuple" +print_namedtuple(t) # E: Argument 1 to "print_namedtuple" has incompatible type "tuple[str, ...]"; expected "NamedTuple" [builtins fixtures/tuple.pyi] [typing fixtures/typing-namedtuple.pyi] @@ -1074,9 +1074,9 @@ def good6() -> NamedTuple: def bad1() -> NamedTuple: return 1 # E: Incompatible return value type (got "int", expected "NamedTuple") def bad2() -> NamedTuple: - return () # E: Incompatible return value type (got "Tuple[()]", expected "NamedTuple") + return () # E: Incompatible return value type (got "tuple[()]", expected "NamedTuple") def bad3() -> NamedTuple: - return (1, 2) # E: Incompatible return value type (got "Tuple[int, int]", expected "NamedTuple") + return (1, 2) # E: Incompatible return value type (got "tuple[int, int]", expected "NamedTuple") [builtins fixtures/tuple.pyi] [typing fixtures/typing-namedtuple.pyi] @@ -1090,14 +1090,14 @@ C = NamedTuple("C", [("x", Literal[True, False])]) T = Tuple[Literal[True, False]] # Was error here: -# Incompatible types in assignment (expression has type "List[C]", variable has type "List[C]") +# Incompatible types in assignment (expression has type "list[C]", variable has type "list[C]") x: List[C] = [C(True)] t: T # Was error here: -# Incompatible types in assignment (expression has type "List[Tuple[bool]]", -# variable has type "List[Tuple[Union[Literal[True], Literal[False]]]]") +# Incompatible types in assignment (expression has type "list[tuple[bool]]", +# variable has type "list[tuple[Union[Literal[True], Literal[False]]]]") y: List[T] = [t] [builtins fixtures/tuple.pyi] [typing fixtures/typing-namedtuple.pyi] @@ -1114,22 +1114,22 @@ class C(NamedTuple): def foo(c: C) -> None: if c: - reveal_type(c) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.C]" + reveal_type(c) # N: Revealed type is "tuple[builtins.int, fallback=__main__.C]" else: - reveal_type(c) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.C]" + reveal_type(c) # N: Revealed type is "tuple[builtins.int, fallback=__main__.C]" def bar(c: C) -> None: if not c: - reveal_type(c) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.C]" + reveal_type(c) # N: Revealed type is "tuple[builtins.int, fallback=__main__.C]" else: - reveal_type(c) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.C]" + reveal_type(c) # N: Revealed type is "tuple[builtins.int, fallback=__main__.C]" class C1(NamedTuple): x: int def foo1(c: C1) -> None: if c: - reveal_type(c) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.C1]" + reveal_type(c) # N: Revealed type is "tuple[builtins.int, fallback=__main__.C1]" else: c # E: Statement is unreachable @@ -1137,7 +1137,7 @@ def bar1(c: C1) -> None: if not c: c # E: Statement is unreachable else: - reveal_type(c) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.C1]" + reveal_type(c) # N: Revealed type is "tuple[builtins.int, fallback=__main__.C1]" [builtins fixtures/tuple.pyi] [typing fixtures/typing-namedtuple.pyi] @@ -1162,7 +1162,7 @@ class One(NamedTuple): bar: int baz: str o: One -reveal_type(o.__match_args__) # N: Revealed type is "Tuple[Literal['bar'], Literal['baz']]" +reveal_type(o.__match_args__) # N: Revealed type is "tuple[Literal['bar'], Literal['baz']]" [builtins fixtures/tuple.pyi] [typing fixtures/typing-namedtuple.pyi] @@ -1202,11 +1202,11 @@ class NT(NamedTuple, Generic[T]): value: T nts: NT[str] -reveal_type(nts) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.NT[builtins.str]]" +reveal_type(nts) # N: Revealed type is "tuple[builtins.int, builtins.str, fallback=__main__.NT[builtins.str]]" reveal_type(nts.value) # N: Revealed type is "builtins.str" nti = NT(key=0, value=0) -reveal_type(nti) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.NT[builtins.int]]" +reveal_type(nti) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.NT[builtins.int]]" reveal_type(nti.value) # N: Revealed type is "builtins.int" NT[str](key=0, value=0) # E: Argument "value" to "NT" has incompatible type "int"; expected "str" @@ -1224,8 +1224,8 @@ class NT(NamedTuple, Generic[T]): Alias = NT[List[T]] an: Alias[str] -reveal_type(an) # N: Revealed type is "Tuple[builtins.int, builtins.list[builtins.str], fallback=__main__.NT[builtins.list[builtins.str]]]" -Alias[str](key=0, value=0) # E: Argument "value" to "NT" has incompatible type "int"; expected "List[str]" +reveal_type(an) # N: Revealed type is "tuple[builtins.int, builtins.list[builtins.str], fallback=__main__.NT[builtins.list[builtins.str]]]" +Alias[str](key=0, value=0) # E: Argument "value" to "NT" has incompatible type "int"; expected "list[str]" [builtins fixtures/tuple.pyi] [typing fixtures/typing-namedtuple.pyi] @@ -1261,7 +1261,7 @@ nts: NT[str] reveal_type(nts.foo()) # N: Revealed type is "builtins.str" nti = NT.from_value(1) -reveal_type(nti) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.NT[builtins.int]]" +reveal_type(nti) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.NT[builtins.int]]" NT[str].from_value(1) # E: Argument 1 to "from_value" of "NT" has incompatible type "int"; expected "str" [builtins fixtures/tuple.pyi] [typing fixtures/typing-namedtuple.pyi] @@ -1279,7 +1279,7 @@ nti: NT[int] def foo(x: Tuple[int, ...]) -> None: ... foo(nti) -foo(nts) # E: Argument 1 to "foo" has incompatible type "NT[str]"; expected "Tuple[int, ...]" +foo(nts) # E: Argument 1 to "foo" has incompatible type "NT[str]"; expected "tuple[int, ...]" [builtins fixtures/tuple.pyi] [typing fixtures/typing-namedtuple.pyi] @@ -1297,10 +1297,10 @@ x: Tuple[int, ...] S = TypeVar("S") def foo(x: S, y: S) -> S: ... -reveal_type(foo(nti, nti)) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.NT[builtins.int]]" +reveal_type(foo(nti, nti)) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.NT[builtins.int]]" -reveal_type(foo(nti, nts)) # N: Revealed type is "Tuple[builtins.int, builtins.object, fallback=__main__.NT[builtins.object]]" -reveal_type(foo(nts, nti)) # N: Revealed type is "Tuple[builtins.int, builtins.object, fallback=__main__.NT[builtins.object]]" +reveal_type(foo(nti, nts)) # N: Revealed type is "tuple[builtins.int, builtins.object, fallback=__main__.NT[builtins.object]]" +reveal_type(foo(nts, nti)) # N: Revealed type is "tuple[builtins.int, builtins.object, fallback=__main__.NT[builtins.object]]" reveal_type(foo(nti, x)) # N: Revealed type is "builtins.tuple[builtins.int, ...]" reveal_type(foo(nts, x)) # N: Revealed type is "builtins.tuple[Union[builtins.int, builtins.str], ...]" @@ -1314,13 +1314,13 @@ from typing import NamedTuple, TypeVar T = TypeVar("T") NT = NamedTuple("NT", [("key", int), ("value", T)]) -reveal_type(NT) # N: Revealed type is "def [T] (key: builtins.int, value: T`1) -> Tuple[builtins.int, T`1, fallback=__main__.NT[T`1]]" +reveal_type(NT) # N: Revealed type is "def [T] (key: builtins.int, value: T`1) -> tuple[builtins.int, T`1, fallback=__main__.NT[T`1]]" nts: NT[str] -reveal_type(nts) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.NT[builtins.str]]" +reveal_type(nts) # N: Revealed type is "tuple[builtins.int, builtins.str, fallback=__main__.NT[builtins.str]]" nti = NT(key=0, value=0) -reveal_type(nti) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.NT[builtins.int]]" +reveal_type(nti) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.NT[builtins.int]]" NT[str](key=0, value=0) # E: Argument "value" to "NT" has incompatible type "int"; expected "str" [builtins fixtures/tuple.pyi] [typing fixtures/typing-namedtuple.pyi] @@ -1362,7 +1362,7 @@ class NT(NamedTuple, Generic[T]): return self._replace() class SNT(NT[int]): ... -reveal_type(SNT("test", 42).meth()) # N: Revealed type is "Tuple[builtins.str, builtins.int, fallback=__main__.SNT]" +reveal_type(SNT("test", 42).meth()) # N: Revealed type is "tuple[builtins.str, builtins.int, fallback=__main__.SNT]" [builtins fixtures/tuple.pyi] [typing fixtures/typing-namedtuple.pyi] @@ -1500,7 +1500,7 @@ def g(x: Union[A, B, str]) -> Union[A, B, str]: if isinstance(x, str): return x else: - reveal_type(x) # N: Revealed type is "Union[Tuple[Tuple[builtins.str, fallback=__main__.AKey], fallback=__main__.A], Tuple[Tuple[builtins.str, fallback=__main__.BKey], fallback=__main__.B]]" + reveal_type(x) # N: Revealed type is "Union[tuple[tuple[builtins.str, fallback=__main__.AKey], fallback=__main__.A], tuple[tuple[builtins.str, fallback=__main__.BKey], fallback=__main__.B]]" return x._replace() # no errors should be raised above. diff --git a/test-data/unit/check-narrowing.test b/test-data/unit/check-narrowing.test index dc2cfd46d9ad..4afed0e3ec86 100644 --- a/test-data/unit/check-narrowing.test +++ b/test-data/unit/check-narrowing.test @@ -53,24 +53,24 @@ else: x3: Union[NamedTuple1, NamedTuple2] if x3.key == "A": - reveal_type(x3) # N: Revealed type is "Tuple[Literal['A'], builtins.int, fallback=__main__.NamedTuple1]" + reveal_type(x3) # N: Revealed type is "tuple[Literal['A'], builtins.int, fallback=__main__.NamedTuple1]" reveal_type(x3.key) # N: Revealed type is "Literal['A']" else: - reveal_type(x3) # N: Revealed type is "Tuple[Literal['B'], builtins.str, fallback=__main__.NamedTuple2]" + reveal_type(x3) # N: Revealed type is "tuple[Literal['B'], builtins.str, fallback=__main__.NamedTuple2]" reveal_type(x3.key) # N: Revealed type is "Literal['B']" if x3[0] == "A": - reveal_type(x3) # N: Revealed type is "Tuple[Literal['A'], builtins.int, fallback=__main__.NamedTuple1]" + reveal_type(x3) # N: Revealed type is "tuple[Literal['A'], builtins.int, fallback=__main__.NamedTuple1]" reveal_type(x3[0]) # N: Revealed type is "Literal['A']" else: - reveal_type(x3) # N: Revealed type is "Tuple[Literal['B'], builtins.str, fallback=__main__.NamedTuple2]" + reveal_type(x3) # N: Revealed type is "tuple[Literal['B'], builtins.str, fallback=__main__.NamedTuple2]" reveal_type(x3[0]) # N: Revealed type is "Literal['B']" x4: Union[Tuple1, Tuple2] if x4[0] == "A": - reveal_type(x4) # N: Revealed type is "Tuple[Literal['A'], builtins.int]" + reveal_type(x4) # N: Revealed type is "tuple[Literal['A'], builtins.int]" reveal_type(x4[0]) # N: Revealed type is "Literal['A']" else: - reveal_type(x4) # N: Revealed type is "Tuple[Literal['B'], builtins.str]" + reveal_type(x4) # N: Revealed type is "tuple[Literal['B'], builtins.str]" reveal_type(x4[0]) # N: Revealed type is "Literal['B']" x5: Union[TypedDict1, TypedDict2] @@ -142,24 +142,24 @@ else: x3: Union[NamedTuple1, NamedTuple2] if x3.key is Key.A: - reveal_type(x3) # N: Revealed type is "Tuple[Literal[__main__.Key.A], builtins.int, fallback=__main__.NamedTuple1]" + reveal_type(x3) # N: Revealed type is "tuple[Literal[__main__.Key.A], builtins.int, fallback=__main__.NamedTuple1]" reveal_type(x3.key) # N: Revealed type is "Literal[__main__.Key.A]" else: - reveal_type(x3) # N: Revealed type is "Tuple[Literal[__main__.Key.B], builtins.str, fallback=__main__.NamedTuple2]" + reveal_type(x3) # N: Revealed type is "tuple[Literal[__main__.Key.B], builtins.str, fallback=__main__.NamedTuple2]" reveal_type(x3.key) # N: Revealed type is "Literal[__main__.Key.B]" if x3[0] is Key.A: - reveal_type(x3) # N: Revealed type is "Tuple[Literal[__main__.Key.A], builtins.int, fallback=__main__.NamedTuple1]" + reveal_type(x3) # N: Revealed type is "tuple[Literal[__main__.Key.A], builtins.int, fallback=__main__.NamedTuple1]" reveal_type(x3[0]) # N: Revealed type is "Literal[__main__.Key.A]" else: - reveal_type(x3) # N: Revealed type is "Tuple[Literal[__main__.Key.B], builtins.str, fallback=__main__.NamedTuple2]" + reveal_type(x3) # N: Revealed type is "tuple[Literal[__main__.Key.B], builtins.str, fallback=__main__.NamedTuple2]" reveal_type(x3[0]) # N: Revealed type is "Literal[__main__.Key.B]" x4: Union[Tuple1, Tuple2] if x4[0] is Key.A: - reveal_type(x4) # N: Revealed type is "Tuple[Literal[__main__.Key.A], builtins.int]" + reveal_type(x4) # N: Revealed type is "tuple[Literal[__main__.Key.A], builtins.int]" reveal_type(x4[0]) # N: Revealed type is "Literal[__main__.Key.A]" else: - reveal_type(x4) # N: Revealed type is "Tuple[Literal[__main__.Key.B], builtins.str]" + reveal_type(x4) # N: Revealed type is "tuple[Literal[__main__.Key.B], builtins.str]" reveal_type(x4[0]) # N: Revealed type is "Literal[__main__.Key.B]" x5: Union[TypedDict1, TypedDict2] @@ -213,19 +213,19 @@ else: x3: Union[NamedTuple1, NamedTuple2] if isinstance(x3.key, int): - reveal_type(x3) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.NamedTuple1]" + reveal_type(x3) # N: Revealed type is "tuple[builtins.int, fallback=__main__.NamedTuple1]" else: - reveal_type(x3) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.NamedTuple2]" + reveal_type(x3) # N: Revealed type is "tuple[builtins.str, fallback=__main__.NamedTuple2]" if isinstance(x3[0], int): - reveal_type(x3) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.NamedTuple1]" + reveal_type(x3) # N: Revealed type is "tuple[builtins.int, fallback=__main__.NamedTuple1]" else: - reveal_type(x3) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.NamedTuple2]" + reveal_type(x3) # N: Revealed type is "tuple[builtins.str, fallback=__main__.NamedTuple2]" x4: Union[Tuple1, Tuple2] if isinstance(x4[0], int): - reveal_type(x4) # N: Revealed type is "Tuple[builtins.int]" + reveal_type(x4) # N: Revealed type is "tuple[builtins.int]" else: - reveal_type(x4) # N: Revealed type is "Tuple[builtins.str]" + reveal_type(x4) # N: Revealed type is "tuple[builtins.str]" x5: Union[TypedDict1, TypedDict2] if isinstance(x5["key"], int): @@ -414,7 +414,7 @@ ok_mixture: Union[KeyedObject, KeyedNamedTuple] if ok_mixture.key is Key.A: reveal_type(ok_mixture) # N: Revealed type is "__main__.KeyedObject" else: - reveal_type(ok_mixture) # N: Revealed type is "Tuple[Literal[__main__.Key.C], fallback=__main__.KeyedNamedTuple]" + reveal_type(ok_mixture) # N: Revealed type is "tuple[Literal[__main__.Key.C], fallback=__main__.KeyedNamedTuple]" impossible_mixture: Union[KeyedObject, KeyedTypedDict] if impossible_mixture.key is Key.A: # E: Item "KeyedTypedDict" of "Union[KeyedObject, KeyedTypedDict]" has no attribute "key" @@ -431,15 +431,15 @@ weird_mixture: Union[KeyedTypedDict, KeyedNamedTuple] if weird_mixture["key"] is Key.B: # E: No overload variant of "__getitem__" of "tuple" matches argument type "str" \ # N: Possible overload variants: \ # N: def __getitem__(self, int, /) -> Literal[Key.C] \ - # N: def __getitem__(self, slice, /) -> Tuple[Literal[Key.C], ...] - reveal_type(weird_mixture) # N: Revealed type is "Union[TypedDict('__main__.KeyedTypedDict', {'key': Literal[__main__.Key.B]}), Tuple[Literal[__main__.Key.C], fallback=__main__.KeyedNamedTuple]]" + # N: def __getitem__(self, slice, /) -> tuple[Literal[Key.C], ...] + reveal_type(weird_mixture) # N: Revealed type is "Union[TypedDict('__main__.KeyedTypedDict', {'key': Literal[__main__.Key.B]}), tuple[Literal[__main__.Key.C], fallback=__main__.KeyedNamedTuple]]" else: - reveal_type(weird_mixture) # N: Revealed type is "Union[TypedDict('__main__.KeyedTypedDict', {'key': Literal[__main__.Key.B]}), Tuple[Literal[__main__.Key.C], fallback=__main__.KeyedNamedTuple]]" + reveal_type(weird_mixture) # N: Revealed type is "Union[TypedDict('__main__.KeyedTypedDict', {'key': Literal[__main__.Key.B]}), tuple[Literal[__main__.Key.C], fallback=__main__.KeyedNamedTuple]]" if weird_mixture[0] is Key.B: # E: TypedDict key must be a string literal; expected one of ("key") - reveal_type(weird_mixture) # N: Revealed type is "Union[TypedDict('__main__.KeyedTypedDict', {'key': Literal[__main__.Key.B]}), Tuple[Literal[__main__.Key.C], fallback=__main__.KeyedNamedTuple]]" + reveal_type(weird_mixture) # N: Revealed type is "Union[TypedDict('__main__.KeyedTypedDict', {'key': Literal[__main__.Key.B]}), tuple[Literal[__main__.Key.C], fallback=__main__.KeyedNamedTuple]]" else: - reveal_type(weird_mixture) # N: Revealed type is "Union[TypedDict('__main__.KeyedTypedDict', {'key': Literal[__main__.Key.B]}), Tuple[Literal[__main__.Key.C], fallback=__main__.KeyedNamedTuple]]" + reveal_type(weird_mixture) # N: Revealed type is "Union[TypedDict('__main__.KeyedTypedDict', {'key': Literal[__main__.Key.B]}), tuple[Literal[__main__.Key.C], fallback=__main__.KeyedNamedTuple]]" [builtins fixtures/tuple.pyi] [typing fixtures/typing-full.pyi] @@ -1106,7 +1106,7 @@ T = TypeVar("T", A, B) def f(cls: Type[T]) -> T: if issubclass(cls, A): - reveal_type(cls) # N: Revealed type is "Type[__main__.A]" + reveal_type(cls) # N: Revealed type is "type[__main__.A]" x: bool if x: return A() @@ -1260,14 +1260,14 @@ class C: pass def f(t: Type[C]) -> None: if type(t) is M: - reveal_type(t) # N: Revealed type is "Type[__main__.C]" + reveal_type(t) # N: Revealed type is "type[__main__.C]" else: - reveal_type(t) # N: Revealed type is "Type[__main__.C]" + reveal_type(t) # N: Revealed type is "type[__main__.C]" if type(t) is not M: - reveal_type(t) # N: Revealed type is "Type[__main__.C]" + reveal_type(t) # N: Revealed type is "type[__main__.C]" else: - reveal_type(t) # N: Revealed type is "Type[__main__.C]" - reveal_type(t) # N: Revealed type is "Type[__main__.C]" + reveal_type(t) # N: Revealed type is "type[__main__.C]" + reveal_type(t) # N: Revealed type is "type[__main__.C]" [case testNarrowingUsingTypeVar] from typing import Type, TypeVar @@ -1502,14 +1502,14 @@ from typing import Tuple x: Tuple[int, ...] if len(x) == 3: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int, builtins.int]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int, builtins.int]" else: reveal_type(x) # N: Revealed type is "builtins.tuple[builtins.int, ...]" if len(x) != 3: reveal_type(x) # N: Revealed type is "builtins.tuple[builtins.int, ...]" else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int, builtins.int]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int, builtins.int]" [builtins fixtures/len.pyi] [case testNarrowingLenTypeUnaffected] @@ -1541,8 +1541,8 @@ VarTuple = Union[Tuple[int, int], Tuple[int, int, int]] x: VarTuple y: VarTuple if len(x) == len(y) == 3: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int, builtins.int]" - reveal_type(y) # N: Revealed type is "Tuple[builtins.int, builtins.int, builtins.int]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int, builtins.int]" + reveal_type(y) # N: Revealed type is "tuple[builtins.int, builtins.int, builtins.int]" [builtins fixtures/len.pyi] [case testNarrowingLenFinal] @@ -1553,7 +1553,7 @@ VarTuple = Union[Tuple[int, int], Tuple[int, int, int]] x: VarTuple fin: Final = 3 if len(x) == fin: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int, builtins.int]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int, builtins.int]" [builtins fixtures/len.pyi] [case testNarrowingLenGreaterThan] @@ -1563,24 +1563,24 @@ VarTuple = Union[Tuple[int], Tuple[int, int], Tuple[int, int, int]] x: VarTuple if len(x) > 1: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], Tuple[builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], tuple[builtins.int, builtins.int, builtins.int]]" else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int]" if len(x) < 2: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int]" else: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], Tuple[builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], tuple[builtins.int, builtins.int, builtins.int]]" if len(x) >= 2: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], Tuple[builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], tuple[builtins.int, builtins.int, builtins.int]]" else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int]" if len(x) <= 2: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int], Tuple[builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int], tuple[builtins.int, builtins.int]]" else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int, builtins.int]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int, builtins.int]" [builtins fixtures/len.pyi] [case testNarrowingLenBothSidesUnionTuples] @@ -1595,9 +1595,9 @@ VarTuple = Union[ x: VarTuple if 2 <= len(x) <= 3: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], Tuple[builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], tuple[builtins.int, builtins.int, builtins.int]]" else: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int], Tuple[builtins.int, builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int], tuple[builtins.int, builtins.int, builtins.int, builtins.int]]" [builtins fixtures/len.pyi] [case testNarrowingLenGreaterThanHomogeneousTupleShort] @@ -1608,9 +1608,9 @@ VarTuple = Tuple[int, ...] x: VarTuple if len(x) < 3: - reveal_type(x) # N: Revealed type is "Union[Tuple[()], Tuple[builtins.int], Tuple[builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[()], tuple[builtins.int], tuple[builtins.int, builtins.int]]" else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int, builtins.int, Unpack[builtins.tuple[builtins.int, ...]]]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int, builtins.int, Unpack[builtins.tuple[builtins.int, ...]]]" reveal_type(x) # N: Revealed type is "builtins.tuple[builtins.int, ...]" [builtins fixtures/len.pyi] @@ -1633,9 +1633,9 @@ from typing import Tuple x: Tuple[int, ...] if 1 < len(x) < 4: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], Tuple[builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], tuple[builtins.int, builtins.int, builtins.int]]" else: - reveal_type(x) # N: Revealed type is "Union[Tuple[()], Tuple[builtins.int], Tuple[builtins.int, builtins.int, builtins.int, builtins.int, Unpack[builtins.tuple[builtins.int, ...]]]]" + reveal_type(x) # N: Revealed type is "Union[tuple[()], tuple[builtins.int], tuple[builtins.int, builtins.int, builtins.int, builtins.int, Unpack[builtins.tuple[builtins.int, ...]]]]" reveal_type(x) # N: Revealed type is "builtins.tuple[builtins.int, ...]" [builtins fixtures/len.pyi] @@ -1647,12 +1647,12 @@ x: Union[Tuple[int, int], Tuple[int, int, int]] if len(x) >= 4: reveal_type(x) # E: Statement is unreachable else: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], Tuple[builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], tuple[builtins.int, builtins.int, builtins.int]]" if len(x) < 2: reveal_type(x) # E: Statement is unreachable else: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], Tuple[builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], tuple[builtins.int, builtins.int, builtins.int]]" [builtins fixtures/len.pyi] [case testNarrowingLenMixedTypes] @@ -1661,17 +1661,17 @@ from typing import Tuple, List, Union x: Union[Tuple[int, int], Tuple[int, int, int], List[int]] a = b = c = 0 if len(x) == 3: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int, builtins.int], builtins.list[builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int, builtins.int], builtins.list[builtins.int]]" a, b, c = x else: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], builtins.list[builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], builtins.list[builtins.int]]" a, b = x if len(x) != 3: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], builtins.list[builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], builtins.list[builtins.int]]" a, b = x else: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int, builtins.int], builtins.list[builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int, builtins.int], builtins.list[builtins.int]]" a, b, c = x [builtins fixtures/len.pyi] @@ -1682,14 +1682,14 @@ from typing_extensions import TypeVarTuple, Unpack Ts = TypeVarTuple("Ts") def foo(x: Tuple[int, Unpack[Ts], str]) -> None: if len(x) == 5: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`-1], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`-1], builtins.str]" else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`-1], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`-1], builtins.str]" if len(x) != 5: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`-1], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`-1], builtins.str]" else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`-1], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`-1], builtins.str]" [builtins fixtures/len.pyi] [case testNarrowingLenTypeVarTupleGreaterThan] @@ -1699,17 +1699,17 @@ from typing_extensions import TypeVarTuple, Unpack Ts = TypeVarTuple("Ts") def foo(x: Tuple[int, Unpack[Ts], str]) -> None: if len(x) > 5: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`-1], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`-1], builtins.str]" reveal_type(x[5]) # N: Revealed type is "builtins.object" reveal_type(x[-6]) # N: Revealed type is "builtins.object" reveal_type(x[-1]) # N: Revealed type is "builtins.str" else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`-1], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`-1], builtins.str]" if len(x) < 5: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`-1], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`-1], builtins.str]" else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`-1], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`-1], builtins.str]" x[5] # E: Tuple index out of range \ # N: Variadic tuple can have length 5 x[-6] # E: Tuple index out of range \ @@ -1730,23 +1730,23 @@ def foo(x: Tuple[int, Unpack[Ts], str]) -> None: if len(x) == 1: reveal_type(x) # E: Statement is unreachable else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`-1], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`-1], builtins.str]" if len(x) != 1: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`-1], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`-1], builtins.str]" else: reveal_type(x) # E: Statement is unreachable def bar(x: Tuple[int, Unpack[Ts], str]) -> None: if len(x) >= 2: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`-1], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`-1], builtins.str]" else: reveal_type(x) # E: Statement is unreachable if len(x) < 2: reveal_type(x) # E: Statement is unreachable else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`-1], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`-1], builtins.str]" [builtins fixtures/len.pyi] [case testNarrowingLenVariadicTupleEquals] @@ -1755,14 +1755,14 @@ from typing_extensions import Unpack def foo(x: Tuple[int, Unpack[Tuple[float, ...]], str]) -> None: if len(x) == 4: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.float, builtins.float, builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.float, builtins.float, builtins.str]" else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" if len(x) != 4: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.float, builtins.float, builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.float, builtins.float, builtins.str]" [builtins fixtures/len.pyi] [case testNarrowingLenVariadicTupleGreaterThan] @@ -1771,16 +1771,16 @@ from typing_extensions import Unpack def foo(x: Tuple[int, Unpack[Tuple[float, ...]], str]) -> None: if len(x) > 3: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.float, builtins.float, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.float, builtins.float, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" else: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.str], Tuple[builtins.int, builtins.float, builtins.str]]" - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.str], tuple[builtins.int, builtins.float, builtins.str]]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" if len(x) < 3: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.str]" else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.float, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.float, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" [builtins fixtures/len.pyi] [case testNarrowingLenVariadicTupleUnreachable] @@ -1792,23 +1792,23 @@ def foo(x: Tuple[int, Unpack[Tuple[float, ...]], str]) -> None: if len(x) == 1: reveal_type(x) # E: Statement is unreachable else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" if len(x) != 1: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" else: reveal_type(x) # E: Statement is unreachable def bar(x: Tuple[int, Unpack[Tuple[float, ...]], str]) -> None: if len(x) >= 2: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" else: reveal_type(x) # E: Statement is unreachable if len(x) < 2: reveal_type(x) # E: Statement is unreachable else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" [builtins fixtures/len.pyi] [case testNarrowingLenBareExpressionPrecise] @@ -1817,7 +1817,7 @@ from typing import Tuple x: Tuple[int, ...] assert x -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]]]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]]]" [builtins fixtures/len.pyi] [case testNarrowingLenBareExpressionTypeVarTuple] @@ -1836,9 +1836,9 @@ from typing import Tuple, Optional x: Optional[Tuple[int, ...]] if x: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]]]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]]]" else: - reveal_type(x) # N: Revealed type is "Union[Tuple[()], None]" + reveal_type(x) # N: Revealed type is "Union[tuple[()], None]" [builtins fixtures/len.pyi] [case testNarrowingLenBareExpressionWithNoneImprecise] @@ -1857,14 +1857,14 @@ from typing import Any x: Any if isinstance(x, (list, tuple)) and len(x) == 0: - reveal_type(x) # N: Revealed type is "Union[Tuple[()], builtins.list[Any]]" + reveal_type(x) # N: Revealed type is "Union[tuple[()], builtins.list[Any]]" else: reveal_type(x) # N: Revealed type is "Any" reveal_type(x) # N: Revealed type is "Any" x1: Any if isinstance(x1, (list, tuple)) and len(x1) > 1: - reveal_type(x1) # N: Revealed type is "Union[Tuple[Any, Any, Unpack[builtins.tuple[Any, ...]]], builtins.list[Any]]" + reveal_type(x1) # N: Revealed type is "Union[tuple[Any, Any, Unpack[builtins.tuple[Any, ...]]], builtins.list[Any]]" else: reveal_type(x1) # N: Revealed type is "Any" reveal_type(x1) # N: Revealed type is "Any" @@ -1875,7 +1875,7 @@ from typing import Any x: Any if isinstance(x, (list, tuple)) and len(x) == 0: - reveal_type(x) # N: Revealed type is "Union[Tuple[()], builtins.list[Any]]" + reveal_type(x) # N: Revealed type is "Union[tuple[()], builtins.list[Any]]" else: reveal_type(x) # N: Revealed type is "Any" reveal_type(x) # N: Revealed type is "Any" @@ -1900,15 +1900,15 @@ x: VarTuple supported: Literal[2] if len(x) == supported: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int]" else: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int], Tuple[builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int], tuple[builtins.int, builtins.int, builtins.int]]" not_supported_yet: Literal[2, 3] if len(x) == not_supported_yet: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int], Tuple[builtins.int, builtins.int], Tuple[builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int], tuple[builtins.int, builtins.int], tuple[builtins.int, builtins.int, builtins.int]]" else: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int], Tuple[builtins.int, builtins.int], Tuple[builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int], tuple[builtins.int, builtins.int], tuple[builtins.int, builtins.int, builtins.int]]" [builtins fixtures/len.pyi] [case testNarrowingLenUnionOfVariadicTuples] @@ -1916,7 +1916,7 @@ from typing import Tuple, Union x: Union[Tuple[int, ...], Tuple[str, ...]] if len(x) == 2: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], Tuple[builtins.str, builtins.str]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], tuple[builtins.str, builtins.str]]" else: reveal_type(x) # N: Revealed type is "Union[builtins.tuple[builtins.int, ...], builtins.tuple[builtins.str, ...]]" [builtins fixtures/len.pyi] @@ -1934,9 +1934,9 @@ class Point3D(NamedTuple): x: Union[Point2D, Point3D] if len(x) == 2: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.Point2D]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.Point2D]" else: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int, builtins.int, fallback=__main__.Point3D]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int, builtins.int, fallback=__main__.Point3D]" [builtins fixtures/len.pyi] [case testNarrowingLenTupleSubclass] @@ -1947,7 +1947,7 @@ class Ints(Tuple[int, ...]): x: Ints if len(x) == 2: - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.Ints]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.Ints]" reveal_type(x.size) # N: Revealed type is "builtins.int" else: reveal_type(x) # N: Revealed type is "__main__.Ints" @@ -1991,15 +1991,15 @@ x: Union[Tuple[int, int], Tuple[int, int, int]] n: int if len(x) == n: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], Tuple[builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], tuple[builtins.int, builtins.int, builtins.int]]" else: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], Tuple[builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], tuple[builtins.int, builtins.int, builtins.int]]" a: Any if len(x) == a: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], Tuple[builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], tuple[builtins.int, builtins.int, builtins.int]]" else: - reveal_type(x) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], Tuple[builtins.int, builtins.int, builtins.int]]" + reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], tuple[builtins.int, builtins.int, builtins.int]]" [builtins fixtures/len.pyi] [case testNarrowingLenUnionWithUnreachable] @@ -2012,7 +2012,7 @@ def f(x: Union[int, Sequence[int]]) -> None: and isinstance(x[0], int) and isinstance(x[1], int) ): - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int]" [builtins fixtures/len.pyi] [case testNarrowingIsSubclassNoneType1] @@ -2020,9 +2020,9 @@ from typing import Type, Union def f(cls: Type[Union[None, int]]) -> None: if issubclass(cls, int): - reveal_type(cls) # N: Revealed type is "Type[builtins.int]" + reveal_type(cls) # N: Revealed type is "type[builtins.int]" else: - reveal_type(cls) # N: Revealed type is "Type[None]" + reveal_type(cls) # N: Revealed type is "type[None]" [builtins fixtures/isinstance.pyi] [case testNarrowingIsSubclassNoneType2] @@ -2030,9 +2030,9 @@ from typing import Type, Union def f(cls: Type[Union[None, int]]) -> None: if issubclass(cls, type(None)): - reveal_type(cls) # N: Revealed type is "Type[None]" + reveal_type(cls) # N: Revealed type is "type[None]" else: - reveal_type(cls) # N: Revealed type is "Type[builtins.int]" + reveal_type(cls) # N: Revealed type is "type[builtins.int]" [builtins fixtures/isinstance.pyi] [case testNarrowingIsSubclassNoneType3] @@ -2042,9 +2042,9 @@ NoneType_ = type(None) def f(cls: Type[Union[None, int]]) -> None: if issubclass(cls, NoneType_): - reveal_type(cls) # N: Revealed type is "Type[None]" + reveal_type(cls) # N: Revealed type is "type[None]" else: - reveal_type(cls) # N: Revealed type is "Type[builtins.int]" + reveal_type(cls) # N: Revealed type is "type[builtins.int]" [builtins fixtures/isinstance.pyi] [case testNarrowingIsSubclassNoneType4] @@ -2055,9 +2055,9 @@ from typing import Type, Union def f(cls: Type[Union[None, int]]) -> None: if issubclass(cls, NoneType): - reveal_type(cls) # N: Revealed type is "Type[None]" + reveal_type(cls) # N: Revealed type is "type[None]" else: - reveal_type(cls) # N: Revealed type is "Type[builtins.int]" + reveal_type(cls) # N: Revealed type is "type[builtins.int]" [builtins fixtures/isinstance.pyi] [case testNarrowingIsInstanceNoIntersectionWithFinalTypeAndNoneType] @@ -2351,7 +2351,7 @@ while f(): y = 1 reveal_type(y) # N: Revealed type is "Union[builtins.int, None]" -z = [] # E: Need type annotation for "z" (hint: "z: List[] = ...") +z = [] # E: Need type annotation for "z" (hint: "z: list[] = ...") def g() -> None: for i in range(2): while f(): @@ -2361,7 +2361,7 @@ def g() -> None: class A: def g(self) -> None: - z = [] # E: Need type annotation for "z" (hint: "z: List[] = ...") + z = [] # E: Need type annotation for "z" (hint: "z: list[] = ...") for i in range(2): while f(): if z: diff --git a/test-data/unit/check-newsemanal.test b/test-data/unit/check-newsemanal.test index b6756abafc49..1d489d54409f 100644 --- a/test-data/unit/check-newsemanal.test +++ b/test-data/unit/check-newsemanal.test @@ -863,8 +863,8 @@ In = NamedTuple('In', [('s', str), ('t', Other)]) Out = NamedTuple('Out', [('x', In), ('y', Other)]) o: Out i: In -reveal_type(o) # N: Revealed type is "Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]" -reveal_type(o.x) # N: Revealed type is "Tuple[builtins.str, __main__.Other, fallback=__main__.In]" +reveal_type(o) # N: Revealed type is "tuple[tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]" +reveal_type(o.x) # N: Revealed type is "tuple[builtins.str, __main__.Other, fallback=__main__.In]" reveal_type(o.y) # N: Revealed type is "__main__.Other" reveal_type(o.x.t) # N: Revealed type is "__main__.Other" reveal_type(i.t) # N: Revealed type is "__main__.Other" @@ -880,8 +880,8 @@ class Out(NamedTuple): x: In y: Other -reveal_type(o) # N: Revealed type is "Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]" -reveal_type(o.x) # N: Revealed type is "Tuple[builtins.str, __main__.Other, fallback=__main__.In]" +reveal_type(o) # N: Revealed type is "tuple[tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]" +reveal_type(o.x) # N: Revealed type is "tuple[builtins.str, __main__.Other, fallback=__main__.In]" reveal_type(o.y) # N: Revealed type is "__main__.Other" reveal_type(o.x.t) # N: Revealed type is "__main__.Other" reveal_type(i.t) # N: Revealed type is "__main__.Other" @@ -898,8 +898,8 @@ from typing import NamedTuple o: C.Out i: C.In -reveal_type(o) # N: Revealed type is "Tuple[Tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In], __main__.C.Other, fallback=__main__.C.Out]" -reveal_type(o.x) # N: Revealed type is "Tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In]" +reveal_type(o) # N: Revealed type is "tuple[tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In], __main__.C.Other, fallback=__main__.C.Out]" +reveal_type(o.x) # N: Revealed type is "tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In]" reveal_type(o.y) # N: Revealed type is "__main__.C.Other" reveal_type(o.x.t) # N: Revealed type is "__main__.C.Other" reveal_type(i.t) # N: Revealed type is "__main__.C.Other" @@ -917,8 +917,8 @@ from typing import NamedTuple o: C.Out i: C.In -reveal_type(o) # N: Revealed type is "Tuple[Tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In], __main__.C.Other, fallback=__main__.C.Out]" -reveal_type(o.x) # N: Revealed type is "Tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In]" +reveal_type(o) # N: Revealed type is "tuple[tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In], __main__.C.Other, fallback=__main__.C.Out]" +reveal_type(o.x) # N: Revealed type is "tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In]" reveal_type(o.y) # N: Revealed type is "__main__.C.Other" reveal_type(o.x.t) # N: Revealed type is "__main__.C.Other" reveal_type(i.t) # N: Revealed type is "__main__.C.Other" @@ -944,8 +944,8 @@ class C: self.o: Out c = C() -reveal_type(c.o) # N: Revealed type is "Tuple[Tuple[builtins.str, __main__.Other@7, fallback=__main__.C.In@6], __main__.Other@7, fallback=__main__.C.Out@5]" -reveal_type(c.o.x) # N: Revealed type is "Tuple[builtins.str, __main__.Other@7, fallback=__main__.C.In@6]" +reveal_type(c.o) # N: Revealed type is "tuple[tuple[builtins.str, __main__.Other@7, fallback=__main__.C.In@6], __main__.Other@7, fallback=__main__.C.Out@5]" +reveal_type(c.o.x) # N: Revealed type is "tuple[builtins.str, __main__.Other@7, fallback=__main__.C.In@6]" [builtins fixtures/tuple.pyi] [case testNewAnalyzerNamedTupleClassNestedMethod] @@ -964,16 +964,16 @@ class C: self.o: Out c = C() -reveal_type(c.o) # N: Revealed type is "Tuple[Tuple[builtins.str, __main__.Other@12, fallback=__main__.C.In@9], __main__.Other@12, fallback=__main__.C.Out@5]" -reveal_type(c.o.x) # N: Revealed type is "Tuple[builtins.str, __main__.Other@12, fallback=__main__.C.In@9]" -reveal_type(c.o.method()) # N: Revealed type is "Tuple[builtins.str, __main__.Other@12, fallback=__main__.C.In@9]" +reveal_type(c.o) # N: Revealed type is "tuple[tuple[builtins.str, __main__.Other@12, fallback=__main__.C.In@9], __main__.Other@12, fallback=__main__.C.Out@5]" +reveal_type(c.o.x) # N: Revealed type is "tuple[builtins.str, __main__.Other@12, fallback=__main__.C.In@9]" +reveal_type(c.o.method()) # N: Revealed type is "tuple[builtins.str, __main__.Other@12, fallback=__main__.C.In@9]" [builtins fixtures/tuple.pyi] [case testNewAnalyzerNamedTupleClassForwardMethod] from typing import NamedTuple n: NT -reveal_type(n.get_other()) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.Other]" +reveal_type(n.get_other()) # N: Revealed type is "tuple[builtins.str, fallback=__main__.Other]" reveal_type(n.get_other().s) # N: Revealed type is "builtins.str" class NT(NamedTuple): @@ -995,8 +995,8 @@ class SubO(Out): pass o: SubO -reveal_type(SubO._make) # N: Revealed type is "def (iterable: typing.Iterable[Any]) -> Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.SubO]" -reveal_type(o._replace(y=Other())) # N: Revealed type is "Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.SubO]" +reveal_type(SubO._make) # N: Revealed type is "def (iterable: typing.Iterable[Any]) -> tuple[tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.SubO]" +reveal_type(o._replace(y=Other())) # N: Revealed type is "tuple[tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.SubO]" [builtins fixtures/tuple.pyi] [case testNewAnalyzerNamedTupleBaseClass] @@ -1009,10 +1009,10 @@ class Out(NamedTuple('Out', [('x', In), ('y', Other)])): pass o: Out -reveal_type(o) # N: Revealed type is "Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]" -reveal_type(o.x) # N: Revealed type is "Tuple[builtins.str, __main__.Other, fallback=__main__.In]" +reveal_type(o) # N: Revealed type is "tuple[tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]" +reveal_type(o.x) # N: Revealed type is "tuple[builtins.str, __main__.Other, fallback=__main__.In]" reveal_type(o.x.t) # N: Revealed type is "__main__.Other" -reveal_type(Out._make) # N: Revealed type is "def (iterable: typing.Iterable[Any]) -> Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]" +reveal_type(Out._make) # N: Revealed type is "def (iterable: typing.Iterable[Any]) -> tuple[tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]" [builtins fixtures/tuple.pyi] [case testNewAnalyzerIncompleteRefShadowsBuiltin1] @@ -1078,7 +1078,7 @@ from b import C import a [file a.py] C = 1 -from b import C # E: Incompatible import of "C" (imported name has type "Type[C]", local name has type "int") +from b import C # E: Incompatible import of "C" (imported name has type "type[C]", local name has type "int") [file b.py] import a @@ -1092,7 +1092,7 @@ import a C = 1 MYPY = False if MYPY: # Tweak processing order - from b import * # E: Incompatible import of "C" (imported name has type "Type[C]", local name has type "int") + from b import * # E: Incompatible import of "C" (imported name has type "type[C]", local name has type "int") [file b.py] import a @@ -1104,7 +1104,7 @@ class B: ... import a [file a.py] C = 1 -from b import * # E: Incompatible import of "C" (imported name has type "Type[C]", local name has type "int") +from b import * # E: Incompatible import of "C" (imported name has type "type[C]", local name has type "int") [file b.py] MYPY = False @@ -1432,7 +1432,7 @@ from a import x class B(List[B], Generic[T]): pass T = TypeVar('T') -reveal_type(x) # N: Revealed type is "b.B[Tuple[builtins.int, builtins.int]]" +reveal_type(x) # N: Revealed type is "b.B[tuple[builtins.int, builtins.int]]" [builtins fixtures/list.pyi] [case testNewAnalyzerAliasToNotReadyClassInGeneric] @@ -1449,7 +1449,7 @@ from a import x class B(List[B]): pass -reveal_type(x) # N: Revealed type is "Tuple[b.B, b.B]" +reveal_type(x) # N: Revealed type is "tuple[b.B, b.B]" [builtins fixtures/list.pyi] [case testNewAnalyzerAliasToNotReadyClassDoubleGeneric] @@ -1570,7 +1570,7 @@ import a [file a.py] from b import B def func() -> B: ... -reveal_type(func()) # N: Revealed type is "builtins.list[Tuple[b.C, b.C]]" +reveal_type(func()) # N: Revealed type is "builtins.list[tuple[b.C, b.C]]" [file b.py] from typing import List, Tuple @@ -1597,7 +1597,7 @@ abl: List[Tuple[A, B]] abd = {a: b for a, b in abl} x: Dict[B, A] = {a: b for a, b in abl} # E: Key expression in dictionary comprehension has incompatible type "A"; expected type "B" \ # E: Value expression in dictionary comprehension has incompatible type "B"; expected type "A" -y: A = {a: b for a, b in abl} # E: Incompatible types in assignment (expression has type "Dict[A, B]", variable has type "A") +y: A = {a: b for a, b in abl} # E: Incompatible types in assignment (expression has type "dict[A, B]", variable has type "A") class A: pass class B: pass [builtins fixtures/dict.pyi] @@ -1840,7 +1840,7 @@ x.extend(y) import b [file a.py] from b import x -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int]" [file b.py] import a x = (1, 2) @@ -1850,7 +1850,7 @@ x = (1, 2) import a [file a.py] from b import x -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int]" [file b.py] import a x = (1, 2) @@ -1974,7 +1974,7 @@ S = TypeVar('S', bound='Tuple[G[A], ...]') class GG(Generic[S]): pass -g: GG[Tuple[G[B], G[C]]] # E: Type argument "Tuple[G[B], G[C]]" of "GG" must be a subtype of "Tuple[G[A], ...]" \ +g: GG[Tuple[G[B], G[C]]] # E: Type argument "tuple[G[B], G[C]]" of "GG" must be a subtype of "tuple[G[A], ...]" \ # E: Type argument "B" of "G" must be a subtype of "A" \ # E: Type argument "C" of "G" must be a subtype of "A" @@ -2176,7 +2176,7 @@ def test() -> None: reveal_type(y.x) # N: Revealed type is "builtins.int" reveal_type(y[0]) # N: Revealed type is "builtins.int" x: A - reveal_type(x) # N: Revealed type is "__main__.G@7[Tuple[builtins.int, fallback=__main__.C@5]]" + reveal_type(x) # N: Revealed type is "__main__.G@7[tuple[builtins.int, fallback=__main__.C@5]]" [builtins fixtures/list.pyi] [case testNewAnalyzerDuplicateTypeVar] @@ -2314,7 +2314,7 @@ from typing import cast, NamedTuple x = cast('C', None) -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.C]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, fallback=__main__.C]" reveal_type(x.x) # N: Revealed type is "builtins.int" C = NamedTuple('C', [('x', int)]) @@ -2746,7 +2746,7 @@ class C(Generic[T]): pass C = C[int] # E: Cannot assign to a type \ - # E: Incompatible types in assignment (expression has type "Type[C[int]]", variable has type "Type[C[T]]") + # E: Incompatible types in assignment (expression has type "type[C[int]]", variable has type "type[C[T]]") x: C reveal_type(x) # N: Revealed type is "__main__.C[Any]" diff --git a/test-data/unit/check-newsyntax.test b/test-data/unit/check-newsyntax.test index a696eb2932fe..df36a1ce4dd2 100644 --- a/test-data/unit/check-newsyntax.test +++ b/test-data/unit/check-newsyntax.test @@ -21,7 +21,7 @@ from typing import Dict, Any d: Dict[int, str] = {} d[42] = 'ab' d[42] = 42 # E: Incompatible types in assignment (expression has type "int", target has type "str") -d['ab'] = 'ab' # E: Invalid index type "str" for "Dict[int, str]"; expected type "int" +d['ab'] = 'ab' # E: Invalid index type "str" for "dict[int, str]"; expected type "int" [builtins fixtures/dict.pyi] [out] diff --git a/test-data/unit/check-newtype.test b/test-data/unit/check-newtype.test index a0a30079f062..f7219e721222 100644 --- a/test-data/unit/check-newtype.test +++ b/test-data/unit/check-newtype.test @@ -44,7 +44,7 @@ main:12: error: Argument 1 to "TcpPacketId" has incompatible type "int"; expecte from typing import NewType, Tuple TwoTuple = NewType('TwoTuple', Tuple[int, str]) a = TwoTuple((3, "a")) -b = TwoTuple(("a", 3)) # E: Argument 1 to "TwoTuple" has incompatible type "Tuple[str, int]"; expected "Tuple[int, str]" +b = TwoTuple(("a", 3)) # E: Argument 1 to "TwoTuple" has incompatible type "tuple[str, int]"; expected "tuple[int, str]" reveal_type(a[0]) # N: Revealed type is "builtins.int" reveal_type(a[1]) # N: Revealed type is "builtins.str" @@ -291,7 +291,7 @@ Foo = NewType('Foo', Union[int, float]) # E: Argument 2 to NewType(...) must be [case testNewTypeWithTypeTypeFails] from typing import NewType, Type -Foo = NewType('Foo', Type[int]) # E: Argument 2 to NewType(...) must be subclassable (got "Type[int]") +Foo = NewType('Foo', Type[int]) # E: Argument 2 to NewType(...) must be subclassable (got "type[int]") a = Foo(type(3)) [builtins fixtures/args.pyi] [out] diff --git a/test-data/unit/check-optional.test b/test-data/unit/check-optional.test index 5ed4c15f470e..679906b0e00e 100644 --- a/test-data/unit/check-optional.test +++ b/test-data/unit/check-optional.test @@ -201,7 +201,7 @@ x.append(1) # E: Argument 1 to "append" of "list" has incompatible type "int"; [case testInferNonOptionalListType] x = [] x.append(1) -x() # E: "List[int]" not callable +x() # E: "list[int]" not callable [builtins fixtures/list.pyi] [case testInferOptionalDictKeyValueTypes] @@ -209,13 +209,13 @@ x = {None: None} x["bar"] = 1 [builtins fixtures/dict.pyi] [out] -main:2: error: Invalid index type "str" for "Dict[None, None]"; expected type "None" +main:2: error: Invalid index type "str" for "dict[None, None]"; expected type "None" main:2: error: Incompatible types in assignment (expression has type "int", target has type "None") [case testInferNonOptionalDictType] x = {} x["bar"] = 1 -x() # E: "Dict[str, int]" not callable +x() # E: "dict[str, int]" not callable [builtins fixtures/dict.pyi] [case testNoneClassVariable] @@ -781,7 +781,7 @@ asdf(x) \[mypy-a] strict_optional = False [out] -main:4: error: Argument 1 to "asdf" has incompatible type "List[str]"; expected "List[Optional[str]]" +main:4: error: Argument 1 to "asdf" has incompatible type "list[str]"; expected "list[Optional[str]]" main:4: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance main:4: note: Consider using "Sequence" instead, which is covariant [builtins fixtures/list.pyi] @@ -978,7 +978,7 @@ def f23(b: bool) -> None: def f1(b: bool) -> None: if b: - x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") + x = [] # E: Need type annotation for "x" (hint: "x: list[] = ...") else: x = None diff --git a/test-data/unit/check-overloading.test b/test-data/unit/check-overloading.test index 243568c54253..0ccc8a2a353c 100644 --- a/test-data/unit/check-overloading.test +++ b/test-data/unit/check-overloading.test @@ -620,7 +620,7 @@ t: type a: A if int(): - a = A # E: Incompatible types in assignment (expression has type "Type[A]", variable has type "A") + a = A # E: Incompatible types in assignment (expression has type "type[A]", variable has type "A") t = A class A: @@ -811,7 +811,7 @@ n = 1 m = 1 n = 'x' # E: Incompatible types in assignment (expression has type "str", variable has type "int") m = 'x' # E: Incompatible types in assignment (expression has type "str", variable has type "int") -f(list_object) # E: Argument 1 to "f" has incompatible type "List[object]"; expected "List[int]" +f(list_object) # E: Argument 1 to "f" has incompatible type "list[object]"; expected "list[int]" [builtins fixtures/list.pyi] [case testOverlappingOverloadSignatures] @@ -1147,7 +1147,7 @@ def f(x: str) -> None: pass f(1.1) f('') f(1) -f(()) # E: No overload variant of "f" matches argument type "Tuple[()]" \ +f(()) # E: No overload variant of "f" matches argument type "tuple[()]" \ # N: Possible overload variants: \ # N: def f(x: float) -> None \ # N: def f(x: str) -> None @@ -1216,13 +1216,13 @@ from typing import overload def f(x: int, y: str) -> int: pass @overload def f(*x: str) -> str: pass -f(*(1,))() # E: No overload variant of "f" matches argument type "Tuple[int]" \ +f(*(1,))() # E: No overload variant of "f" matches argument type "tuple[int]" \ # N: Possible overload variants: \ # N: def f(x: int, y: str) -> int \ # N: def f(*x: str) -> str f(*('',))() # E: "str" not callable f(*(1, ''))() # E: "int" not callable -f(*(1, '', 1))() # E: No overload variant of "f" matches argument type "Tuple[int, str, int]" \ +f(*(1, '', 1))() # E: No overload variant of "f" matches argument type "tuple[int, str, int]" \ # N: Possible overload variants: \ # N: def f(x: int, y: str) -> int \ # N: def f(*x: str) -> str @@ -1239,7 +1239,7 @@ def f(x: int, y: List[int] = None) -> int: pass def f(x: int, y: List[str] = None) -> int: pass f(y=[1], x=0)() # E: "int" not callable f(y=[''], x=0)() # E: "int" not callable -a = f(y=[['']], x=0) # E: List item 0 has incompatible type "List[str]"; expected "int" +a = f(y=[['']], x=0) # E: List item 0 has incompatible type "list[str]"; expected "int" reveal_type(a) # N: Revealed type is "builtins.int" [builtins fixtures/list.pyi] @@ -1299,7 +1299,7 @@ def g(x: U, y: V) -> None: f(y) # E: No overload variant of "f" matches argument type "V" \ # N: Possible overload variants: \ # N: def [T: str] f(x: T) -> T \ - # N: def [T: str] f(x: List[T]) -> None + # N: def [T: str] f(x: list[T]) -> None a = f([x]) reveal_type(a) # N: Revealed type is "None" f([y]) # E: Value of type variable "T" of "f" cannot be "V" @@ -1414,11 +1414,11 @@ main:17: note: Revealed type is "builtins.int" main:18: note: Revealed type is "builtins.str" main:19: note: Revealed type is "Any" main:20: note: Revealed type is "Union[builtins.int, builtins.str]" -main:21: error: Argument 1 to "foo" has incompatible type "List[bool]"; expected "List[int]" +main:21: error: Argument 1 to "foo" has incompatible type "list[bool]"; expected "list[int]" main:21: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance main:21: note: Consider using "Sequence" instead, which is covariant -main:22: error: Argument 1 to "foo" has incompatible type "List[object]"; expected "List[int]" -main:23: error: Argument 1 to "foo" has incompatible type "List[Union[int, str]]"; expected "List[int]" +main:22: error: Argument 1 to "foo" has incompatible type "list[object]"; expected "list[int]" +main:23: error: Argument 1 to "foo" has incompatible type "list[Union[int, str]]"; expected "list[int]" [case testOverloadAgainstEmptyCollections] from typing import overload, List @@ -1482,7 +1482,7 @@ class A(Generic[T]): b = A() # type: A[Tuple[int, int]] b.f((0, 0)) -b.f((0, '')) # E: Argument 1 to "f" of "A" has incompatible type "Tuple[int, str]"; expected "Tuple[int, int]" +b.f((0, '')) # E: Argument 1 to "f" of "A" has incompatible type "tuple[int, str]"; expected "tuple[int, int]" [builtins fixtures/tuple.pyi] [case testSingleOverloadStub] @@ -1554,14 +1554,14 @@ def f(x: int, y: Tuple[str, ...]) -> None: pass @overload def f(x: int, y: str) -> None: pass f(1, ('2', '3')) -f(1, (2, '3')) # E: Argument 2 to "f" has incompatible type "Tuple[int, str]"; expected "Tuple[str, ...]" +f(1, (2, '3')) # E: Argument 2 to "f" has incompatible type "tuple[int, str]"; expected "tuple[str, ...]" f(1, ('2',)) f(1, '2') -f(1, (2, 3)) # E: Argument 2 to "f" has incompatible type "Tuple[int, int]"; expected "Tuple[str, ...]" +f(1, (2, 3)) # E: Argument 2 to "f" has incompatible type "tuple[int, int]"; expected "tuple[str, ...]" x = ('2', '3') # type: Tuple[str, ...] f(1, x) y = (2, 3) # type: Tuple[int, ...] -f(1, y) # E: Argument 2 to "f" has incompatible type "Tuple[int, ...]"; expected "Tuple[str, ...]" +f(1, y) # E: Argument 2 to "f" has incompatible type "tuple[int, ...]"; expected "tuple[str, ...]" [builtins fixtures/tuple.pyi] [case testCallableSpecificOverload] @@ -2539,7 +2539,7 @@ x: List[int] reveal_type(foo(*x)) # N: Revealed type is "__main__.C" y: List[str] -foo(*y) # E: No overload variant of "foo" matches argument type "List[str]" \ +foo(*y) # E: No overload variant of "foo" matches argument type "list[str]" \ # N: Possible overload variants: \ # N: def foo(x: int) -> A \ # N: def foo(x: int, y: int) -> B \ @@ -2626,8 +2626,8 @@ def f(*xs: int) -> Tuple[int, ...]: ... def f(*args): pass i: int -reveal_type(f(i)) # N: Revealed type is "Tuple[builtins.int]" -reveal_type(f(i, i)) # N: Revealed type is "Tuple[builtins.int, builtins.int]" +reveal_type(f(i)) # N: Revealed type is "tuple[builtins.int]" +reveal_type(f(i, i)) # N: Revealed type is "tuple[builtins.int, builtins.int]" reveal_type(f(i, i, i)) # N: Revealed type is "builtins.tuple[builtins.int, ...]" reveal_type(f(*[])) # N: Revealed type is "builtins.tuple[builtins.int, ...]" @@ -2648,8 +2648,8 @@ def f(*args): pass i: int reveal_type(f(*())) # N: Revealed type is "builtins.tuple[builtins.int, ...]" -reveal_type(f(*(i,))) # N: Revealed type is "Tuple[builtins.int]" -reveal_type(f(*(i, i))) # N: Revealed type is "Tuple[builtins.int, builtins.int]" +reveal_type(f(*(i,))) # N: Revealed type is "tuple[builtins.int]" +reveal_type(f(*(i, i))) # N: Revealed type is "tuple[builtins.int, builtins.int]" reveal_type(f(*(i, i, i))) # N: Revealed type is "builtins.tuple[builtins.int, ...]" [builtins fixtures/tuple.pyi] @@ -2668,8 +2668,8 @@ C = NamedTuple('C', [('a', int), ('b', int), ('c', int)]) a: A b: B c: C -reveal_type(f(*a)) # N: Revealed type is "Tuple[builtins.int, builtins.int]" -reveal_type(f(*b)) # N: Revealed type is "Tuple[builtins.int, builtins.int]" +reveal_type(f(*a)) # N: Revealed type is "tuple[builtins.int, builtins.int]" +reveal_type(f(*b)) # N: Revealed type is "tuple[builtins.int, builtins.int]" reveal_type(f(*c)) # N: Revealed type is "builtins.tuple[builtins.int, ...]" [builtins fixtures/tuple.pyi] @@ -2708,8 +2708,8 @@ a: A b: B c: C -reveal_type(f(**a)) # N: Revealed type is "Tuple[builtins.int]" -reveal_type(f(**b)) # N: Revealed type is "Tuple[builtins.int, builtins.int]" +reveal_type(f(**a)) # N: Revealed type is "tuple[builtins.int]" +reveal_type(f(**b)) # N: Revealed type is "tuple[builtins.int, builtins.int]" reveal_type(f(**c)) # N: Revealed type is "builtins.tuple[builtins.int, ...]" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -3497,12 +3497,12 @@ def t_is_same_bound(arg1: T1, arg2: S) -> Tuple[T1, S]: x3: Union[List[S], List[Tuple[S, T1]]] y3: S Dummy[T1]().foo(x3, y3) # E: Cannot infer type argument 1 of "foo" of "Dummy" \ - # E: Argument 1 to "foo" of "Dummy" has incompatible type "Union[List[S], List[Tuple[S, T1]]]"; expected "List[Tuple[T1, Any]]" + # E: Argument 1 to "foo" of "Dummy" has incompatible type "Union[list[S], list[tuple[S, T1]]]"; expected "list[tuple[T1, Any]]" x4: Union[List[int], List[Tuple[C, int]]] y4: int reveal_type(Dummy[C]().foo(x4, y4)) # N: Revealed type is "Union[builtins.int, __main__.C]" - Dummy[A]().foo(x4, y4) # E: Argument 1 to "foo" of "Dummy" has incompatible type "Union[List[int], List[Tuple[C, int]]]"; expected "List[Tuple[A, int]]" + Dummy[A]().foo(x4, y4) # E: Argument 1 to "foo" of "Dummy" has incompatible type "Union[list[int], list[tuple[C, int]]]"; expected "list[tuple[A, int]]" return arg1, arg2 @@ -4264,7 +4264,7 @@ class Wrapper: @classmethod # E: Overloaded function implementation cannot produce return type of signature 1 def foo(cls, x: Union[int, str]) -> str: - reveal_type(cls) # N: Revealed type is "Type[__main__.Wrapper]" + reveal_type(cls) # N: Revealed type is "type[__main__.Wrapper]" reveal_type(cls.other()) # N: Revealed type is "builtins.str" return "..." @@ -4589,10 +4589,10 @@ class Child(Parent): def child_only(self) -> int: pass x: Union[int, str] -reveal_type(Parent.foo(3)) # N: Revealed type is "Type[__main__.Parent]" -reveal_type(Child.foo(3)) # N: Revealed type is "Type[__main__.Child]" +reveal_type(Parent.foo(3)) # N: Revealed type is "type[__main__.Parent]" +reveal_type(Child.foo(3)) # N: Revealed type is "type[__main__.Child]" reveal_type(Child.foo("...")) # N: Revealed type is "builtins.str" -reveal_type(Child.foo(x)) # N: Revealed type is "Union[Type[__main__.Child], builtins.str]" +reveal_type(Child.foo(x)) # N: Revealed type is "Union[type[__main__.Child], builtins.str]" reveal_type(Child.foo(3)().child_only()) # N: Revealed type is "builtins.int" [builtins fixtures/classmethod.pyi] @@ -5079,7 +5079,7 @@ a = multiple_plausible(Other()) # E: No overload variant of "multiple_plausible # N: def multiple_plausible(x: str) -> str reveal_type(a) # N: Revealed type is "Any" -b = single_plausible(Other) # E: Argument 1 to "single_plausible" has incompatible type "Type[Other]"; expected "Type[int]" +b = single_plausible(Other) # E: Argument 1 to "single_plausible" has incompatible type "type[Other]"; expected "type[int]" reveal_type(b) # N: Revealed type is "builtins.int" c = single_plausible([Other()]) # E: List item 0 has incompatible type "Other"; expected "str" diff --git a/test-data/unit/check-parameter-specification.test b/test-data/unit/check-parameter-specification.test index 6f01b15e11f6..085f6fe59809 100644 --- a/test-data/unit/check-parameter-specification.test +++ b/test-data/unit/check-parameter-specification.test @@ -1276,8 +1276,8 @@ def c3(f: Callable[P, int], *args, **kwargs) -> int: ... # It is ok to define, def c4(f: Callable[P, int], *args: int, **kwargs: str) -> int: # but not ok to call: - f(*args, **kwargs) # E: Argument 1 has incompatible type "*Tuple[int, ...]"; expected "P.args" \ - # E: Argument 2 has incompatible type "**Dict[str, str]"; expected "P.kwargs" + f(*args, **kwargs) # E: Argument 1 has incompatible type "*tuple[int, ...]"; expected "P.args" \ + # E: Argument 2 has incompatible type "**dict[str, str]"; expected "P.kwargs" return 1 def f1(f: Callable[P, int], *args, **kwargs: P.kwargs) -> int: ... # E: ParamSpec must have "*args" typed as "P.args" and "**kwargs" typed as "P.kwargs" @@ -1306,8 +1306,8 @@ def c3(f: Callable[Concatenate[int, P], int], *args, **kwargs) -> int: ... # It is ok to define, def c4(f: Callable[Concatenate[int, P], int], *args: int, **kwargs: str) -> int: # but not ok to call: - f(1, *args, **kwargs) # E: Argument 2 has incompatible type "*Tuple[int, ...]"; expected "P.args" \ - # E: Argument 3 has incompatible type "**Dict[str, str]"; expected "P.kwargs" + f(1, *args, **kwargs) # E: Argument 2 has incompatible type "*tuple[int, ...]"; expected "P.args" \ + # E: Argument 3 has incompatible type "**dict[str, str]"; expected "P.kwargs" return 1 def f1(f: Callable[Concatenate[int, P], int], *args, **kwargs: P.kwargs) -> int: ... # E: ParamSpec must have "*args" typed as "P.args" and "**kwargs" typed as "P.kwargs" @@ -2409,19 +2409,19 @@ def run2(func: Callable[Concatenate[int, P], T], *args: P.args, **kwargs: P.kwar func2 = partial(func, **kwargs) p = [""] func2(1, *p) # E: Too few arguments \ - # E: Argument 2 has incompatible type "*List[str]"; expected "P.args" + # E: Argument 2 has incompatible type "*list[str]"; expected "P.args" func2(1, 2, *p) # E: Too few arguments \ # E: Argument 2 has incompatible type "int"; expected "P.args" \ - # E: Argument 3 has incompatible type "*List[str]"; expected "P.args" - func2(1, *args, *p) # E: Argument 3 has incompatible type "*List[str]"; expected "P.args" - func2(1, *p, *args) # E: Argument 2 has incompatible type "*List[str]"; expected "P.args" + # E: Argument 3 has incompatible type "*list[str]"; expected "P.args" + func2(1, *args, *p) # E: Argument 3 has incompatible type "*list[str]"; expected "P.args" + func2(1, *p, *args) # E: Argument 2 has incompatible type "*list[str]"; expected "P.args" return func2(1, *args) def run3(func: Callable[Concatenate[int, P], T], *args: P.args, **kwargs: P.kwargs) -> T: func2 = partial(func, 1, *args) d = {"":""} func2(**d) # E: Too few arguments \ - # E: Argument 1 has incompatible type "**Dict[str, str]"; expected "P.kwargs" + # E: Argument 1 has incompatible type "**dict[str, str]"; expected "P.kwargs" return func2(**kwargs) def run4(func: Callable[Concatenate[int, P], T], *args: P.args, **kwargs: P.kwargs) -> T: @@ -2474,7 +2474,7 @@ def run(func: Callable[Concatenate[int, str, P], T], *args: P.args, **kwargs: P. func2(*args_prefix) # E: Too few arguments func2(*args, *args_prefix) # E: Argument 1 has incompatible type "*P.args"; expected "int" \ # E: Argument 1 has incompatible type "*P.args"; expected "str" \ - # E: Argument 2 has incompatible type "*Tuple[int, str]"; expected "P.args" + # E: Argument 2 has incompatible type "*tuple[int, str]"; expected "P.args" return func2(*args_prefix, *args) [builtins fixtures/paramspec.pyi] @@ -2599,7 +2599,7 @@ def run3(predicate: Callable[Concatenate[int, str, _P], None], *args: _P.args, * base_ok: tuple[int, str] predicate(*base_ok, *args, **kwargs) base_bad: tuple[Union[int, str], ...] - predicate(*base_bad, *args, **kwargs) # E: Argument 1 has incompatible type "*Tuple[Union[int, str], ...]"; expected "int" \ - # E: Argument 1 has incompatible type "*Tuple[Union[int, str], ...]"; expected "str" \ - # E: Argument 1 has incompatible type "*Tuple[Union[int, str], ...]"; expected "_P.args" + predicate(*base_bad, *args, **kwargs) # E: Argument 1 has incompatible type "*tuple[Union[int, str], ...]"; expected "int" \ + # E: Argument 1 has incompatible type "*tuple[Union[int, str], ...]"; expected "str" \ + # E: Argument 1 has incompatible type "*tuple[Union[int, str], ...]"; expected "_P.args" [builtins fixtures/paramspec.pyi] diff --git a/test-data/unit/check-plugin-attrs.test b/test-data/unit/check-plugin-attrs.test index c44854b7fc42..6415b5104296 100644 --- a/test-data/unit/check-plugin-attrs.test +++ b/test-data/unit/check-plugin-attrs.test @@ -31,7 +31,7 @@ class A: reveal_type(A) # N: Revealed type is "def (a: builtins.int, b: builtins.list[builtins.int], c: builtins.str =, d: builtins.int =) -> __main__.A" A(1, [2]) A(1, [2], '3', 4) -A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "List[int]" # E: Argument 3 to "A" has incompatible type "int"; expected "str" +A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "list[int]" # E: Argument 3 to "A" has incompatible type "int"; expected "str" A(1, [2], '3', 4, 5) # E: Too many arguments for "A" [builtins fixtures/list.pyi] @@ -49,7 +49,7 @@ class A: reveal_type(A) # N: Revealed type is "def (a: builtins.int, b: builtins.list[builtins.int], c: builtins.str =, d: builtins.int =) -> __main__.A" A(1, [2]) A(1, [2], '3', 4) -A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "List[int]" # E: Argument 3 to "A" has incompatible type "int"; expected "str" +A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "list[int]" # E: Argument 3 to "A" has incompatible type "int"; expected "str" A(1, [2], '3', 4, 5) # E: Too many arguments for "A" [builtins fixtures/list.pyi] @@ -67,7 +67,7 @@ class A: reveal_type(A) # N: Revealed type is "def (a: builtins.int, b: builtins.list[builtins.int], c: builtins.str =, d: builtins.int =) -> __main__.A" A(1, [2]) A(1, [2], '3', 4) -A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "List[int]" # E: Argument 3 to "A" has incompatible type "int"; expected "str" +A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "list[int]" # E: Argument 3 to "A" has incompatible type "int"; expected "str" A(1, [2], '3', 4, 5) # E: Too many arguments for "A" [builtins fixtures/list.pyi] @@ -120,7 +120,7 @@ class A: reveal_type(A) # N: Revealed type is "def (a: Any, b: builtins.list[builtins.int], c: Any =, d: Any =) -> __main__.A" A(1, [2]) A(1, [2], '3', 4) -A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "List[int]" +A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "list[int]" A(1, [2], '3', 4, 5) # E: Too many arguments for "A" [builtins fixtures/list.pyi] @@ -463,7 +463,7 @@ class A(Generic[T]): def bar(self) -> T: return self.x[0] def problem(self) -> T: - return self.x # E: Incompatible return value type (got "List[T]", expected "T") + return self.x # E: Incompatible return value type (got "list[T]", expected "T") reveal_type(A) # N: Revealed type is "def [T] (x: builtins.list[T`1], y: T`1) -> __main__.A[T`1]" a = A([1], 2) reveal_type(a) # N: Revealed type is "__main__.A[builtins.int]" @@ -495,7 +495,7 @@ class A(Generic[T]): def bar(self) -> T: return self.x[0] def problem(self) -> T: - return self.x # E: Incompatible return value type (got "List[T]", expected "T") + return self.x # E: Incompatible return value type (got "list[T]", expected "T") reveal_type(A) # N: Revealed type is "def [T] (x: typing.Iterable[T`1], y: T`1) -> __main__.A[T`1]" a1 = A([1], 2) reveal_type(a1) # N: Revealed type is "__main__.A[builtins.int]" @@ -668,7 +668,7 @@ class A(Generic[T]): x: Optional[T] @classmethod def clsmeth(cls) -> None: - reveal_type(cls) # N: Revealed type is "Type[__main__.A[T`1]]" + reveal_type(cls) # N: Revealed type is "type[__main__.A[T`1]]" [builtins fixtures/classmethod.pyi] @@ -723,7 +723,7 @@ class A: b: str = attr.ib() @classmethod def new(cls) -> A: - reveal_type(cls) # N: Revealed type is "Type[__main__.A]" + reveal_type(cls) # N: Revealed type is "type[__main__.A]" return cls(6, 'hello') @classmethod def bad(cls) -> A: @@ -758,7 +758,7 @@ class A: @classmethod def foo(cls, x: Union[int, str]) -> Union[int, str]: - reveal_type(cls) # N: Revealed type is "Type[__main__.A]" + reveal_type(cls) # N: Revealed type is "type[__main__.A]" reveal_type(cls.other()) # N: Revealed type is "builtins.str" return x @@ -1207,7 +1207,7 @@ def my_factory() -> int: return 7 @attr.s class A: - x: int = attr.ib(factory=list) # E: Incompatible types in assignment (expression has type "List[Never]", variable has type "int") + x: int = attr.ib(factory=list) # E: Incompatible types in assignment (expression has type "list[Never]", variable has type "int") y: str = attr.ib(factory=my_factory) # E: Incompatible types in assignment (expression has type "int", variable has type "str") [builtins fixtures/list.pyi] @@ -1518,7 +1518,7 @@ class A: b: int = attr.ib() c: str = attr.ib() -reveal_type(A.__attrs_attrs__) # N: Revealed type is "Tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]" +reveal_type(A.__attrs_attrs__) # N: Revealed type is "tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]" reveal_type(A.__attrs_attrs__[0]) # N: Revealed type is "attr.Attribute[builtins.int]" reveal_type(A.__attrs_attrs__.b) # N: Revealed type is "attr.Attribute[builtins.int]" A.__attrs_attrs__.x # E: "____main___A_AttrsAttributes__" has no attribute "x" @@ -1533,7 +1533,7 @@ class A: b = attr.ib() c = attr.ib() -reveal_type(A.__attrs_attrs__) # N: Revealed type is "Tuple[attr.Attribute[Any], attr.Attribute[Any], fallback=__main__.A.____main___A_AttrsAttributes__]" +reveal_type(A.__attrs_attrs__) # N: Revealed type is "tuple[attr.Attribute[Any], attr.Attribute[Any], fallback=__main__.A.____main___A_AttrsAttributes__]" reveal_type(A.__attrs_attrs__[0]) # N: Revealed type is "attr.Attribute[Any]" reveal_type(A.__attrs_attrs__.b) # N: Revealed type is "attr.Attribute[Any]" A.__attrs_attrs__.x # E: "____main___A_AttrsAttributes__" has no attribute "x" @@ -1548,7 +1548,7 @@ class A: b: int c: str -reveal_type(A.__attrs_attrs__) # N: Revealed type is "Tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]" +reveal_type(A.__attrs_attrs__) # N: Revealed type is "tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]" reveal_type(A.__attrs_attrs__[0]) # N: Revealed type is "attr.Attribute[builtins.int]" reveal_type(A.__attrs_attrs__.b) # N: Revealed type is "attr.Attribute[builtins.int]" A.__attrs_attrs__.x # E: "____main___A_AttrsAttributes__" has no attribute "x" @@ -1576,8 +1576,8 @@ def takes_attrs_instance(inst: AttrsInstance) -> None: takes_attrs_cls(A) takes_attrs_instance(A(1, "")) -takes_attrs_cls(A(1, "")) # E: Argument 1 to "takes_attrs_cls" has incompatible type "A"; expected "Type[AttrsInstance]" -takes_attrs_instance(A) # E: Argument 1 to "takes_attrs_instance" has incompatible type "Type[A]"; expected "AttrsInstance" # N: ClassVar protocol member AttrsInstance.__attrs_attrs__ can never be matched by a class object +takes_attrs_cls(A(1, "")) # E: Argument 1 to "takes_attrs_cls" has incompatible type "A"; expected "type[AttrsInstance]" +takes_attrs_instance(A) # E: Argument 1 to "takes_attrs_instance" has incompatible type "type[A]"; expected "AttrsInstance" # N: ClassVar protocol member AttrsInstance.__attrs_attrs__ can never be matched by a class object [builtins fixtures/plugin_attrs.pyi] [case testAttrsFields] @@ -1589,7 +1589,7 @@ class A: b: int c: str -reveal_type(f(A)) # N: Revealed type is "Tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]" +reveal_type(f(A)) # N: Revealed type is "tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]" reveal_type(f(A)[0]) # N: Revealed type is "attr.Attribute[builtins.int]" reveal_type(f(A).b) # N: Revealed type is "attr.Attribute[builtins.int]" f(A).x # E: "____main___A_AttrsAttributes__" has no attribute "x" @@ -1613,7 +1613,7 @@ class A: TA = TypeVar('TA', bound=A) def f(t: TA) -> None: - reveal_type(fields(t)) # N: Revealed type is "Tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]" + reveal_type(fields(t)) # N: Revealed type is "tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]" reveal_type(fields(t)[0]) # N: Revealed type is "attr.Attribute[builtins.int]" reveal_type(fields(t).b) # N: Revealed type is "attr.Attribute[builtins.int]" fields(t).x # E: "____main___A_AttrsAttributes__" has no attribute "x" @@ -1632,8 +1632,8 @@ class A: if has(A): fields(A) else: - fields(A) # E: Argument 1 to "fields" has incompatible type "Type[A]"; expected "Type[AttrsInstance]" -fields(None) # E: Argument 1 to "fields" has incompatible type "None"; expected "Type[AttrsInstance]" + fields(A) # E: Argument 1 to "fields" has incompatible type "type[A]"; expected "type[AttrsInstance]" +fields(None) # E: Argument 1 to "fields" has incompatible type "None"; expected "type[AttrsInstance]" fields(cast(Any, 42)) fields(cast(Type[Any], 43)) @@ -1651,8 +1651,8 @@ class A: b, c = bc self.__attrs_init__(b, c) -reveal_type(A) # N: Revealed type is "def (bc: Tuple[builtins.int, builtins.str]) -> __main__.A" -reveal_type(A.__init__) # N: Revealed type is "def (self: __main__.A, bc: Tuple[builtins.int, builtins.str])" +reveal_type(A) # N: Revealed type is "def (bc: tuple[builtins.int, builtins.str]) -> __main__.A" +reveal_type(A.__init__) # N: Revealed type is "def (self: __main__.A, bc: tuple[builtins.int, builtins.str])" reveal_type(A.__attrs_init__) # N: Revealed type is "def (self: __main__.A, b: builtins.int, c: builtins.str)" [builtins fixtures/plugin_attrs.pyi] @@ -1729,14 +1729,14 @@ class Some: y: str z: bool -reveal_type(Some.__slots__) # N: Revealed type is "Tuple[builtins.str, builtins.str, builtins.str]" +reveal_type(Some.__slots__) # N: Revealed type is "tuple[builtins.str, builtins.str, builtins.str]" @dataclass(slots=True) class Other: x: int y: str -reveal_type(Other.__slots__) # N: Revealed type is "Tuple[builtins.str, builtins.str]" +reveal_type(Other.__slots__) # N: Revealed type is "tuple[builtins.str, builtins.str]" @dataclass @@ -1744,7 +1744,7 @@ class NoSlots: x: int y: str -NoSlots.__slots__ # E: "Type[NoSlots]" has no attribute "__slots__" +NoSlots.__slots__ # E: "type[NoSlots]" has no attribute "__slots__" [builtins fixtures/plugin_attrs.pyi] [case testAttrsWithMatchArgs] @@ -1759,8 +1759,8 @@ class ToMatch: z: int = attr.field(kw_only=True) i: int = attr.field(init=False) -reveal_type(ToMatch(x=1, y=2, z=3).__match_args__) # N: Revealed type is "Tuple[Literal['x']?, Literal['y']?]" -reveal_type(ToMatch(1, 2, z=3).__match_args__) # N: Revealed type is "Tuple[Literal['x']?, Literal['y']?]" +reveal_type(ToMatch(x=1, y=2, z=3).__match_args__) # N: Revealed type is "tuple[Literal['x']?, Literal['y']?]" +reveal_type(ToMatch(1, 2, z=3).__match_args__) # N: Revealed type is "tuple[Literal['x']?, Literal['y']?]" [builtins fixtures/plugin_attrs.pyi] [case testAttrsWithMatchArgsDefaultCase] @@ -1773,7 +1773,7 @@ class ToMatch1: y: int t1: ToMatch1 -reveal_type(t1.__match_args__) # N: Revealed type is "Tuple[Literal['x']?, Literal['y']?]" +reveal_type(t1.__match_args__) # N: Revealed type is "tuple[Literal['x']?, Literal['y']?]" @attr.define class ToMatch2: @@ -1781,7 +1781,7 @@ class ToMatch2: y: int t2: ToMatch2 -reveal_type(t2.__match_args__) # N: Revealed type is "Tuple[Literal['x']?, Literal['y']?]" +reveal_type(t2.__match_args__) # N: Revealed type is "tuple[Literal['x']?, Literal['y']?]" [builtins fixtures/plugin_attrs.pyi] [case testAttrsWithMatchArgsOverrideExisting] @@ -1796,7 +1796,7 @@ class ToMatch: y: int # It works the same way runtime does: -reveal_type(ToMatch(x=1, y=2).__match_args__) # N: Revealed type is "Tuple[Literal['a']?, Literal['b']?]" +reveal_type(ToMatch(x=1, y=2).__match_args__) # N: Revealed type is "tuple[Literal['a']?, Literal['b']?]" @attr.s(auto_attribs=True) class WithoutMatch: @@ -1804,7 +1804,7 @@ class WithoutMatch: x: int y: int -reveal_type(WithoutMatch(x=1, y=2).__match_args__) # N: Revealed type is "Tuple[Literal['a']?, Literal['b']?]" +reveal_type(WithoutMatch(x=1, y=2).__match_args__) # N: Revealed type is "tuple[Literal['a']?, Literal['b']?]" [builtins fixtures/plugin_attrs.pyi] [case testAttrsWithMatchArgsOldVersion] @@ -2172,7 +2172,7 @@ class B: a_or_b: A[int] | B a2 = attrs.evolve(a_or_b, x=42, y=True) a2 = attrs.evolve(a_or_b, x=42, y=True, z='42') # E: Argument "z" to "evolve" of "Union[A[int], B]" has incompatible type "str"; expected "Never" -a2 = attrs.evolve(a_or_b, x=42, y=True, w={}) # E: Argument "w" to "evolve" of "Union[A[int], B]" has incompatible type "Dict[Never, Never]"; expected "Never" +a2 = attrs.evolve(a_or_b, x=42, y=True, w={}) # E: Argument "w" to "evolve" of "Union[A[int], B]" has incompatible type "dict[Never, Never]"; expected "Never" [builtins fixtures/plugin_attrs.pyi] diff --git a/test-data/unit/check-protocols.test b/test-data/unit/check-protocols.test index 34e3f3e88080..7f11774fbfff 100644 --- a/test-data/unit/check-protocols.test +++ b/test-data/unit/check-protocols.test @@ -715,7 +715,7 @@ c: C var: P2[int, int] = c var2: P2[int, str] = c # E: Incompatible types in assignment (expression has type "C", variable has type "P2[int, str]") \ # N: Following member(s) of "C" have conflicts: \ - # N: attr2: expected "Tuple[int, str]", got "Tuple[int, int]" + # N: attr2: expected "tuple[int, str]", got "tuple[int, int]" class D(Generic[T]): attr1: T @@ -973,7 +973,7 @@ class B: t: P1 t = A() # E: Incompatible types in assignment (expression has type "A", variable has type "P1") \ # N: Following member(s) of "A" have conflicts: \ - # N: attr1: expected "Sequence[P2]", got "List[B]" + # N: attr1: expected "Sequence[P2]", got "list[B]" [builtins fixtures/list.pyi] [case testMutuallyRecursiveProtocolsTypesWithSubteMismatchWriteable] @@ -1607,13 +1607,13 @@ def f(cls: Type[P]) -> P: def g() -> P: return P() # E: Cannot instantiate protocol class "P" -f(P) # E: Only concrete class can be given where "Type[P]" is expected +f(P) # E: Only concrete class can be given where "type[P]" is expected f(B) # OK f(C) # OK x: Type[P1] xbad: Type[Pbad] f(x) # OK -f(xbad) # E: Argument 1 to "f" has incompatible type "Type[Pbad]"; expected "Type[P]" +f(xbad) # E: Argument 1 to "f" has incompatible type "type[Pbad]"; expected "type[P]" [case testInstantiationProtocolInTypeForAliases] from typing import Type, Protocol @@ -1631,7 +1631,7 @@ Alias = P GoodAlias = C Alias() # E: Cannot instantiate protocol class "P" GoodAlias() -f(Alias) # E: Only concrete class can be given where "Type[P]" is expected +f(Alias) # E: Only concrete class can be given where "type[P]" is expected f(GoodAlias) [case testInstantiationProtocolInTypeForVariables] @@ -1648,14 +1648,14 @@ class C: var: Type[P] var() if int(): - var = P # E: Can only assign concrete classes to a variable of type "Type[P]" + var = P # E: Can only assign concrete classes to a variable of type "type[P]" var = B # OK var = C # OK var_old = None # type: Type[P] # Old syntax for variable annotations var_old() if int(): - var_old = P # E: Can only assign concrete classes to a variable of type "Type[P]" + var_old = P # E: Can only assign concrete classes to a variable of type "type[P]" var_old = B # OK var_old = C # OK @@ -1825,7 +1825,7 @@ def f(x: MyProto[int]) -> None: f(t) # OK y: MyProto[str] -y = t # E: Incompatible types in assignment (expression has type "Tuple[int, str]", variable has type "MyProto[str]") +y = t # E: Incompatible types in assignment (expression has type "tuple[int, str]", variable has type "MyProto[str]") [builtins fixtures/isinstancelist.pyi] [case testBasicNamedTupleStructuralSubtyping] @@ -1943,7 +1943,7 @@ class Actual: def __call__(self, arg: int) -> str: pass def fun(cb: Callable[[T], S]) -> Tuple[T, S]: pass -reveal_type(fun(Actual())) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(fun(Actual())) # N: Revealed type is "tuple[builtins.int, builtins.str]" [builtins fixtures/tuple.pyi] -- Standard protocol types (SupportsInt, Sized, etc.) @@ -2439,9 +2439,9 @@ cls: Type[Union[C, E]] issubclass(cls, PBad) # E: Only protocols that don't have non-method members can be used with issubclass() \ # N: Protocol "PBad" has non-method member(s): x if issubclass(cls, P): - reveal_type(cls) # N: Revealed type is "Type[__main__.C]" + reveal_type(cls) # N: Revealed type is "type[__main__.C]" else: - reveal_type(cls) # N: Revealed type is "Type[__main__.E]" + reveal_type(cls) # N: Revealed type is "type[__main__.E]" @runtime_checkable class POverload(Protocol): @@ -2491,7 +2491,7 @@ def call(x: int, y: str) -> Tuple[int, str]: ... def func(caller: Caller[T, S]) -> Tuple[T, S]: pass -reveal_type(func(call)) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(func(call)) # N: Revealed type is "tuple[builtins.int, builtins.str]" [builtins fixtures/tuple.pyi] [out] @@ -2531,7 +2531,7 @@ 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" \ +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]" [builtins fixtures/tuple.pyi] [out] @@ -2711,7 +2711,7 @@ class A(Protocol[T, S]): def f() -> int: ... def test(func: A[T, S]) -> Tuple[T, S]: ... -reveal_type(test(f)) # N: Revealed type is "Tuple[builtins.str, builtins.int]" +reveal_type(test(f)) # N: Revealed type is "tuple[builtins.str, builtins.int]" [builtins fixtures/tuple.pyi] [case testProtocolsAlwaysABCs] @@ -2917,7 +2917,7 @@ class Blooper: reveal_type([self, x]) # N: Revealed type is "builtins.list[builtins.object]" class Gleemer: - flap = [] # E: Need type annotation for "flap" (hint: "flap: List[] = ...") + flap = [] # E: Need type annotation for "flap" (hint: "flap: list[] = ...") def gleem(self, x: Flapper) -> None: reveal_type([self, x]) # N: Revealed type is "builtins.list[builtins.object]" @@ -3287,7 +3287,7 @@ class C: def foo(t: Template) -> None: ... foo(B()) # E: Argument 1 to "foo" has incompatible type "B"; expected "Template" \ # N: Following member(s) of "B" have conflicts: \ - # N: Meta: expected "Type[__main__.Template.Meta]", got "Type[__main__.B.Meta]" + # N: Meta: expected "type[__main__.Template.Meta]", got "type[__main__.B.Meta]" foo(C()) # OK [case testProtocolClassObjectAttribute] @@ -3308,10 +3308,10 @@ class D: def test(arg: P) -> None: ... test(A) # OK test(B) # OK -test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(C) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: Following member(s) of "C" have conflicts: \ # N: foo: expected "int", got "str" -test(D) # E: Argument 1 to "test" has incompatible type "Type[D]"; expected "P" \ +test(D) # E: Argument 1 to "test" has incompatible type "type[D]"; expected "P" \ # N: Only class variables allowed for class object access on protocols, foo is an instance variable of "D" [case testProtocolClassObjectClassVarRejected] @@ -3324,7 +3324,7 @@ class B: foo: ClassVar[int] def test(arg: P) -> None: ... -test(B) # E: Argument 1 to "test" has incompatible type "Type[B]"; expected "P" \ +test(B) # E: Argument 1 to "test" has incompatible type "type[B]"; expected "P" \ # N: ClassVar protocol member P.foo can never be matched by a class object [case testProtocolClassObjectPropertyRejected] @@ -3344,11 +3344,11 @@ class D: 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" \ +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: 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" \ +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" test(D) # OK [builtins fixtures/property.pyi] @@ -3366,7 +3366,7 @@ class C: def test(arg: P) -> None: ... test(B) # OK -test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(C) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ # N: def foo(obj: Any) -> int \ @@ -3386,7 +3386,7 @@ class C: def test(arg: P) -> None: ... test(B) # OK -test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(C) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ # N: def foo(obj: B) -> int \ @@ -3420,7 +3420,7 @@ class C: def test(arg: P) -> None: ... test(B) # OK -test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(C) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ # N: @overload \ @@ -3448,7 +3448,7 @@ class C: def test(arg: P) -> None: ... test(B) # OK -test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(C) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ # N: def foo() -> int \ @@ -3471,7 +3471,7 @@ class C: def test(arg: P) -> None: ... test(B) # OK -test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(C) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ # N: def foo() -> int \ @@ -3495,12 +3495,12 @@ class C(AA[str]): ... def test(arg: P) -> None: ... test(B) # OK -test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(C) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ - # N: def foo(obj: Any) -> List[int] \ + # N: def foo(obj: Any) -> list[int] \ # N: Got: \ - # N: def foo(self: A[List[str]]) -> List[str] + # N: def foo(self: A[list[str]]) -> list[str] [builtins fixtures/list.pyi] [case testProtocolClassObjectGenericClassMethod] @@ -3520,12 +3520,12 @@ class C(AA[str]): ... def test(arg: P) -> None: ... test(B) # OK -test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(C) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ - # N: def foo() -> List[int] \ + # N: def foo() -> list[int] \ # N: Got: \ - # N: def foo() -> List[str] + # N: def foo() -> list[str] [builtins fixtures/isinstancelist.pyi] [case testProtocolClassObjectSelfTypeInstanceMethod] @@ -3542,7 +3542,7 @@ class C: def test(arg: P) -> None: ... test(B) # OK -test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(C) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ # N: def [T] foo(arg: T) -> T \ @@ -3565,7 +3565,7 @@ class C: def test(arg: P) -> None: ... test(B) # OK -test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(C) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ # N: def foo() -> B \ @@ -3589,7 +3589,7 @@ class C: def test(arg: P) -> None: ... test(B) # OK -test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(C) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: "C" has constructor incompatible with "__call__" of "P" \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ @@ -3611,7 +3611,7 @@ class C: def test(arg: P) -> None: ... test(B) # OK -test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(C) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: "C" has constructor incompatible with "__call__" of "P" \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ @@ -3635,7 +3635,7 @@ class C: def __call__(self, el: str) -> None: return None -p: P = C # E: Incompatible types in assignment (expression has type "Type[C]", variable has type "P") \ +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] \ @@ -3667,10 +3667,10 @@ c: Type[C] d: Type[D] test(a) # OK test(b) # OK -test(c) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(c) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: Following member(s) of "C" have conflicts: \ # N: foo: expected "int", got "str" -test(d) # E: Argument 1 to "test" has incompatible type "Type[D]"; expected "P" \ +test(d) # E: Argument 1 to "test" has incompatible type "type[D]"; expected "P" \ # N: Only class variables allowed for class object access on protocols, foo is an instance variable of "D" [case testProtocolTypeTypeInstanceMethod] @@ -3688,7 +3688,7 @@ def test(arg: P) -> None: ... b: Type[B] c: Type[C] test(b) # OK -test(c) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(c) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ # N: def foo(cls: Any) -> int \ @@ -3712,7 +3712,7 @@ def test(arg: P) -> None: ... b: Type[B] c: Type[C] test(b) # OK -test(c) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(c) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ # N: def foo() -> int \ @@ -3736,7 +3736,7 @@ def test(arg: P) -> None: ... b: Type[B] c: Type[C] test(b) # OK -test(c) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P" \ +test(c) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P" \ # N: Following member(s) of "C" have conflicts: \ # N: Expected: \ # N: def [T] foo(arg: T) -> T \ diff --git a/test-data/unit/check-python310.test b/test-data/unit/check-python310.test index af3982f6accd..fdf6b25f3591 100644 --- a/test-data/unit/check-python310.test +++ b/test-data/unit/check-python310.test @@ -240,7 +240,7 @@ match m: reveal_type(a) # N: Revealed type is "builtins.int" reveal_type(b) # N: Revealed type is "builtins.str" reveal_type(c) # N: Revealed type is "builtins.bool" - reveal_type(m) # N: Revealed type is "Tuple[builtins.int, builtins.str, builtins.bool]" + reveal_type(m) # N: Revealed type is "tuple[builtins.int, builtins.str, builtins.bool]" [builtins fixtures/list.pyi] [case testMatchSequencePatternTupleTooLong] @@ -270,7 +270,7 @@ m: Tuple[object, object] match m: case [1, "str"]: - reveal_type(m) # N: Revealed type is "Tuple[Literal[1], Literal['str']]" + reveal_type(m) # N: Revealed type is "tuple[Literal[1], Literal['str']]" [builtins fixtures/list.pyi] [case testMatchSequencePatternTupleStarred] @@ -282,7 +282,7 @@ match m: reveal_type(a) # N: Revealed type is "builtins.int" reveal_type(b) # N: Revealed type is "builtins.list[builtins.str]" reveal_type(c) # N: Revealed type is "builtins.bool" - reveal_type(m) # N: Revealed type is "Tuple[builtins.int, builtins.str, builtins.bool]" + reveal_type(m) # N: Revealed type is "tuple[builtins.int, builtins.str, builtins.bool]" [builtins fixtures/list.pyi] [case testMatchSequencePatternTupleStarredUnion] @@ -294,13 +294,13 @@ match m: reveal_type(a) # N: Revealed type is "builtins.int" reveal_type(b) # N: Revealed type is "builtins.list[Union[builtins.str, builtins.float]]" reveal_type(c) # N: Revealed type is "builtins.bool" - reveal_type(m) # N: Revealed type is "Tuple[builtins.int, builtins.str, builtins.float, builtins.bool]" + reveal_type(m) # N: Revealed type is "tuple[builtins.int, builtins.str, builtins.float, builtins.bool]" [builtins fixtures/list.pyi] [case testMatchSequencePatternTupleStarredTooShort] from typing import Tuple m: Tuple[int] -reveal_type(m) # N: Revealed type is "Tuple[builtins.int]" +reveal_type(m) # N: Revealed type is "tuple[builtins.int]" match m: case [a, *b, c]: @@ -326,7 +326,7 @@ class Example: SubClass: type[Example] match [SubClass("a"), SubClass("b")]: - case [SubClass(value), *rest]: # E: Expected type in class pattern; found "Type[__main__.Example]" + case [SubClass(value), *rest]: # E: Expected type in class pattern; found "type[__main__.Example]" reveal_type(value) # E: Cannot determine type of "value" \ # N: Revealed type is "Any" reveal_type(rest) # N: Revealed type is "builtins.list[__main__.Example]" @@ -1519,43 +1519,43 @@ m2: Tuple[int | str] match m2: case (int(),): - reveal_type(m2) # N: Revealed type is "Tuple[builtins.int]" + reveal_type(m2) # N: Revealed type is "tuple[builtins.int]" case r2: - reveal_type(m2) # N: Revealed type is "Tuple[builtins.str]" + reveal_type(m2) # N: Revealed type is "tuple[builtins.str]" m3: Tuple[Union[int, str]] match m3: case (1,): - reveal_type(m3) # N: Revealed type is "Tuple[Literal[1]]" + reveal_type(m3) # N: Revealed type is "tuple[Literal[1]]" case r2: - reveal_type(m3) # N: Revealed type is "Tuple[Union[builtins.int, builtins.str]]" + reveal_type(m3) # N: Revealed type is "tuple[Union[builtins.int, builtins.str]]" m4: Tuple[Literal[1], int] match m4: case (1, 5): - reveal_type(m4) # N: Revealed type is "Tuple[Literal[1], Literal[5]]" + reveal_type(m4) # N: Revealed type is "tuple[Literal[1], Literal[5]]" case (1, 6): - reveal_type(m4) # N: Revealed type is "Tuple[Literal[1], Literal[6]]" + reveal_type(m4) # N: Revealed type is "tuple[Literal[1], Literal[6]]" case _: - reveal_type(m4) # N: Revealed type is "Tuple[Literal[1], builtins.int]" + reveal_type(m4) # N: Revealed type is "tuple[Literal[1], builtins.int]" m5: Tuple[Literal[1, 2], Literal["a", "b"]] match m5: case (1, str()): - reveal_type(m5) # N: Revealed type is "Tuple[Literal[1], Union[Literal['a'], Literal['b']]]" + reveal_type(m5) # N: Revealed type is "tuple[Literal[1], Union[Literal['a'], Literal['b']]]" case _: - reveal_type(m5) # N: Revealed type is "Tuple[Literal[2], Union[Literal['a'], Literal['b']]]" + reveal_type(m5) # N: Revealed type is "tuple[Literal[2], Union[Literal['a'], Literal['b']]]" m6: Tuple[Literal[1, 2], Literal["a", "b"]] match m6: case (1, "a"): - reveal_type(m6) # N: Revealed type is "Tuple[Literal[1], Literal['a']]" + reveal_type(m6) # N: Revealed type is "tuple[Literal[1], Literal['a']]" case _: - reveal_type(m6) # N: Revealed type is "Tuple[Union[Literal[1], Literal[2]], Union[Literal['a'], Literal['b']]]" + reveal_type(m6) # N: Revealed type is "tuple[Union[Literal[1], Literal[2]], Union[Literal['a'], Literal['b']]]" [builtins fixtures/tuple.pyi] @@ -1896,9 +1896,9 @@ class AnnAssign(stmt): value: str simple: int -reveal_type(AST.__match_args__) # N: Revealed type is "Tuple[()]" -reveal_type(stmt.__match_args__) # N: Revealed type is "Tuple[()]" -reveal_type(AnnAssign.__match_args__) # N: Revealed type is "Tuple[Literal['target']?, Literal['annotation']?, Literal['value']?, Literal['simple']?]" +reveal_type(AST.__match_args__) # N: Revealed type is "tuple[()]" +reveal_type(stmt.__match_args__) # N: Revealed type is "tuple[()]" +reveal_type(AnnAssign.__match_args__) # N: Revealed type is "tuple[Literal['target']?, Literal['annotation']?, Literal['value']?, Literal['simple']?]" AnnAssign.__match_args__ = ('a', 'b', 'c', 'd') # E: Cannot assign to "__match_args__" __match_args__ = 0 @@ -2041,12 +2041,12 @@ S = TypeVar("S", int, str) def my_func(pairs: Iterable[tuple[S, S]]) -> None: for pair in pairs: - reveal_type(pair) # N: Revealed type is "Tuple[builtins.int, builtins.int]" \ - # N: Revealed type is "Tuple[builtins.str, builtins.str]" + reveal_type(pair) # N: Revealed type is "tuple[builtins.int, builtins.int]" \ + # N: Revealed type is "tuple[builtins.str, builtins.str]" match pair: case _: - reveal_type(pair) # N: Revealed type is "Tuple[builtins.int, builtins.int]" \ - # N: Revealed type is "Tuple[builtins.str, builtins.str]" + reveal_type(pair) # N: Revealed type is "tuple[builtins.int, builtins.int]" \ + # N: Revealed type is "tuple[builtins.str, builtins.str]" [builtins fixtures/tuple.pyi] [case testPossiblyUndefinedMatch] @@ -2236,7 +2236,7 @@ def match_stmt_error4(x: Optional[list[str]]) -> None: if x is None: x = ["a"] def nested() -> list[str]: - return x # E: Incompatible return value type (got "Optional[List[str]]", expected "List[str]") + return x # E: Incompatible return value type (got "Optional[list[str]]", expected "list[str]") match ["a"]: case [*x]: pass @@ -2542,8 +2542,8 @@ from typing import Literal def x() -> tuple[Literal["test"]]: ... match x(): - case (x,) if x == "test": # E: Incompatible types in capture pattern (pattern captures type "Literal['test']", variable has type "Callable[[], Tuple[Literal['test']]]") - reveal_type(x) # N: Revealed type is "def () -> Tuple[Literal['test']]" + case (x,) if x == "test": # E: Incompatible types in capture pattern (pattern captures type "Literal['test']", variable has type "Callable[[], tuple[Literal['test']]]") + reveal_type(x) # N: Revealed type is "def () -> tuple[Literal['test']]" case foo: foo @@ -2598,7 +2598,7 @@ class K(NamedTuple): def f(t: T) -> None: match t: case T([K() as k]): - reveal_type(k) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.K]" + reveal_type(k) # N: Revealed type is "tuple[builtins.int, fallback=__main__.K]" [builtins fixtures/tuple.pyi] [case testNewRedefineMatchBasics] diff --git a/test-data/unit/check-python311.test b/test-data/unit/check-python311.test index c6d42660403e..09c8d6082365 100644 --- a/test-data/unit/check-python311.test +++ b/test-data/unit/check-python311.test @@ -81,9 +81,9 @@ reveal_type(coro) # N: Revealed type is "def () -> typing.Coroutine[Any, Any, t [case testTypeVarTupleNewSyntaxAnnotations] Ints = tuple[int, int, int] x: tuple[str, *Ints] -reveal_type(x) # N: Revealed type is "Tuple[builtins.str, builtins.int, builtins.int, builtins.int]" +reveal_type(x) # N: Revealed type is "tuple[builtins.str, builtins.int, builtins.int, builtins.int]" y: tuple[int, *tuple[int, ...]] -reveal_type(y) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]]]" +reveal_type(y) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]]]" [builtins fixtures/tuple.pyi] [case testTypeVarTupleNewSyntaxGenerics] @@ -95,8 +95,8 @@ class C(Generic[T, *Ts]): attr: tuple[int, *Ts, str] def test(self) -> None: - reveal_type(self.attr) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`2], builtins.str]" - self.attr = ci # E: Incompatible types in assignment (expression has type "C[*Tuple[int, ...]]", variable has type "Tuple[int, *Ts, str]") + reveal_type(self.attr) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`2], builtins.str]" + self.attr = ci # E: Incompatible types in assignment (expression has type "C[*tuple[int, ...]]", variable has type "tuple[int, *Ts, str]") def meth(self, *args: *Ts) -> T: ... ci: C[*tuple[int, ...]] @@ -135,11 +135,11 @@ myclass1 = MyClass(float) reveal_type(myclass1) # N: Revealed type is "__main__.MyClass[builtins.float, None]" myclass2 = MyClass(float, float) reveal_type(myclass2) # N: Revealed type is "__main__.MyClass[builtins.float, builtins.float]" -myclass3 = MyClass(float, float, float) # E: No overload variant of "MyClass" matches argument types "Type[float]", "Type[float]", "Type[float]" \ +myclass3 = MyClass(float, float, float) # E: No overload variant of "MyClass" matches argument types "type[float]", "type[float]", "type[float]" \ # N: Possible overload variants: \ # N: def [T1, T2] __init__(self) -> MyClass[None, None] \ - # N: def [T1, T2] __init__(self, Type[T1], /) -> MyClass[T1, None] \ - # N: def [T1, T2] __init__(Type[T1], Type[T2], /) -> MyClass[T1, T2] + # N: def [T1, T2] __init__(self, type[T1], /) -> MyClass[T1, None] \ + # N: def [T1, T2] __init__(type[T1], type[T2], /) -> MyClass[T1, T2] reveal_type(myclass3) # N: Revealed type is "Any" [builtins fixtures/tuple.pyi] @@ -169,7 +169,7 @@ x3: Alias3[int] # E: Bad number of arguments for type alias, expected 0, given reveal_type(x3) # N: Revealed type is "def (*Any) -> builtins.int" IntList = List[int] -Alias4 = Callable[[*IntList], int] # E: "List[int]" cannot be unpacked (must be tuple or TypeVarTuple) +Alias4 = Callable[[*IntList], int] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) x4: Alias4[int] # E: Bad number of arguments for type alias, expected 0, given 1 reveal_type(x4) # N: Revealed type is "def (*Any) -> builtins.int" [builtins fixtures/tuple.pyi] diff --git a/test-data/unit/check-python312.test b/test-data/unit/check-python312.test index 2244548ea969..70ab59eb28e4 100644 --- a/test-data/unit/check-python312.test +++ b/test-data/unit/check-python312.test @@ -90,10 +90,10 @@ reveal_type(ident('x')) # N: Revealed type is "builtins.str" a: TV # E: Name "TV" is not defined def tup[T, S](x: T, y: S) -> tuple[T, S]: - reveal_type((x, y)) # N: Revealed type is "Tuple[T`-1, S`-2]" + reveal_type((x, y)) # N: Revealed type is "tuple[T`-1, S`-2]" return (x, y) -reveal_type(tup(1, 'x')) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(tup(1, 'x')) # N: Revealed type is "tuple[builtins.int, builtins.str]" [builtins fixtures/tuple.pyi] [case testPEP695GenericClassSyntax] @@ -910,10 +910,10 @@ reveal_type(f) # N: Revealed type is "def (builtins.str, Union[builtins.int, No [case testPEP695TypeVarTuple] def f[*Ts](t: tuple[*Ts]) -> tuple[*Ts]: - reveal_type(t) # N: Revealed type is "Tuple[Unpack[Ts`-1]]" + reveal_type(t) # N: Revealed type is "tuple[Unpack[Ts`-1]]" return t -reveal_type(f((1, 'x'))) # N: Revealed type is "Tuple[Literal[1]?, Literal['x']?]" +reveal_type(f((1, 'x'))) # N: Revealed type is "tuple[Literal[1]?, Literal['x']?]" a: tuple[int, ...] reveal_type(f(a)) # N: Revealed type is "builtins.tuple[builtins.int, ...]" @@ -933,7 +933,7 @@ from typing import Callable type C[*Ts] = tuple[*Ts, int] a: C[str, None] -reveal_type(a) # N: Revealed type is "Tuple[builtins.str, None, builtins.int]" +reveal_type(a) # N: Revealed type is "tuple[builtins.str, None, builtins.int]" [builtins fixtures/tuple.pyi] [case testPEP695IncrementalFunction] @@ -1370,8 +1370,8 @@ class C: class D(C): pass -reveal_type(C.m(1)) # N: Revealed type is "Tuple[__main__.C, builtins.int]" -reveal_type(D.m(1)) # N: Revealed type is "Tuple[__main__.D, builtins.int]" +reveal_type(C.m(1)) # N: Revealed type is "tuple[__main__.C, builtins.int]" +reveal_type(D.m(1)) # N: Revealed type is "tuple[__main__.D, builtins.int]" class E[T]: def m(self) -> Self: @@ -1384,9 +1384,9 @@ class F[T](E[T]): pass reveal_type(E[int]().m()) # N: Revealed type is "__main__.E[builtins.int]" -reveal_type(E[int]().mm(b'x')) # N: Revealed type is "Tuple[__main__.E[builtins.int], builtins.bytes]" +reveal_type(E[int]().mm(b'x')) # N: Revealed type is "tuple[__main__.E[builtins.int], builtins.bytes]" reveal_type(F[str]().m()) # N: Revealed type is "__main__.F[builtins.str]" -reveal_type(F[str]().mm(b'x')) # N: Revealed type is "Tuple[__main__.F[builtins.str], builtins.bytes]" +reveal_type(F[str]().mm(b'x')) # N: Revealed type is "tuple[__main__.F[builtins.str], builtins.bytes]" [builtins fixtures/tuple.pyi] [case testPEP695CallAlias] @@ -1487,7 +1487,7 @@ class C: reveal_type(C.a) # N: Revealed type is "builtins.int" reveal_type(C.b) # N: Revealed type is "Union[builtins.list[builtins.str], None]" -C.A = str # E: Incompatible types in assignment (expression has type "Type[str]", variable has type "TypeAliasType") +C.A = str # E: Incompatible types in assignment (expression has type "type[str]", variable has type "TypeAliasType") x: C.A y: C.B[int] diff --git a/test-data/unit/check-python313.test b/test-data/unit/check-python313.test index f020b1602b99..65604754cc0f 100644 --- a/test-data/unit/check-python313.test +++ b/test-data/unit/check-python313.test @@ -14,7 +14,7 @@ def f2[**P1 = [int, str]](a: Callable[P1, None]) -> Callable[P1, None]: ... reveal_type(f2) # N: Revealed type is "def [P1 = [builtins.int, builtins.str]] (a: def (*P1.args, **P1.kwargs)) -> def (*P1.args, **P1.kwargs)" def f3[*Ts1 = *tuple[int, str]](a: tuple[*Ts1]) -> tuple[*Ts1]: ... -reveal_type(f3) # N: Revealed type is "def [Ts1 = Unpack[Tuple[builtins.int, builtins.str]]] (a: Tuple[Unpack[Ts1`-1 = Unpack[Tuple[builtins.int, builtins.str]]]]) -> Tuple[Unpack[Ts1`-1 = Unpack[Tuple[builtins.int, builtins.str]]]]" +reveal_type(f3) # N: Revealed type is "def [Ts1 = Unpack[tuple[builtins.int, builtins.str]]] (a: tuple[Unpack[Ts1`-1 = Unpack[tuple[builtins.int, builtins.str]]]]) -> tuple[Unpack[Ts1`-1 = Unpack[tuple[builtins.int, builtins.str]]]]" class ClassA1[T1 = int]: ... @@ -23,7 +23,7 @@ class ClassA3[*Ts1 = *tuple[int, str]]: ... reveal_type(ClassA1) # N: Revealed type is "def [T1 = builtins.int] () -> __main__.ClassA1[T1`1 = builtins.int]" reveal_type(ClassA2) # N: Revealed type is "def [P1 = [builtins.int, builtins.str]] () -> __main__.ClassA2[P1`1 = [builtins.int, builtins.str]]" -reveal_type(ClassA3) # N: Revealed type is "def [Ts1 = Unpack[Tuple[builtins.int, builtins.str]]] () -> __main__.ClassA3[Unpack[Ts1`1 = Unpack[Tuple[builtins.int, builtins.str]]]]" +reveal_type(ClassA3) # N: Revealed type is "def [Ts1 = Unpack[tuple[builtins.int, builtins.str]]] () -> __main__.ClassA3[Unpack[Ts1`1 = Unpack[tuple[builtins.int, builtins.str]]]]" [builtins fixtures/tuple.pyi] [case testPEP695TypeParameterDefaultValid] @@ -141,7 +141,7 @@ reveal_type(func_b1(2)) # N: Revealed type is "def (builtins.int, builtins.str) def func_c1[*Ts = *tuple[int, str]](x: int | Callable[[*Ts], None]) -> tuple[*Ts]: ... # reveal_type(func_c1(callback1)) # Revealed type is "Tuple[str]" # TODO -reveal_type(func_c1(2)) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(func_c1(2)) # N: Revealed type is "tuple[builtins.int, builtins.str]" [builtins fixtures/tuple.pyi] [case testPEP695TypeParameterDefaultClass1] @@ -251,7 +251,7 @@ def func_c1( b: TC1[float], ) -> None: # reveal_type(a) # Revealed type is "Tuple[builtins.int, builtins.str]" # TODO - reveal_type(b) # N: Revealed type is "Tuple[builtins.float]" + reveal_type(b) # N: Revealed type is "tuple[builtins.float]" [builtins fixtures/tuple.pyi] [typing fixtures/typing-full.pyi] diff --git a/test-data/unit/check-python38.test b/test-data/unit/check-python38.test index f90baed0eb16..dd3f793fd02b 100644 --- a/test-data/unit/check-python38.test +++ b/test-data/unit/check-python38.test @@ -404,9 +404,9 @@ else: def get_things() -> Union[Tuple[Good], Tuple[Bad]]: ... if (things := get_things())[0].is_good: - reveal_type(things) # N: Revealed type is "Tuple[__main__.Good]" + reveal_type(things) # N: Revealed type is "tuple[__main__.Good]" else: - reveal_type(things) # N: Revealed type is "Tuple[__main__.Bad]" + reveal_type(things) # N: Revealed type is "tuple[__main__.Bad]" [builtins fixtures/list.pyi] [case testWalrusConditionalTypeCheck] @@ -443,7 +443,7 @@ reveal_type(maybe_str) # N: Revealed type is "Union[builtins.str, None]" from typing import List def check_partial_list() -> None: - if (x := []): # E: Need type annotation for "x" (hint: "x: List[] = ...") + if (x := []): # E: Need type annotation for "x" (hint: "x: list[] = ...") pass y: List[str] @@ -790,7 +790,7 @@ dct: Dict[str, int] = {"a": "b", **other} main:5: error: Dict entry 0 has incompatible type "str": "str"; expected "str": "int" dct: Dict[str, int] = {"a": "b", **other} ^~~~~~~~ -main:5: error: Unpacked dict entry 1 has incompatible type "Dict[str, str]"; expected "SupportsKeysAndGetItem[str, int]" +main:5: error: Unpacked dict entry 1 has incompatible type "dict[str, str]"; expected "SupportsKeysAndGetItem[str, int]" dct: Dict[str, int] = {"a": "b", **other} ^~~~~ diff --git a/test-data/unit/check-recursive-types.test b/test-data/unit/check-recursive-types.test index 7f6e181a16ca..7ed5ea53c27e 100644 --- a/test-data/unit/check-recursive-types.test +++ b/test-data/unit/check-recursive-types.test @@ -12,7 +12,7 @@ if isinstance(x, list): x = x[0] class Bad: ... -x = ["foo", {"bar": [Bad()]}] # E: List item 0 has incompatible type "Bad"; expected "Union[str, List[JSON], Dict[str, JSON]]" +x = ["foo", {"bar": [Bad()]}] # E: List item 0 has incompatible type "Bad"; expected "Union[str, list[JSON], dict[str, JSON]]" [builtins fixtures/isinstancelist.pyi] [case testRecursiveAliasBasicGenericSubtype] @@ -54,7 +54,7 @@ reveal_type(flatten([1, [2, [3]]])) # N: Revealed type is "builtins.list[builti class Bad: ... x: Nested[int] = [1, [2, [3]]] -x = [1, [Bad()]] # E: List item 1 has incompatible type "List[Bad]"; expected "Union[int, Nested[int]]" +x = [1, [Bad()]] # E: List item 1 has incompatible type "list[Bad]"; expected "Union[int, Nested[int]]" [builtins fixtures/isinstancelist.pyi] [case testRecursiveAliasGenericInferenceNested] @@ -95,7 +95,7 @@ A = Union[B, int] B = Callable[[C], int] C = Type[A] x: A -reveal_type(x) # N: Revealed type is "Union[def (Union[Type[def (...) -> builtins.int], Type[builtins.int]]) -> builtins.int, builtins.int]" +reveal_type(x) # N: Revealed type is "Union[def (Union[type[def (...) -> builtins.int], type[builtins.int]]) -> builtins.int, builtins.int]" [case testRecursiveAliasesProhibited-skip] from typing import Type, Callable, Union @@ -161,7 +161,7 @@ y: C reveal_type(y.x) # N: Revealed type is "builtins.int" reveal_type(y[0]) # N: Revealed type is "builtins.int" x: A -reveal_type(x) # N: Revealed type is "__main__.G[Tuple[builtins.int, fallback=__main__.C]]" +reveal_type(x) # N: Revealed type is "__main__.G[tuple[builtins.int, fallback=__main__.C]]" [builtins fixtures/list.pyi] [case testRecursiveAliasViaBaseClassImported] @@ -189,7 +189,7 @@ class A(NamedTuple('A', [('attr', List[Exp])])): pass class B(NamedTuple('B', [('val', object)])): pass def my_eval(exp: Exp) -> int: - reveal_type(exp) # N: Revealed type is "Union[Tuple[builtins.list[...], fallback=__main__.A], Tuple[builtins.object, fallback=__main__.B]]" + reveal_type(exp) # N: Revealed type is "Union[tuple[builtins.list[...], fallback=__main__.A], tuple[builtins.object, fallback=__main__.B]]" if isinstance(exp, A): my_eval(exp[0][0]) return my_eval(exp.attr[0]) @@ -413,7 +413,7 @@ S = Type[S] # E: Type[...] can't contain "Type[...]" U = Type[Union[int, U]] # E: Type[...] can't contain "Union[Type[...], Type[...]]" \ # E: Type[...] can't contain "Type[...]" x: U -reveal_type(x) # N: Revealed type is "Type[Any]" +reveal_type(x) # N: Revealed type is "type[Any]" D = List[F[List[T]]] # E: Invalid recursive alias: type variable nesting on right hand side F = D[T] # Error reported above @@ -427,9 +427,9 @@ from typing import NamedTuple, Optional NT = NamedTuple("NT", [("x", Optional[NT]), ("y", int)]) nt: NT -reveal_type(nt) # N: Revealed type is "Tuple[Union[..., None], builtins.int, fallback=__main__.NT]" -reveal_type(nt.x) # N: Revealed type is "Union[Tuple[Union[..., None], builtins.int, fallback=__main__.NT], None]" -reveal_type(nt[0]) # N: Revealed type is "Union[Tuple[Union[..., None], builtins.int, fallback=__main__.NT], None]" +reveal_type(nt) # N: Revealed type is "tuple[Union[..., None], builtins.int, fallback=__main__.NT]" +reveal_type(nt.x) # N: Revealed type is "Union[tuple[Union[..., None], builtins.int, fallback=__main__.NT], None]" +reveal_type(nt[0]) # N: Revealed type is "Union[tuple[Union[..., None], builtins.int, fallback=__main__.NT], None]" y: str if nt.x is not None: y = nt.x[0] # E: Incompatible types in assignment (expression has type "Optional[NT]", variable has type "str") @@ -440,9 +440,9 @@ from typing import NamedTuple, TypeVar, Tuple NT = NamedTuple("NT", [("x", NT), ("y", int)]) nt: NT -reveal_type(nt) # N: Revealed type is "Tuple[..., builtins.int, fallback=__main__.NT]" -reveal_type(nt.x) # N: Revealed type is "Tuple[..., builtins.int, fallback=__main__.NT]" -reveal_type(nt[0]) # N: Revealed type is "Tuple[Tuple[..., builtins.int, fallback=__main__.NT], builtins.int, fallback=__main__.NT]" +reveal_type(nt) # N: Revealed type is "tuple[..., builtins.int, fallback=__main__.NT]" +reveal_type(nt.x) # N: Revealed type is "tuple[..., builtins.int, fallback=__main__.NT]" +reveal_type(nt[0]) # N: Revealed type is "tuple[tuple[..., builtins.int, fallback=__main__.NT], builtins.int, fallback=__main__.NT]" y: str if nt.x is not None: y = nt.x[0] # E: Incompatible types in assignment (expression has type "NT", variable has type "str") @@ -464,9 +464,9 @@ class NT(NamedTuple): y: int nt: NT -reveal_type(nt) # N: Revealed type is "Tuple[Union[..., None], builtins.int, fallback=__main__.NT]" -reveal_type(nt.x) # N: Revealed type is "Union[Tuple[Union[..., None], builtins.int, fallback=__main__.NT], None]" -reveal_type(nt[0]) # N: Revealed type is "Union[Tuple[Union[..., None], builtins.int, fallback=__main__.NT], None]" +reveal_type(nt) # N: Revealed type is "tuple[Union[..., None], builtins.int, fallback=__main__.NT]" +reveal_type(nt.x) # N: Revealed type is "Union[tuple[Union[..., None], builtins.int, fallback=__main__.NT], None]" +reveal_type(nt[0]) # N: Revealed type is "Union[tuple[Union[..., None], builtins.int, fallback=__main__.NT], None]" y: str if nt.x is not None: y = nt.x[0] # E: Incompatible types in assignment (expression has type "Optional[NT]", variable has type "str") @@ -491,7 +491,7 @@ class B(Tuple[B, int]): x: int C = NewType("C", B) b, _ = x -reveal_type(b) # N: Revealed type is "Tuple[..., builtins.int, fallback=__main__.B]" +reveal_type(b) # N: Revealed type is "tuple[..., builtins.int, fallback=__main__.B]" reveal_type(b.x) # N: Revealed type is "builtins.int" y: CNT @@ -516,13 +516,13 @@ class B(NamedTuple): y: int n: A -reveal_type(n) # N: Revealed type is "Tuple[builtins.str, builtins.tuple[Tuple[..., builtins.int, fallback=__main__.B], ...], fallback=__main__.A]" +reveal_type(n) # N: Revealed type is "tuple[builtins.str, builtins.tuple[tuple[..., builtins.int, fallback=__main__.B], ...], fallback=__main__.A]" T = TypeVar("T") S = TypeVar("S") def foo(arg: Tuple[T, S]) -> Union[T, S]: ... x = foo(n) -y: str = x # E: Incompatible types in assignment (expression has type "Union[str, Tuple[B, ...]]", variable has type "str") +y: str = x # E: Incompatible types in assignment (expression has type "Union[str, tuple[B, ...]]", variable has type "str") [builtins fixtures/tuple.pyi] [case testMutuallyRecursiveNamedTuplesJoin] @@ -535,7 +535,7 @@ class B(NamedTuple): A = NamedTuple('A', [('x', str), ('y', B)]) n: B m: A -s: str = n.x # E: Incompatible types in assignment (expression has type "Tuple[A, int]", variable has type "str") +s: str = n.x # E: Incompatible types in assignment (expression has type "tuple[A, int]", variable has type "str") reveal_type(m[0]) # N: Revealed type is "builtins.str" lst = [m, n] @@ -567,7 +567,7 @@ n = n.y.x t: Tuple[str, B] t = n -t = m # E: Incompatible types in assignment (expression has type "B", variable has type "Tuple[str, B]") +t = m # E: Incompatible types in assignment (expression has type "B", variable has type "tuple[str, B]") [builtins fixtures/tuple.pyi] [case testMutuallyRecursiveNamedTuplesCalls] @@ -578,8 +578,8 @@ B = NamedTuple('B', [('x', A), ('y', int)]) A = NamedTuple('A', [('x', str), ('y', 'B')]) n: A def f(m: B) -> None: pass -reveal_type(n) # N: Revealed type is "Tuple[builtins.str, Tuple[..., builtins.int, fallback=__main__.B], fallback=__main__.A]" -reveal_type(f) # N: Revealed type is "def (m: Tuple[Tuple[builtins.str, ..., fallback=__main__.A], builtins.int, fallback=__main__.B])" +reveal_type(n) # N: Revealed type is "tuple[builtins.str, tuple[..., builtins.int, fallback=__main__.B], fallback=__main__.A]" +reveal_type(f) # N: Revealed type is "def (m: tuple[tuple[builtins.str, ..., fallback=__main__.A], builtins.int, fallback=__main__.B])" f(n) # E: Argument 1 to "f" has incompatible type "A"; expected "B" [builtins fixtures/tuple.pyi] @@ -591,7 +591,7 @@ def foo() -> None: # N: Recursive types are not allowed at function scope y: int b: B - reveal_type(b) # N: Revealed type is "Tuple[Any, builtins.int, fallback=__main__.B@3]" + reveal_type(b) # N: Revealed type is "tuple[Any, builtins.int, fallback=__main__.B@3]" [builtins fixtures/tuple.pyi] [case testBasicRecursiveGenericNamedTuple] @@ -606,7 +606,7 @@ class A: ... class B(A): ... nti: NT[int] = NT(key=0, value=NT(key=1, value=A())) # E: Argument "value" to "NT" has incompatible type "NT[A]"; expected "Union[int, NT[int]]" -reveal_type(nti) # N: Revealed type is "Tuple[builtins.int, Union[builtins.int, ...], fallback=__main__.NT[builtins.int]]" +reveal_type(nti) # N: Revealed type is "tuple[builtins.int, Union[builtins.int, ...], fallback=__main__.NT[builtins.int]]" nta: NT[A] ntb: NT[B] @@ -807,11 +807,11 @@ Tree2 = Union[str, Tuple[Tree2, Tree2]] Tree3 = Union[str, Tuple[Tree3, Tree3, Tree3]] def test1() -> Tree1: - return 42 # E: Incompatible return value type (got "int", expected "Union[str, Tuple[Tree1]]") + return 42 # E: Incompatible return value type (got "int", expected "Union[str, tuple[Tree1]]") def test2() -> Tree2: - return 42 # E: Incompatible return value type (got "int", expected "Union[str, Tuple[Tree2, Tree2]]") + return 42 # E: Incompatible return value type (got "int", expected "Union[str, tuple[Tree2, Tree2]]") def test3() -> Tree3: - return 42 # E: Incompatible return value type (got "int", expected "Union[str, Tuple[Tree3, Tree3, Tree3]]") + return 42 # E: Incompatible return value type (got "int", expected "Union[str, tuple[Tree3, Tree3, Tree3]]") [builtins fixtures/tuple.pyi] [case testRecursiveDoubleUnionNoCrash] @@ -892,7 +892,7 @@ from typing import List, NamedTuple Example = NamedTuple("Example", [("rec", List["Example"])]) e: Example -reveal_type(e) # N: Revealed type is "Tuple[builtins.list[...], fallback=__main__.Example]" +reveal_type(e) # N: Revealed type is "tuple[builtins.list[...], fallback=__main__.Example]" [builtins fixtures/tuple.pyi] [case testRecursiveBoundFunctionScopeNoCrash] @@ -932,7 +932,7 @@ x: A[int, str] *_, last = x if last is not None: - reveal_type(last) # N: Revealed type is "Tuple[builtins.int, builtins.str, Union[Tuple[builtins.int, builtins.str, Union[..., None]], None]]" + reveal_type(last) # N: Revealed type is "tuple[builtins.int, builtins.str, Union[tuple[builtins.int, builtins.str, Union[..., None]], None]]" [builtins fixtures/tuple.pyi] [case testRecursiveAliasLiteral] diff --git a/test-data/unit/check-redefine.test b/test-data/unit/check-redefine.test index aaec94b546f5..7ddfdd0f8a4f 100644 --- a/test-data/unit/check-redefine.test +++ b/test-data/unit/check-redefine.test @@ -323,7 +323,7 @@ def f() -> None: def f() -> None: class x: pass x = 1 # E: Cannot assign to a type \ - # E: Incompatible types in assignment (expression has type "int", variable has type "Type[x]") + # E: Incompatible types in assignment (expression has type "int", variable has type "type[x]") y = 1 class y: pass # E: Name "y" already defined on line 5 diff --git a/test-data/unit/check-redefine2.test b/test-data/unit/check-redefine2.test index 238b64399ce4..fa831008fbae 100644 --- a/test-data/unit/check-redefine2.test +++ b/test-data/unit/check-redefine2.test @@ -1118,13 +1118,13 @@ def f1() -> None: reveal_type(x) # N: Revealed type is "builtins.int" def f2() -> None: - x, *y = t() # E: Need type annotation for "y" (hint: "y: List[] = ...") + x, *y = t() # E: Need type annotation for "y" (hint: "y: list[] = ...") def f3() -> None: x, _ = 1, [] def f4() -> None: - a, b = 1, [] # E: Need type annotation for "b" (hint: "b: List[] = ...") + a, b = 1, [] # E: Need type annotation for "b" (hint: "b: list[] = ...") [builtins fixtures/tuple.pyi] [case testNewRedefineUseInferredTypedDictTypeForContext] diff --git a/test-data/unit/check-selftype.test b/test-data/unit/check-selftype.test index ffa1a369e883..5f337f773e6f 100644 --- a/test-data/unit/check-selftype.test +++ b/test-data/unit/check-selftype.test @@ -55,7 +55,7 @@ class A: return A() # E: Incompatible return value type (got "A", expected "T") elif A(): return B() # E: Incompatible return value type (got "B", expected "T") - reveal_type(_type(self)) # N: Revealed type is "Type[T`-1]" + reveal_type(_type(self)) # N: Revealed type is "type[T`-1]" return reveal_type(_type(self)()) # N: Revealed type is "T`-1" class B(A): @@ -306,7 +306,7 @@ class A: @classmethod def new(cls: Type[T], factory: Callable[[T], T]) -> T: - reveal_type(cls) # N: Revealed type is "Type[T`-1]" + reveal_type(cls) # N: Revealed type is "type[T`-1]" reveal_type(cls()) # N: Revealed type is "T`-1" cls(2) # E: Too many arguments for "A" return cls() @@ -413,7 +413,7 @@ class A: return self @classmethod - def cfoo(cls: Type[T]) -> T: # E: The erased type of self "Type[builtins.str]" is not a supertype of its class "Type[__main__.A]" + def cfoo(cls: Type[T]) -> T: # E: The erased type of self "type[builtins.str]" is not a supertype of its class "type[__main__.A]" return cls() Q = TypeVar('Q', bound='B') @@ -441,7 +441,7 @@ class D: return self @classmethod - def cfoo(cls: Type[Q]) -> Q: # E: The erased type of self "Type[__main__.B]" is not a supertype of its class "Type[__main__.D]" + def cfoo(cls: Type[Q]) -> Q: # E: The erased type of self "type[__main__.B]" is not a supertype of its class "type[__main__.D]" return cls() [builtins fixtures/classmethod.pyi] @@ -473,10 +473,10 @@ class A: pass class B: - def __new__(cls: Type[T]) -> T: # E: The erased type of self "Type[__main__.A]" is not a supertype of its class "Type[__main__.B]" + def __new__(cls: Type[T]) -> T: # E: The erased type of self "type[__main__.A]" is not a supertype of its class "type[__main__.B]" return cls() - def __init_subclass__(cls: Type[T]) -> None: # E: The erased type of self "Type[__main__.A]" is not a supertype of its class "Type[__main__.B]" + def __init_subclass__(cls: Type[T]) -> None: # E: The erased type of self "type[__main__.A]" is not a supertype of its class "type[__main__.B]" pass class C: @@ -487,19 +487,19 @@ class C: pass class D: - def __new__(cls: D) -> D: # E: The erased type of self "__main__.D" is not a supertype of its class "Type[__main__.D]" + def __new__(cls: D) -> D: # E: The erased type of self "__main__.D" is not a supertype of its class "type[__main__.D]" return cls - def __init_subclass__(cls: D) -> None: # E: The erased type of self "__main__.D" is not a supertype of its class "Type[__main__.D]" + def __init_subclass__(cls: D) -> None: # E: The erased type of self "__main__.D" is not a supertype of its class "type[__main__.D]" pass class E: def __new__(cls) -> E: - reveal_type(cls) # N: Revealed type is "Type[__main__.E]" + reveal_type(cls) # N: Revealed type is "type[__main__.E]" return cls() def __init_subclass__(cls) -> None: - reveal_type(cls) # N: Revealed type is "Type[__main__.E]" + reveal_type(cls) # N: Revealed type is "type[__main__.E]" [case testSelfTypeNew_explicit] from typing import TypeVar, Type @@ -516,11 +516,11 @@ class A: class B: @staticmethod - def __new__(cls: Type[T]) -> T: # E: The erased type of self "Type[__main__.A]" is not a supertype of its class "Type[__main__.B]" + def __new__(cls: Type[T]) -> T: # E: The erased type of self "type[__main__.A]" is not a supertype of its class "type[__main__.B]" return cls() @classmethod - def __init_subclass__(cls: Type[T]) -> None: # E: The erased type of self "Type[__main__.A]" is not a supertype of its class "Type[__main__.B]" + def __init_subclass__(cls: Type[T]) -> None: # E: The erased type of self "type[__main__.A]" is not a supertype of its class "type[__main__.B]" pass class C: @@ -534,22 +534,22 @@ class C: class D: @staticmethod - def __new__(cls: D) -> D: # E: The erased type of self "__main__.D" is not a supertype of its class "Type[__main__.D]" + def __new__(cls: D) -> D: # E: The erased type of self "__main__.D" is not a supertype of its class "type[__main__.D]" return cls @classmethod - def __init_subclass__(cls: D) -> None: # E: The erased type of self "__main__.D" is not a supertype of its class "Type[__main__.D]" + def __init_subclass__(cls: D) -> None: # E: The erased type of self "__main__.D" is not a supertype of its class "type[__main__.D]" pass class E: @staticmethod def __new__(cls) -> E: - reveal_type(cls) # N: Revealed type is "Type[__main__.E]" + reveal_type(cls) # N: Revealed type is "type[__main__.E]" return cls() @classmethod def __init_subclass__(cls) -> None: - reveal_type(cls) # N: Revealed type is "Type[__main__.E]" + reveal_type(cls) # N: Revealed type is "type[__main__.E]" [builtins fixtures/classmethod.pyi] @@ -608,13 +608,13 @@ class B(A): pass reveal_type(A().g) # N: Revealed type is "builtins.int" -reveal_type(A().gt) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.A]" +reveal_type(A().gt) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.A]" reveal_type(A().f()) # N: Revealed type is "builtins.int" -reveal_type(A().ft()) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.A]" +reveal_type(A().ft()) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.A]" reveal_type(B().g) # N: Revealed type is "builtins.int" -reveal_type(B().gt) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.B]" +reveal_type(B().gt) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.B]" reveal_type(B().f()) # N: Revealed type is "builtins.int" -reveal_type(B().ft()) # N: Revealed type is "Tuple[builtins.int, builtins.int, fallback=__main__.B]" +reveal_type(B().ft()) # N: Revealed type is "tuple[builtins.int, builtins.int, fallback=__main__.B]" [builtins fixtures/property.pyi] @@ -645,9 +645,9 @@ reveal_type(Y.gt) # N: Revealed type is "def (x: builtins.int) -> __main__.Y" reveal_type(Y.f()) # N: Revealed type is "builtins.int" reveal_type(Y.ft()) # N: Revealed type is "def (x: builtins.int) -> __main__.Y" reveal_type(X1.g) # N: Revealed type is "builtins.int" -reveal_type(X1.gt) # N: Revealed type is "Type[__main__.X]" +reveal_type(X1.gt) # N: Revealed type is "type[__main__.X]" reveal_type(X1.f()) # N: Revealed type is "builtins.int" -reveal_type(X1.ft()) # N: Revealed type is "Type[__main__.X]" +reveal_type(X1.ft()) # N: Revealed type is "type[__main__.X]" [builtins fixtures/property.pyi] @@ -703,9 +703,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 "Callable[[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 "Callable[[type[C[str]]], None]" DS.from_item() [builtins fixtures/classmethod.pyi] @@ -723,7 +723,7 @@ class C(Generic[T]): ci: C[int] cs: C[str] -reveal_type(ci.from_item) # N: Revealed type is "def (item: Tuple[builtins.int])" +reveal_type(ci.from_item) # N: Revealed type is "def (item: tuple[builtins.int])" reveal_type(cs.from_item) # N: Revealed type is "def (item: builtins.str)" [builtins fixtures/tuple.pyi] @@ -844,7 +844,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 "Callable[[Base[list[S]]], S]" [builtins fixtures/list.pyi] [case testMixinAllowedWithProtocol] @@ -963,7 +963,7 @@ c: Lnk[int, float] = Lnk() d: Lnk[str, float] = b >> c # OK e: Lnk[str, Tuple[int, float]] = a >> (b, c) # OK -f: Lnk[str, Tuple[float, int]] = a >> (c, b) # E: Unsupported operand types for >> ("Lnk[str, Tuple[str, int]]" and "Tuple[Lnk[int, float], Lnk[str, int]]") +f: Lnk[str, Tuple[float, int]] = a >> (c, b) # E: Unsupported operand types for >> ("Lnk[str, tuple[str, int]]" and "tuple[Lnk[int, float], Lnk[str, int]]") [builtins fixtures/tuple.pyi] [case testSelfTypeMutuallyExclusiveRestrictions] @@ -1019,7 +1019,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 "Callable[[type[T]], T]" [case testSelfTypeProtocolClassmethodMatch] from typing import Type, TypeVar, Protocol @@ -1120,7 +1120,7 @@ class C(Generic[T]): class D(Generic[V]): def f(self) -> None: - reveal_type(C[Tuple[V, str]]().magic()) # N: Revealed type is "Tuple[Tuple[V`1, builtins.str], V`1, builtins.str]" + reveal_type(C[Tuple[V, str]]().magic()) # N: Revealed type is "tuple[tuple[V`1, builtins.str], V`1, builtins.str]" [builtins fixtures/tuple.pyi] [case testSelfTypeOnUnion] @@ -1414,7 +1414,7 @@ class C(Generic[T]): def f(self) -> None: for x, y in Z(self.a, self.b): - reveal_type((x, y)) # N: Revealed type is "Tuple[T`1, builtins.str]" + reveal_type((x, y)) # N: Revealed type is "tuple[T`1, builtins.str]" [builtins fixtures/tuple.pyi] [case testEnumerateReturningSelfFromIter] @@ -1508,7 +1508,7 @@ from typing import Self, TypeVar, Tuple T = TypeVar("T") class C: def meth(self: T) -> Tuple[Self, T]: ... # E: Method cannot have explicit self annotation and Self type -reveal_type(C().meth()) # N: Revealed type is "Tuple[Never, __main__.C]" +reveal_type(C().meth()) # N: Revealed type is "tuple[Never, __main__.C]" [builtins fixtures/property.pyi] [case testTypingSelfProperty] @@ -1571,7 +1571,7 @@ Pairs = List[Tuple[T, T]] class C(Generic[T]): def pairs(self) -> Pairs[Self]: ... class D(C[T]): ... -reveal_type(D[int]().pairs()) # N: Revealed type is "builtins.list[Tuple[__main__.D[builtins.int], __main__.D[builtins.int]]]" +reveal_type(D[int]().pairs()) # N: Revealed type is "builtins.list[tuple[__main__.D[builtins.int], __main__.D[builtins.int]]]" [builtins fixtures/tuple.pyi] [case testTypingSelfOverrideVar] @@ -1609,11 +1609,11 @@ class C(Generic[T]): def __init__(self, val: T) -> None: ... @classmethod def pair(cls, val: T) -> Tuple[Self, Self]: - return (cls(val), C(val)) # E: Incompatible return value type (got "Tuple[Self, C[T]]", expected "Tuple[Self, Self]") + return (cls(val), C(val)) # E: Incompatible return value type (got "tuple[Self, C[T]]", expected "tuple[Self, Self]") class D(C[int]): pass -reveal_type(C.pair(42)) # N: Revealed type is "Tuple[__main__.C[builtins.int], __main__.C[builtins.int]]" -reveal_type(D.pair("no")) # N: Revealed type is "Tuple[__main__.D, __main__.D]" \ +reveal_type(C.pair(42)) # N: Revealed type is "tuple[__main__.C[builtins.int], __main__.C[builtins.int]]" +reveal_type(D.pair("no")) # N: Revealed type is "tuple[__main__.D, __main__.D]" \ # E: Argument 1 to "pair" of "C" has incompatible type "str"; expected "int" [builtins fixtures/classmethod.pyi] @@ -1630,8 +1630,8 @@ class D(C[int]): ... c: C[int] d: D -reveal_type(c.meth("test")) # N: Revealed type is "Tuple[__main__.C[builtins.int], builtins.str, builtins.int]" -reveal_type(d.meth("test")) # N: Revealed type is "Tuple[__main__.D, builtins.str, builtins.int]" +reveal_type(c.meth("test")) # N: Revealed type is "tuple[__main__.C[builtins.int], builtins.str, builtins.int]" +reveal_type(d.meth("test")) # N: Revealed type is "tuple[__main__.D, builtins.str, builtins.int]" [builtins fixtures/tuple.pyi] [case testTypingSelfRecursiveInit] @@ -1781,8 +1781,8 @@ class C: def bar(self) -> Self: ... def foo(self, x: S) -> Tuple[Self, S]: ... -reveal_type(C.foo) # N: Revealed type is "def [Self <: __main__.C, S] (self: Self`1, x: S`2) -> Tuple[Self`1, S`2]" -reveal_type(C().foo(42)) # N: Revealed type is "Tuple[__main__.C, builtins.int]" +reveal_type(C.foo) # N: Revealed type is "def [Self <: __main__.C, S] (self: Self`1, x: S`2) -> tuple[Self`1, S`2]" +reveal_type(C().foo(42)) # N: Revealed type is "tuple[__main__.C, builtins.int]" [builtins fixtures/tuple.pyi] [case testTypingSelfTypeVarClashAttr] @@ -1795,8 +1795,8 @@ class C: def bar(self) -> Self: ... foo: Callable[[S, Self], Tuple[Self, S]] -reveal_type(C().foo) # N: Revealed type is "def [S] (S`2, __main__.C) -> Tuple[__main__.C, S`2]" -reveal_type(C().foo(42, C())) # N: Revealed type is "Tuple[__main__.C, builtins.int]" +reveal_type(C().foo) # N: Revealed type is "def [S] (S`2, __main__.C) -> tuple[__main__.C, S`2]" +reveal_type(C().foo(42, C())) # N: Revealed type is "tuple[__main__.C, builtins.int]" class This: ... [builtins fixtures/tuple.pyi] @@ -2105,9 +2105,9 @@ class C(Tuple[int, str]): return reveal_type(self.y) # N: Revealed type is "Self`0" c: C -reveal_type(c.x) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.C]" -reveal_type(c.y) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.C]" -reveal_type(C.y) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.C]" +reveal_type(c.x) # N: Revealed type is "tuple[builtins.int, builtins.str, fallback=__main__.C]" +reveal_type(c.y) # N: Revealed type is "tuple[builtins.int, builtins.str, fallback=__main__.C]" +reveal_type(C.y) # N: Revealed type is "tuple[builtins.int, builtins.str, fallback=__main__.C]" C.x # E: Access to generic instance variables via class is ambiguous [builtins fixtures/classmethod.pyi] diff --git a/test-data/unit/check-serialize.test b/test-data/unit/check-serialize.test index 042a962be9b3..63d9ccfc80cb 100644 --- a/test-data/unit/check-serialize.test +++ b/test-data/unit/check-serialize.test @@ -547,7 +547,7 @@ class A(Tuple[int, str]): [builtins fixtures/tuple.pyi] [out2] tmp/a.py:3: error: Too many arguments for "f" of "A" -tmp/a.py:4: note: Revealed type is "Tuple[builtins.int, builtins.str]" +tmp/a.py:4: note: Revealed type is "tuple[builtins.int, builtins.str]" [case testSerializeVariableLengthTupleBaseClass] import a @@ -565,7 +565,7 @@ class A(Tuple[int, ...]): [builtins fixtures/tuple.pyi] [out2] tmp/a.py:3: error: Too many arguments for "f" of "A" -tmp/a.py:4: note: Revealed type is "Tuple[builtins.int, builtins.int]" +tmp/a.py:4: note: Revealed type is "tuple[builtins.int, builtins.int]" [case testSerializePlainTupleBaseClass] import a @@ -583,7 +583,7 @@ class A(tuple): [builtins fixtures/tuple.pyi] [out2] tmp/a.py:3: error: Too many arguments for "f" of "A" -tmp/a.py:4: note: Revealed type is "Tuple[Any, Any]" +tmp/a.py:4: note: Revealed type is "tuple[Any, Any]" [case testSerializeNamedTupleBaseClass] import a @@ -602,8 +602,8 @@ class A(NamedTuple('N', [('x', int), ('y', str)])): [builtins fixtures/tuple.pyi] [out2] tmp/a.py:3: error: Too many arguments for "f" of "A" -tmp/a.py:4: note: Revealed type is "Tuple[builtins.int, builtins.str]" -tmp/a.py:5: note: Revealed type is "Tuple[builtins.int, builtins.str]" +tmp/a.py:4: note: Revealed type is "tuple[builtins.int, builtins.str]" +tmp/a.py:5: note: Revealed type is "tuple[builtins.int, builtins.str]" [case testSerializeAnyBaseClass] import a @@ -727,13 +727,13 @@ class C: self.c = A [builtins fixtures/tuple.pyi] [out1] -main:2: note: Revealed type is "Tuple[builtins.int, fallback=ntcrash.C.A@4]" -main:3: note: Revealed type is "Tuple[builtins.int, fallback=ntcrash.C.A@4]" -main:4: note: Revealed type is "def (x: builtins.int) -> Tuple[builtins.int, fallback=ntcrash.C.A@4]" +main:2: note: Revealed type is "tuple[builtins.int, fallback=ntcrash.C.A@4]" +main:3: note: Revealed type is "tuple[builtins.int, fallback=ntcrash.C.A@4]" +main:4: note: Revealed type is "def (x: builtins.int) -> tuple[builtins.int, fallback=ntcrash.C.A@4]" [out2] -main:2: note: Revealed type is "Tuple[builtins.int, fallback=ntcrash.C.A@4]" -main:3: note: Revealed type is "Tuple[builtins.int, fallback=ntcrash.C.A@4]" -main:4: note: Revealed type is "def (x: builtins.int) -> Tuple[builtins.int, fallback=ntcrash.C.A@4]" +main:2: note: Revealed type is "tuple[builtins.int, fallback=ntcrash.C.A@4]" +main:3: note: Revealed type is "tuple[builtins.int, fallback=ntcrash.C.A@4]" +main:4: note: Revealed type is "def (x: builtins.int) -> tuple[builtins.int, fallback=ntcrash.C.A@4]" -- -- Strict optional @@ -941,9 +941,9 @@ N = NamedTuple('N', [('x', int)]) x: N [builtins fixtures/tuple.pyi] [out2] -tmp/a.py:5: error: Incompatible types in assignment (expression has type "Tuple[int]", variable has type "N") -tmp/a.py:6: error: Incompatible types in assignment (expression has type "Tuple[int]", variable has type "N") -tmp/a.py:9: note: Revealed type is "Tuple[builtins.int, fallback=b.N]" +tmp/a.py:5: error: Incompatible types in assignment (expression has type "tuple[int]", variable has type "N") +tmp/a.py:6: error: Incompatible types in assignment (expression has type "tuple[int]", variable has type "N") +tmp/a.py:9: note: Revealed type is "tuple[builtins.int, fallback=b.N]" tmp/a.py:10: note: Revealed type is "builtins.int" tmp/a.py:11: error: Argument "x" to "N" has incompatible type "str"; expected "int" @@ -993,9 +993,9 @@ tmp/a.py:9: note: Revealed type is "b.DD" tmp/a.py:10: note: Revealed type is "Any" tmp/a.py:11: note: Revealed type is "Union[builtins.int, builtins.str]" tmp/a.py:12: note: Revealed type is "builtins.list[builtins.int]" -tmp/a.py:13: note: Revealed type is "Tuple[builtins.int, builtins.str]" +tmp/a.py:13: note: Revealed type is "tuple[builtins.int, builtins.str]" tmp/a.py:14: note: Revealed type is "def (builtins.int) -> builtins.str" -tmp/a.py:15: note: Revealed type is "Type[builtins.int]" +tmp/a.py:15: note: Revealed type is "type[builtins.int]" tmp/a.py:17: note: Revealed type is "def (*Any, **Any) -> builtins.str" tmp/a.py:19: note: Revealed type is "builtins.type" @@ -1010,9 +1010,9 @@ X = TypeVar('X') Y = Tuple[X, str] [builtins fixtures/tuple.pyi] [out1] -main:4: note: Revealed type is "Tuple[builtins.int, builtins.str]" +main:4: note: Revealed type is "tuple[builtins.int, builtins.str]" [out2] -main:4: note: Revealed type is "Tuple[builtins.int, builtins.str]" +main:4: note: Revealed type is "tuple[builtins.int, builtins.str]" [case testSerializeTuple] # Don't repreat types tested by testSerializeTypeAliases here. diff --git a/test-data/unit/check-statements.test b/test-data/unit/check-statements.test index b0b673f696e1..9ab68b32472d 100644 --- a/test-data/unit/check-statements.test +++ b/test-data/unit/check-statements.test @@ -1305,7 +1305,7 @@ def g() -> Iterator[List[int]]: yield [2, 3, 4] def f() -> Iterator[List[int]]: yield from g() - yield from [1, 2, 3] # E: Incompatible types in "yield from" (actual type "int", expected type "List[int]") + yield from [1, 2, 3] # E: Incompatible types in "yield from" (actual type "int", expected type "list[int]") [builtins fixtures/for.pyi] [out] @@ -1476,7 +1476,7 @@ with A(): with A() as a: # type: Tuple[int, int] pass -with A() as b: # type: Tuple[int, str] # E: Incompatible types in assignment (expression has type "Tuple[int, int]", variable has type "Tuple[int, str]") +with A() as b: # type: Tuple[int, str] # E: Incompatible types in assignment (expression has type "tuple[int, int]", variable has type "tuple[int, str]") pass with A() as (c, d): # type: int, int @@ -2029,7 +2029,7 @@ cs: List[B] if int(): *bs, b = bs if int(): - *bs, c = cs # E: Incompatible types in assignment (expression has type "List[B]", variable has type "List[A]") + *bs, c = cs # E: Incompatible types in assignment (expression has type "list[B]", variable has type "list[A]") if int(): *ns, c = cs if int(): diff --git a/test-data/unit/check-tuples.test b/test-data/unit/check-tuples.test index 3424d053fe42..f118eec4f266 100644 --- a/test-data/unit/check-tuples.test +++ b/test-data/unit/check-tuples.test @@ -11,15 +11,15 @@ t4: Tuple[A, B] t5: Tuple[B, A] if int(): - t1 = t2 # E: Incompatible types in assignment (expression has type "Tuple[B]", variable has type "Tuple[A]") + t1 = t2 # E: Incompatible types in assignment (expression has type "tuple[B]", variable has type "tuple[A]") if int(): - t1 = t3 # E: Incompatible types in assignment (expression has type "Tuple[A, A]", variable has type "Tuple[A]") + t1 = t3 # E: Incompatible types in assignment (expression has type "tuple[A, A]", variable has type "tuple[A]") if int(): - t3 = t1 # E: Incompatible types in assignment (expression has type "Tuple[A]", variable has type "Tuple[A, A]") + t3 = t1 # E: Incompatible types in assignment (expression has type "tuple[A]", variable has type "tuple[A, A]") if int(): - t3 = t4 # E: Incompatible types in assignment (expression has type "Tuple[A, B]", variable has type "Tuple[A, A]") + t3 = t4 # E: Incompatible types in assignment (expression has type "tuple[A, B]", variable has type "tuple[A, A]") if int(): - t3 = t5 # E: Incompatible types in assignment (expression has type "Tuple[B, A]", variable has type "Tuple[A, A]") + t3 = t5 # E: Incompatible types in assignment (expression has type "tuple[B, A]", variable has type "tuple[A, A]") # Ok if int(): @@ -44,10 +44,10 @@ t2: Tuple[A, B] t3: Tuple[B, A] if int(): - t2 = t1 # E: Incompatible types in assignment (expression has type "Tuple[A, A]", variable has type "Tuple[A, B]") - t2 = t3 # E: Incompatible types in assignment (expression has type "Tuple[B, A]", variable has type "Tuple[A, B]") - t3 = t1 # E: Incompatible types in assignment (expression has type "Tuple[A, A]", variable has type "Tuple[B, A]") - t3 = t2 # E: Incompatible types in assignment (expression has type "Tuple[A, B]", variable has type "Tuple[B, A]") + t2 = t1 # E: Incompatible types in assignment (expression has type "tuple[A, A]", variable has type "tuple[A, B]") + t2 = t3 # E: Incompatible types in assignment (expression has type "tuple[B, A]", variable has type "tuple[A, B]") + t3 = t1 # E: Incompatible types in assignment (expression has type "tuple[A, A]", variable has type "tuple[B, A]") + t3 = t2 # E: Incompatible types in assignment (expression has type "tuple[A, B]", variable has type "tuple[B, A]") t1 = t2 t1 = t3 @@ -63,11 +63,11 @@ a, o = None, None # type: (A, object) t = None # type: Tuple[A, A] if int(): - a = t # E: Incompatible types in assignment (expression has type "Tuple[A, A]", variable has type "A") + a = t # E: Incompatible types in assignment (expression has type "tuple[A, A]", variable has type "A") if int(): - t = o # E: Incompatible types in assignment (expression has type "object", variable has type "Tuple[A, A]") + t = o # E: Incompatible types in assignment (expression has type "object", variable has type "tuple[A, A]") if int(): - t = a # E: Incompatible types in assignment (expression has type "A", variable has type "Tuple[A, A]") + t = a # E: Incompatible types in assignment (expression has type "A", variable has type "tuple[A, A]") # TODO: callable types + tuples # Ok @@ -85,7 +85,7 @@ t1: Tuple[A, Tuple[A, A]] t2: Tuple[B, Tuple[B, B]] if int(): - t2 = t1 # E: Incompatible types in assignment (expression has type "Tuple[A, Tuple[A, A]]", variable has type "Tuple[B, Tuple[B, B]]") + t2 = t1 # E: Incompatible types in assignment (expression has type "tuple[A, tuple[A, A]]", variable has type "tuple[B, tuple[B, B]]") if int(): t1 = t2 @@ -99,7 +99,7 @@ t1: Tuple[A, Tuple[A, A]] t2: Tuple[B, Tuple[B, B]] if int(): - t2 = t1 # E: Incompatible types in assignment (expression has type "Tuple[A, Tuple[A, A]]", variable has type "Tuple[B, Tuple[B, B]]") + t2 = t1 # E: Incompatible types in assignment (expression has type "tuple[A, tuple[A, A]]", variable has type "tuple[B, tuple[B, B]]") if int(): t1 = t2 @@ -139,18 +139,18 @@ def takes_tuple_aa(t: tuple[A, A]): ... takes_tuple_aa(tuple_aa) takes_tuple_aa(Tuple_aa) -takes_tuple_aa(tuple_obj) # E: Argument 1 to "takes_tuple_aa" has incompatible type "Tuple[object, ...]"; expected "Tuple[A, A]" -takes_tuple_aa(Tuple_obj) # E: Argument 1 to "takes_tuple_aa" has incompatible type "Tuple[object, ...]"; expected "Tuple[A, A]" -takes_tuple_aa(tuple_obj_one) # E: Argument 1 to "takes_tuple_aa" has incompatible type "Tuple[object]"; expected "Tuple[A, A]" -takes_tuple_aa(Tuple_obj_one) # E: Argument 1 to "takes_tuple_aa" has incompatible type "Tuple[object]"; expected "Tuple[A, A]" -takes_tuple_aa(tuple_obj_two) # E: Argument 1 to "takes_tuple_aa" has incompatible type "Tuple[object, object]"; expected "Tuple[A, A]" -takes_tuple_aa(Tuple_obj_two) # E: Argument 1 to "takes_tuple_aa" has incompatible type "Tuple[object, object]"; expected "Tuple[A, A]" +takes_tuple_aa(tuple_obj) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple[object, ...]"; expected "tuple[A, A]" +takes_tuple_aa(Tuple_obj) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple[object, ...]"; expected "tuple[A, A]" +takes_tuple_aa(tuple_obj_one) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple[object]"; expected "tuple[A, A]" +takes_tuple_aa(Tuple_obj_one) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple[object]"; expected "tuple[A, A]" +takes_tuple_aa(tuple_obj_two) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple[object, object]"; expected "tuple[A, A]" +takes_tuple_aa(Tuple_obj_two) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple[object, object]"; expected "tuple[A, A]" takes_tuple_aa(tuple_any_implicit) takes_tuple_aa(Tuple_any_implicit) takes_tuple_aa(tuple_any) takes_tuple_aa(Tuple_any) -takes_tuple_aa(tuple_any_one) # E: Argument 1 to "takes_tuple_aa" has incompatible type "Tuple[Any]"; expected "Tuple[A, A]" -takes_tuple_aa(Tuple_any_one) # E: Argument 1 to "takes_tuple_aa" has incompatible type "Tuple[Any]"; expected "Tuple[A, A]" +takes_tuple_aa(tuple_any_one) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple[Any]"; expected "tuple[A, A]" +takes_tuple_aa(Tuple_any_one) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple[Any]"; expected "tuple[A, A]" takes_tuple_aa(tuple_any_two) takes_tuple_aa(Tuple_any_two) @@ -175,22 +175,22 @@ takes_tuple_any_implicit(Tuple_any_two) def takes_tuple_any_one(t: tuple[Any]): ... -takes_tuple_any_one(tuple_aa) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "Tuple[A, A]"; expected "Tuple[Any]" -takes_tuple_any_one(Tuple_aa) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "Tuple[A, A]"; expected "Tuple[Any]" -takes_tuple_any_one(tuple_obj) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "Tuple[object, ...]"; expected "Tuple[Any]" -takes_tuple_any_one(Tuple_obj) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "Tuple[object, ...]"; expected "Tuple[Any]" +takes_tuple_any_one(tuple_aa) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "tuple[A, A]"; expected "tuple[Any]" +takes_tuple_any_one(Tuple_aa) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "tuple[A, A]"; expected "tuple[Any]" +takes_tuple_any_one(tuple_obj) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "tuple[object, ...]"; expected "tuple[Any]" +takes_tuple_any_one(Tuple_obj) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "tuple[object, ...]"; expected "tuple[Any]" takes_tuple_any_one(tuple_obj_one) takes_tuple_any_one(Tuple_obj_one) -takes_tuple_any_one(tuple_obj_two) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "Tuple[object, object]"; expected "Tuple[Any]" -takes_tuple_any_one(Tuple_obj_two) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "Tuple[object, object]"; expected "Tuple[Any]" +takes_tuple_any_one(tuple_obj_two) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "tuple[object, object]"; expected "tuple[Any]" +takes_tuple_any_one(Tuple_obj_two) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "tuple[object, object]"; expected "tuple[Any]" takes_tuple_any_one(tuple_any_implicit) takes_tuple_any_one(Tuple_any_implicit) takes_tuple_any_one(tuple_any) takes_tuple_any_one(Tuple_any) takes_tuple_any_one(tuple_any_one) takes_tuple_any_one(Tuple_any_one) -takes_tuple_any_one(tuple_any_two) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "Tuple[Any, Any]"; expected "Tuple[Any]" -takes_tuple_any_one(Tuple_any_two) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "Tuple[Any, Any]"; expected "Tuple[Any]" +takes_tuple_any_one(tuple_any_two) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "tuple[Any, Any]"; expected "tuple[Any]" +takes_tuple_any_one(Tuple_any_two) # E: Argument 1 to "takes_tuple_any_one" has incompatible type "tuple[Any, Any]"; expected "tuple[Any]" class A: pass [builtins fixtures/tuple.pyi] @@ -229,15 +229,15 @@ def takes_tuple_aa(t: Tuple[A, A]): ... takes_tuple_aa(inst_tuple_aa) takes_tuple_aa(inst_tuple_aa_subclass) takes_tuple_aa(inst_tuple_any_subclass) -takes_tuple_aa(inst_tuple_any_one_subclass) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple_any_one_subclass"; expected "Tuple[A, A]" +takes_tuple_aa(inst_tuple_any_one_subclass) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple_any_one_subclass"; expected "tuple[A, A]" takes_tuple_aa(inst_tuple_any_two_subclass) -takes_tuple_aa(inst_tuple_obj_subclass) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple_obj_subclass"; expected "Tuple[A, A]" -takes_tuple_aa(inst_tuple_obj_one_subclass) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple_obj_one_subclass"; expected "Tuple[A, A]" -takes_tuple_aa(inst_tuple_obj_two_subclass) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple_obj_two_subclass"; expected "Tuple[A, A]" +takes_tuple_aa(inst_tuple_obj_subclass) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple_obj_subclass"; expected "tuple[A, A]" +takes_tuple_aa(inst_tuple_obj_one_subclass) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple_obj_one_subclass"; expected "tuple[A, A]" +takes_tuple_aa(inst_tuple_obj_two_subclass) # E: Argument 1 to "takes_tuple_aa" has incompatible type "tuple_obj_two_subclass"; expected "tuple[A, A]" def takes_tuple_aa_subclass(t: tuple_aa_subclass): ... -takes_tuple_aa_subclass(inst_tuple_aa) # E: Argument 1 to "takes_tuple_aa_subclass" has incompatible type "Tuple[A, A]"; expected "tuple_aa_subclass" +takes_tuple_aa_subclass(inst_tuple_aa) # E: Argument 1 to "takes_tuple_aa_subclass" has incompatible type "tuple[A, A]"; expected "tuple_aa_subclass" takes_tuple_aa_subclass(inst_tuple_aa_subclass) takes_tuple_aa_subclass(inst_tuple_any_subclass) # E: Argument 1 to "takes_tuple_aa_subclass" has incompatible type "tuple_any_subclass"; expected "tuple_aa_subclass" takes_tuple_aa_subclass(inst_tuple_any_one_subclass) # E: Argument 1 to "takes_tuple_aa_subclass" has incompatible type "tuple_any_one_subclass"; expected "tuple_aa_subclass" @@ -271,15 +271,15 @@ t3 = None # type: Tuple[A, B] a, b, c = None, None, None # type: (A, B, C) if int(): - t2 = () # E: Incompatible types in assignment (expression has type "Tuple[()]", variable has type "Tuple[A]") + t2 = () # E: Incompatible types in assignment (expression has type "tuple[()]", variable has type "tuple[A]") if int(): - t2 = (a, a) # E: Incompatible types in assignment (expression has type "Tuple[A, A]", variable has type "Tuple[A]") + t2 = (a, a) # E: Incompatible types in assignment (expression has type "tuple[A, A]", variable has type "tuple[A]") if int(): - t3 = (a, a) # E: Incompatible types in assignment (expression has type "Tuple[A, A]", variable has type "Tuple[A, B]") + t3 = (a, a) # E: Incompatible types in assignment (expression has type "tuple[A, A]", variable has type "tuple[A, B]") if int(): - t3 = (b, b) # E: Incompatible types in assignment (expression has type "Tuple[B, B]", variable has type "Tuple[A, B]") + t3 = (b, b) # E: Incompatible types in assignment (expression has type "tuple[B, B]", variable has type "tuple[A, B]") if int(): - t3 = (a, b, a) # E: Incompatible types in assignment (expression has type "Tuple[A, B, A]", variable has type "Tuple[A, B]") + t3 = (a, b, a) # E: Incompatible types in assignment (expression has type "tuple[A, B, A]", variable has type "tuple[A, B]") t1 = () t1 = (a,) @@ -389,9 +389,9 @@ class B: pass t: Tuple[A, B] n = 0 -t[0] = A() # E: Unsupported target for indexed assignment ("Tuple[A, B]") -t[2] = A() # E: Unsupported target for indexed assignment ("Tuple[A, B]") -t[n] = A() # E: Unsupported target for indexed assignment ("Tuple[A, B]") +t[0] = A() # E: Unsupported target for indexed assignment ("tuple[A, B]") +t[2] = A() # E: Unsupported target for indexed assignment ("tuple[A, B]") +t[n] = A() # E: Unsupported target for indexed assignment ("tuple[A, B]") [builtins fixtures/tuple.pyi] @@ -626,8 +626,8 @@ d, e = f, g, h = 1, 1 # E: Need more than 2 values to unpack (3 expected) [case testAssignmentToStarMissingAnnotation] from typing import List t = 1, 2 -a, b, *c = 1, 2 # E: Need type annotation for "c" (hint: "c: List[] = ...") -aa, bb, *cc = t # E: Need type annotation for "cc" (hint: "cc: List[] = ...") +a, b, *c = 1, 2 # E: Need type annotation for "c" (hint: "c: list[] = ...") +aa, bb, *cc = t # E: Need type annotation for "cc" (hint: "cc: list[] = ...") [builtins fixtures/list.pyi] [case testAssignmentToStarAnnotation] @@ -636,7 +636,7 @@ from typing import List li, lo = None, None # type: List[int], List[object] a, b, *c = 1, 2 # type: int, int, List[int] if int(): - c = lo # E: Incompatible types in assignment (expression has type "List[object]", variable has type "List[int]") + c = lo # E: Incompatible types in assignment (expression has type "list[object]", variable has type "list[int]") if int(): c = li [builtins fixtures/list.pyi] @@ -707,7 +707,7 @@ if int(): a, *na = ta if int(): na = la - na = a # E: Incompatible types in assignment (expression has type "A", variable has type "List[A]") + na = a # E: Incompatible types in assignment (expression has type "A", variable has type "list[A]") class A: pass [builtins fixtures/list.pyi] @@ -719,7 +719,7 @@ li: List[int] la: List[A] a, *l = A(), A() if int(): - l = li # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[A]") + l = li # E: Incompatible types in assignment (expression has type "list[int]", variable has type "list[A]") if int(): l = la [builtins fixtures/list.pyi] @@ -734,7 +734,7 @@ li: List[int] la: List[A] a, *l = [A(), A()] if int(): - l = li # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[A]") + l = li # E: Incompatible types in assignment (expression has type "list[int]", variable has type "list[A]") if int(): l = la [builtins fixtures/list.pyi] @@ -747,7 +747,7 @@ la: List[A] ta: Tuple[A, A, A] a, *l = ta if int(): - l = li # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[A]") + l = li # E: Incompatible types in assignment (expression has type "list[int]", variable has type "list[A]") if int(): l = la @@ -761,7 +761,7 @@ li: List[int] la: List[A] a, *l = la if int(): - l = li # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[A]") + l = li # E: Incompatible types in assignment (expression has type "list[int]", variable has type "list[A]") if int(): l = la @@ -835,17 +835,17 @@ if int(): if int(): t, c2 = (a2, b2), c2 if int(): - t, c2 = (a2, a2), c2 # E: Incompatible types in assignment (expression has type "Tuple[A, A]", variable has type "Tuple[A, B]") + t, c2 = (a2, a2), c2 # E: Incompatible types in assignment (expression has type "tuple[A, A]", variable has type "tuple[A, B]") if int(): - t = a1, a1, a1 # E: Incompatible types in assignment (expression has type "Tuple[A, A, A]", variable has type "Tuple[A, B]") + t = a1, a1, a1 # E: Incompatible types in assignment (expression has type "tuple[A, A, A]", variable has type "tuple[A, B]") if int(): - t = a1 # E: Incompatible types in assignment (expression has type "A", variable has type "Tuple[A, B]") + t = a1 # E: Incompatible types in assignment (expression has type "A", variable has type "tuple[A, B]") if int(): a2, a2, a2 = t # E: Need more than 2 values to unpack (3 expected) if int(): a2, = t # E: Too many values to unpack (1 expected, 2 provided) if int(): - a2 = t # E: Incompatible types in assignment (expression has type "Tuple[A, B]", variable has type "A") + a2 = t # E: Incompatible types in assignment (expression has type "tuple[A, B]", variable has type "A") class A: pass class B: pass @@ -864,10 +864,10 @@ def f(x: 'A') -> None: pass a: A -(a, a) + a # E: Unsupported operand types for + ("Tuple[A, A]" and "A") -a + (a, a) # E: Unsupported operand types for + ("A" and "Tuple[A, A]") -f((a, a)) # E: Argument 1 to "f" has incompatible type "Tuple[A, A]"; expected "A" -(a, a).foo # E: "Tuple[A, A]" has no attribute "foo" +(a, a) + a # E: Unsupported operand types for + ("tuple[A, A]" and "A") +a + (a, a) # E: Unsupported operand types for + ("A" and "tuple[A, A]") +f((a, a)) # E: Argument 1 to "f" has incompatible type "tuple[A, A]"; expected "A" +(a, a).foo # E: "tuple[A, A]" has no attribute "foo" [builtins fixtures/tuple.pyi] [case testLargeTuplesInErrorMessages] @@ -879,7 +879,7 @@ class LongTypeName: def __add__(self, x: 'LongTypeName') -> 'LongTypeName': pass [builtins fixtures/tuple.pyi] [out] -main:3: error: Unsupported operand types for + ("LongTypeName" and "Tuple[LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName]") +main:3: error: Unsupported operand types for + ("LongTypeName" and "tuple[LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName]") -- Tuple methods @@ -899,7 +899,7 @@ if int(): i = t.__str__() # E: Incompatible types in assignment (expression has type "str", variable has type "int") if int(): i = s in t # E: Incompatible types in assignment (expression has type "bool", variable has type "int") -t.foo # E: "Tuple[int, str]" has no attribute "foo" +t.foo # E: "tuple[int, str]" has no attribute "foo" if int(): i = t.__len__() @@ -1036,7 +1036,7 @@ from typing import TypeVar, Generic, Tuple T = TypeVar('T') class Test(Generic[T], Tuple[T]): pass x = Test() # type: Test[int] -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.Test[builtins.int]]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, fallback=__main__.Test[builtins.int]]" [builtins fixtures/tuple.pyi] [out] @@ -1064,7 +1064,7 @@ tb = () # type: Tuple[B, ...] fa(ta) fa(tb) fb(tb) -fb(ta) # E: Argument 1 to "fb" has incompatible type "Tuple[A, ...]"; expected "Tuple[B, ...]" +fb(ta) # E: Argument 1 to "fb" has incompatible type "tuple[A, ...]"; expected "tuple[B, ...]" [builtins fixtures/tuple.pyi] [case testSubtypingFixedAndVariableLengthTuples] @@ -1080,8 +1080,8 @@ fa(aa) fa(ab) fa(bb) fb(bb) -fb(ab) # E: Argument 1 to "fb" has incompatible type "Tuple[A, B]"; expected "Tuple[B, ...]" -fb(aa) # E: Argument 1 to "fb" has incompatible type "Tuple[A, A]"; expected "Tuple[B, ...]" +fb(ab) # E: Argument 1 to "fb" has incompatible type "tuple[A, B]"; expected "tuple[B, ...]" +fb(aa) # E: Argument 1 to "fb" has incompatible type "tuple[A, A]"; expected "tuple[B, ...]" [builtins fixtures/tuple.pyi] [case testSubtypingTupleIsContainer] @@ -1102,7 +1102,7 @@ a = () a = (1, 2) b = (*a, '') -reveal_type(b) # N: Revealed type is "Tuple[builtins.int, builtins.int, builtins.str]" +reveal_type(b) # N: Revealed type is "tuple[builtins.int, builtins.int, builtins.str]" [builtins fixtures/tuple.pyi] [case testTupleWithStarExpr2] @@ -1115,7 +1115,7 @@ reveal_type(b) # N: Revealed type is "builtins.tuple[builtins.int, ...]" # flags: --enable-incomplete-feature=PreciseTupleTypes a = [1] b = (0, *a) -reveal_type(b) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]]]" +reveal_type(b) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]]]" [builtins fixtures/tuple.pyi] [case testTupleWithStarExpr3] @@ -1130,9 +1130,9 @@ reveal_type(c) # N: Revealed type is "builtins.tuple[builtins.str, ...]" # flags: --enable-incomplete-feature=PreciseTupleTypes a = [''] b = (0, *a) -reveal_type(b) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.str, ...]]]" +reveal_type(b) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.str, ...]]]" c = (*a, '') -reveal_type(c) # N: Revealed type is "Tuple[Unpack[builtins.tuple[builtins.str, ...]], builtins.str]" +reveal_type(c) # N: Revealed type is "tuple[Unpack[builtins.tuple[builtins.str, ...]], builtins.str]" [builtins fixtures/tuple.pyi] [case testTupleWithStarExpr4] @@ -1159,13 +1159,13 @@ class B: pass def f(x: Union[B, Tuple[A, A]]) -> None: if isinstance(x, tuple): - reveal_type(x) # N: Revealed type is "Tuple[__main__.A, __main__.A]" + reveal_type(x) # N: Revealed type is "tuple[__main__.A, __main__.A]" else: reveal_type(x) # N: Revealed type is "__main__.B" def g(x: Union[str, Tuple[str, str]]) -> None: if isinstance(x, tuple): - reveal_type(x) # N: Revealed type is "Tuple[builtins.str, builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.str, builtins.str]" else: reveal_type(x) # N: Revealed type is "builtins.str" @@ -1178,19 +1178,19 @@ from typing import Tuple, Union Pair = Tuple[int, int] Variant = Union[int, Pair] def tuplify(v: Variant) -> None: - reveal_type(v) # N: Revealed type is "Union[builtins.int, Tuple[builtins.int, builtins.int]]" + reveal_type(v) # N: Revealed type is "Union[builtins.int, tuple[builtins.int, builtins.int]]" if not isinstance(v, tuple): reveal_type(v) # N: Revealed type is "builtins.int" v = (v, v) - reveal_type(v) # N: Revealed type is "Tuple[builtins.int, builtins.int]" - reveal_type(v) # N: Revealed type is "Tuple[builtins.int, builtins.int]" + reveal_type(v) # N: Revealed type is "tuple[builtins.int, builtins.int]" + reveal_type(v) # N: Revealed type is "tuple[builtins.int, builtins.int]" reveal_type(v[0]) # N: Revealed type is "builtins.int" Pair2 = Tuple[int, str] Variant2 = Union[int, Pair2] def tuplify2(v: Variant2) -> None: if isinstance(v, tuple): - reveal_type(v) # N: Revealed type is "Tuple[builtins.int, builtins.str]" + reveal_type(v) # N: Revealed type is "tuple[builtins.int, builtins.str]" else: reveal_type(v) # N: Revealed type is "builtins.int" [builtins fixtures/tuple.pyi] @@ -1200,10 +1200,10 @@ def tuplify2(v: Variant2) -> None: from typing import Tuple, Union def good(blah: Union[Tuple[int, int], int]) -> None: - reveal_type(blah) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], builtins.int]" + reveal_type(blah) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], builtins.int]" if isinstance(blah, tuple): - reveal_type(blah) # N: Revealed type is "Tuple[builtins.int, builtins.int]" - reveal_type(blah) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], builtins.int]" + reveal_type(blah) # N: Revealed type is "tuple[builtins.int, builtins.int]" + reveal_type(blah) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], builtins.int]" [builtins fixtures/tuple.pyi] [out] @@ -1223,7 +1223,7 @@ def g(x: T) -> Tuple[T, T]: return (x, x) z = 1 -x, y = g(z) # E: Argument 1 to "g" has incompatible type "int"; expected "Tuple[B1, B2]" +x, y = g(z) # E: Argument 1 to "g" has incompatible type "int"; expected "tuple[B1, B2]" [builtins fixtures/tuple.pyi] [out] @@ -1374,13 +1374,13 @@ reveal_type(join(subtup, tup2)) # N: Revealed type is "builtins.tuple[builtins. [case testTupleWithUndersizedContext] a = ([1], 'x') if int(): - a = ([], 'x', 1) # E: Incompatible types in assignment (expression has type "Tuple[List[Never], str, int]", variable has type "Tuple[List[int], str]") + a = ([], 'x', 1) # E: Incompatible types in assignment (expression has type "tuple[list[Never], str, int]", variable has type "tuple[list[int], str]") [builtins fixtures/tuple.pyi] [case testTupleWithOversizedContext] a = (1, [1], 'x') if int(): - a = (1, []) # E: Incompatible types in assignment (expression has type "Tuple[int, List[int]]", variable has type "Tuple[int, List[int], str]") + a = (1, []) # E: Incompatible types in assignment (expression has type "tuple[int, list[int]]", variable has type "tuple[int, list[int], str]") [builtins fixtures/tuple.pyi] [case testTupleWithoutContext] @@ -1405,7 +1405,7 @@ def f(a: Tuple) -> None: pass f(()) f((1,)) f(('', '')) -f(0) # E: Argument 1 to "f" has incompatible type "int"; expected "Tuple[Any, ...]" +f(0) # E: Argument 1 to "f" has incompatible type "int"; expected "tuple[Any, ...]" [builtins fixtures/tuple.pyi] [case testTupleSingleton] @@ -1413,9 +1413,9 @@ f(0) # E: Argument 1 to "f" has incompatible type "int"; expected "Tuple[Any, . from typing import Tuple def f(a: Tuple[()]) -> None: pass f(()) -f((1,)) # E: Argument 1 to "f" has incompatible type "Tuple[int]"; expected "Tuple[()]" -f(('', '')) # E: Argument 1 to "f" has incompatible type "Tuple[str, str]"; expected "Tuple[()]" -f(0) # E: Argument 1 to "f" has incompatible type "int"; expected "Tuple[()]" +f((1,)) # E: Argument 1 to "f" has incompatible type "tuple[int]"; expected "tuple[()]" +f(('', '')) # E: Argument 1 to "f" has incompatible type "tuple[str, str]"; expected "tuple[()]" +f(0) # E: Argument 1 to "f" has incompatible type "int"; expected "tuple[()]" [builtins fixtures/tuple.pyi] [case testNonliteralTupleIndex] @@ -1426,7 +1426,7 @@ reveal_type(t[x]) # N: Revealed type is "Union[builtins.int, builtins.str]" t[y] # E: No overload variant of "__getitem__" of "tuple" matches argument type "str" \ # N: Possible overload variants: \ # N: def __getitem__(self, int, /) -> Union[int, str] \ - # N: def __getitem__(self, slice, /) -> Tuple[Union[int, str], ...] + # N: def __getitem__(self, slice, /) -> tuple[Union[int, str], ...] [builtins fixtures/tuple.pyi] @@ -1467,7 +1467,7 @@ class C(Tuple[int, str]): def f(cls) -> None: pass t: Type[C] -t.g() # E: "Type[C]" has no attribute "g" +t.g() # E: "type[C]" has no attribute "g" t.f() [builtins fixtures/classmethod.pyi] @@ -1475,7 +1475,7 @@ t.f() from typing import Tuple def foo(o: CallableTuple) -> int: - reveal_type(o) # N: Revealed type is "Tuple[builtins.str, builtins.int, fallback=__main__.CallableTuple]" + reveal_type(o) # N: Revealed type is "tuple[builtins.str, builtins.int, fallback=__main__.CallableTuple]" return o(1, 2) class CallableTuple(Tuple[str, int]): @@ -1489,7 +1489,7 @@ from typing import Generic, Tuple, TypeVar T = TypeVar('T') def foo(o: CallableTuple[int]) -> int: - reveal_type(o) # N: Revealed type is "Tuple[builtins.str, builtins.int, fallback=__main__.CallableTuple[builtins.int]]" + reveal_type(o) # N: Revealed type is "tuple[builtins.str, builtins.int, fallback=__main__.CallableTuple[builtins.int]]" reveal_type(o.count(3)) # N: Revealed type is "builtins.int" return o(1, 2) @@ -1520,7 +1520,7 @@ from typing import Iterable, Tuple x: Iterable[int] = () y: Tuple[int, int] = (1, 2) x = y -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int]" [builtins fixtures/tuple.pyi] [case testTupleOverlapDifferentTuples] @@ -1532,9 +1532,9 @@ possibles: Tuple[int, Tuple[A]] x: Optional[Tuple[B]] if x in possibles: - reveal_type(x) # N: Revealed type is "Tuple[__main__.B]" + reveal_type(x) # N: Revealed type is "tuple[__main__.B]" else: - reveal_type(x) # N: Revealed type is "Union[Tuple[__main__.B], None]" + reveal_type(x) # N: Revealed type is "Union[tuple[__main__.B], None]" [builtins fixtures/tuple.pyi] @@ -1546,7 +1546,7 @@ reveal_type(tup[0]) # N: Revealed type is "builtins.int" reveal_type(tup[1]) # N: Revealed type is "Union[builtins.str, builtins.int]" reveal_type(tup[2]) # E: Tuple index out of range \ # N: Revealed type is "Union[Any, builtins.str]" -reveal_type(tup[:]) # N: Revealed type is "Union[Tuple[builtins.int, builtins.str], Tuple[builtins.int, builtins.int, builtins.str]]" +reveal_type(tup[:]) # N: Revealed type is "Union[tuple[builtins.int, builtins.str], tuple[builtins.int, builtins.int, builtins.str]]" [builtins fixtures/tuple.pyi] @@ -1558,7 +1558,7 @@ reveal_type(tup[0]) # N: Revealed type is "builtins.int" reveal_type(tup[1]) # N: Revealed type is "Union[builtins.str, builtins.int]" reveal_type(tup[2]) # E: Tuple index out of range \ # N: Revealed type is "Union[Any, builtins.int]" -reveal_type(tup[:]) # N: Revealed type is "Union[Tuple[builtins.int, builtins.str], builtins.list[builtins.int]]" +reveal_type(tup[:]) # N: Revealed type is "Union[tuple[builtins.int, builtins.str], builtins.list[builtins.int]]" [builtins fixtures/tuple.pyi] @@ -1566,7 +1566,7 @@ reveal_type(tup[:]) # N: Revealed type is "Union[Tuple[builtins.int, builtins.s a = (1, "foo", 3) b = ("bar", 7) -reveal_type(a + b) # N: Revealed type is "Tuple[builtins.int, builtins.str, builtins.int, builtins.str, builtins.int]" +reveal_type(a + b) # N: Revealed type is "tuple[builtins.int, builtins.str, builtins.int, builtins.str, builtins.int]" [builtins fixtures/tuple.pyi] @@ -1586,7 +1586,7 @@ t1: Tuple[int, ...] = (1, 2, 3, 4, 5, 6, 7, 8, "str", "str", "str", "str") # E: # N: Expression tuple item 10 has type "str"; "int" expected; # short tuple initializer assignment -t2: Tuple[int, ...] = (1, 2, "s", 4) # E: Incompatible types in assignment (expression has type "Tuple[int, int, str, int]", variable has type "Tuple[int, ...]") +t2: Tuple[int, ...] = (1, 2, "s", 4) # E: Incompatible types in assignment (expression has type "tuple[int, int, str, int]", variable has type "tuple[int, ...]") # long initializer assignment with few mismatches, no ellipsis t3: Tuple[int, int, int, int, int, int, int, int, int, int, int, int] = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "str", "str") # E: Incompatible types in assignment (2 tuple items are incompatible) \ @@ -1600,10 +1600,10 @@ t4: Tuple[int, int, int, int, int, int, int, int, int, int, int, int] = (1, 2, 3 # N: Expression tuple item 10 has type "str"; "int" expected; # short tuple initializer assignment, no ellipsis -t5: Tuple[int, int] = (1, 2, "s", 4) # E: Incompatible types in assignment (expression has type "Tuple[int, int, str, int]", variable has type "Tuple[int, int]") +t5: Tuple[int, int] = (1, 2, "s", 4) # E: Incompatible types in assignment (expression has type "tuple[int, int, str, int]", variable has type "tuple[int, int]") # long initializer assignment with mismatched pairs -t6: Tuple[int, int, int, int, int, int, int, int, int, int, int, int] = (1, 2, 3, 4, 5, 6, 7, 8, "str", "str", "str", "str", 1, 1, 1, 1, 1) # E: Incompatible types in assignment (expression has type Tuple[int, int, ... <15 more items>], variable has type Tuple[int, int, ... <10 more items>]) +t6: Tuple[int, int, int, int, int, int, int, int, int, int, int, int] = (1, 2, 3, 4, 5, 6, 7, 8, "str", "str", "str", "str", 1, 1, 1, 1, 1) # E: Incompatible types in assignment (expression has type tuple[int, int, ... <15 more items>], variable has type tuple[int, int, ... <10 more items>]) [builtins fixtures/tuple.pyi] @@ -1731,11 +1731,11 @@ x9, y9, x10, y10, z5 = *points2, 1, *points2 # E: Contiguous iterable with same [case testMultiplyTupleByIntegerLiteral] from typing import Tuple t = ('',) * 2 -reveal_type(t) # N: Revealed type is "Tuple[builtins.str, builtins.str]" +reveal_type(t) # N: Revealed type is "tuple[builtins.str, builtins.str]" t2 = ('',) * -1 -reveal_type(t2) # N: Revealed type is "Tuple[()]" +reveal_type(t2) # N: Revealed type is "tuple[()]" t3 = ('', 1) * 2 -reveal_type(t3) # N: Revealed type is "Tuple[builtins.str, builtins.int, builtins.str, builtins.int]" +reveal_type(t3) # N: Revealed type is "tuple[builtins.str, builtins.int, builtins.str, builtins.int]" def f() -> Tuple[str, ...]: return ('', ) reveal_type(f() * 2) # N: Revealed type is "builtins.tuple[builtins.str, ...]" @@ -1746,18 +1746,18 @@ from typing import Tuple def f() -> Tuple[()]: ... -reveal_type(f) # N: Revealed type is "def () -> Tuple[()]" -reveal_type(f()) # N: Revealed type is "Tuple[()]" +reveal_type(f) # N: Revealed type is "def () -> tuple[()]" +reveal_type(f()) # N: Revealed type is "tuple[()]" [builtins fixtures/tuple.pyi] [case testMultiplyTupleByIntegerLiteralReverse] from typing import Tuple t = 2 * ('',) -reveal_type(t) # N: Revealed type is "Tuple[builtins.str, builtins.str]" +reveal_type(t) # N: Revealed type is "tuple[builtins.str, builtins.str]" t2 = -1 * ('',) -reveal_type(t2) # N: Revealed type is "Tuple[()]" +reveal_type(t2) # N: Revealed type is "tuple[()]" t3 = 2 * ('', 1) -reveal_type(t3) # N: Revealed type is "Tuple[builtins.str, builtins.int, builtins.str, builtins.int]" +reveal_type(t3) # N: Revealed type is "tuple[builtins.str, builtins.int, builtins.str, builtins.int]" def f() -> Tuple[str, ...]: return ('', ) reveal_type(2 * f()) # N: Revealed type is "builtins.tuple[builtins.str, ...]" @@ -1803,7 +1803,7 @@ def zip(i): ... def g(t: Tuple): reveal_type(zip(*t)) # N: Revealed type is "typing.Iterator[builtins.tuple[Any, ...]]" - reveal_type(zip(t)) # N: Revealed type is "typing.Iterator[Tuple[Any]]" + reveal_type(zip(t)) # N: Revealed type is "typing.Iterator[tuple[Any]]" [builtins fixtures/tuple.pyi] [case testTupleSubclassSlice] @@ -1813,5 +1813,5 @@ class A: ... class tuple_aa_subclass(Tuple[A, A]): ... -inst_tuple_aa_subclass: tuple_aa_subclass = tuple_aa_subclass((A(), A()))[:] # E: Incompatible types in assignment (expression has type "Tuple[A, A]", variable has type "tuple_aa_subclass") +inst_tuple_aa_subclass: tuple_aa_subclass = tuple_aa_subclass((A(), A()))[:] # E: Incompatible types in assignment (expression has type "tuple[A, A]", variable has type "tuple_aa_subclass") [builtins fixtures/tuple.pyi] diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index db314b136515..5f7646c62e96 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -12,7 +12,7 @@ U = Union[int, str] def f(x: U) -> None: pass f(1) f('') -f(()) # E: Argument 1 to "f" has incompatible type "Tuple[()]"; expected "Union[int, str]" +f(()) # E: Argument 1 to "f" has incompatible type "tuple[()]"; expected "Union[int, str]" [targets __main__, __main__.f] [builtins fixtures/tuple.pyi] @@ -21,7 +21,7 @@ from typing import Tuple T = Tuple[int, str] def f(x: T) -> None: pass f((1, 'x')) -f(1) # E: Argument 1 to "f" has incompatible type "int"; expected "Tuple[int, str]" +f(1) # E: Argument 1 to "f" has incompatible type "int"; expected "tuple[int, str]" [targets __main__, __main__.f] [builtins fixtures/tuple.pyi] @@ -64,7 +64,7 @@ from _m import U def f(x: U) -> None: pass f(1) f('x') -f(()) # E: Argument 1 to "f" has incompatible type "Tuple[()]"; expected "Union[int, str]" +f(()) # E: Argument 1 to "f" has incompatible type "tuple[()]"; expected "Union[int, str]" [file _m.py] from typing import Union U = Union[int, str] @@ -168,11 +168,11 @@ f(1) # E: Argument 1 to "f" has incompatible type "int"; expected "str" from typing import Tuple, Callable EmptyTuple = Tuple[()] x: EmptyTuple -reveal_type(x) # N: Revealed type is "Tuple[()]" +reveal_type(x) # N: Revealed type is "tuple[()]" EmptyTupleCallable = Callable[[Tuple[()]], None] f: EmptyTupleCallable -reveal_type(f) # N: Revealed type is "def (Tuple[()])" +reveal_type(f) # N: Revealed type is "def (tuple[()])" [builtins fixtures/list.pyi] [case testForwardTypeAlias] @@ -188,7 +188,7 @@ from typing import TypeVar, Tuple def f(p: 'Alias[str]') -> None: pass -reveal_type(f) # N: Revealed type is "def (p: Tuple[builtins.int, builtins.str])" +reveal_type(f) # N: Revealed type is "def (p: tuple[builtins.int, builtins.str])" T = TypeVar('T') Alias = Tuple[int, T] [builtins fixtures/tuple.pyi] @@ -375,25 +375,25 @@ class Cls: A1('no') # E: Argument 1 to "C" has incompatible type "str"; expected "int" a1 = A1(1) -reveal_type(a1) # N: Revealed type is "Tuple[builtins.int, fallback=nt.C]" +reveal_type(a1) # N: Revealed type is "tuple[builtins.int, fallback=nt.C]" A2(0) # E: Argument 1 to "D" has incompatible type "int"; expected "str" a2 = A2('yes') -reveal_type(a2) # N: Revealed type is "Tuple[builtins.str, fallback=nt.D]" +reveal_type(a2) # N: Revealed type is "tuple[builtins.str, fallback=nt.D]" a3 = A3() -reveal_type(a3) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=nt.E]" +reveal_type(a3) # N: Revealed type is "tuple[builtins.int, builtins.str, fallback=nt.E]" Cls.A1('no') # E: Argument 1 has incompatible type "str"; expected "int" ca1 = Cls.A1(1) -reveal_type(ca1) # N: Revealed type is "Tuple[builtins.int, fallback=nt.C]" +reveal_type(ca1) # N: Revealed type is "tuple[builtins.int, fallback=nt.C]" Cls.A2(0) # E: Argument 1 has incompatible type "int"; expected "str" ca2 = Cls.A2('yes') -reveal_type(ca2) # N: Revealed type is "Tuple[builtins.str, fallback=nt.D]" +reveal_type(ca2) # N: Revealed type is "tuple[builtins.str, fallback=nt.D]" ca3 = Cls.A3() -reveal_type(ca3) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=nt.E]" +reveal_type(ca3) # N: Revealed type is "tuple[builtins.int, builtins.str, fallback=nt.E]" [file nt.pyi] from typing import NamedTuple, Tuple @@ -927,29 +927,29 @@ p = Parent() c = Child() NormalImplicit = 4 # E: Cannot assign multiple types to name "NormalImplicit" without an explicit "Type[...]" annotation \ - # E: Incompatible types in assignment (expression has type "int", variable has type "Type[Foo]") + # E: Incompatible types in assignment (expression has type "int", variable has type "type[Foo]") NormalExplicit = 4 # E: Cannot assign multiple types to name "NormalExplicit" without an explicit "Type[...]" annotation \ - # E: Incompatible types in assignment (expression has type "int", variable has type "Type[Foo]") + # E: Incompatible types in assignment (expression has type "int", variable has type "type[Foo]") SpecialImplicit = 4 # E: Cannot assign multiple types to name "SpecialImplicit" without an explicit "Type[...]" annotation SpecialExplicit = 4 # E: Cannot assign multiple types to name "SpecialExplicit" without an explicit "Type[...]" annotation -Parent.NormalImplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "Type[Foo]") -Parent.NormalExplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "Type[Foo]") +Parent.NormalImplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "type[Foo]") +Parent.NormalExplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "type[Foo]") Parent.SpecialImplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "") Parent.SpecialExplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "") -Child.NormalImplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "Type[Foo]") -Child.NormalExplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "Type[Foo]") +Child.NormalImplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "type[Foo]") +Child.NormalExplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "type[Foo]") Child.SpecialImplicit = 4 Child.SpecialExplicit = 4 -p.NormalImplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "Type[Foo]") -p.NormalExplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "Type[Foo]") +p.NormalImplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "type[Foo]") +p.NormalExplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "type[Foo]") p.SpecialImplicit = 4 p.SpecialExplicit = 4 -c.NormalImplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "Type[Foo]") -c.NormalExplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "Type[Foo]") +c.NormalImplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "type[Foo]") +c.NormalExplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "type[Foo]") c.SpecialImplicit = 4 c.SpecialExplicit = 4 [builtins fixtures/tuple.pyi] @@ -1105,7 +1105,7 @@ reveal_type(t3) # N: Revealed type is "Any" T4 = TypeAliasType("T4") # E: Missing positional argument "value" in call to "TypeAliasType" T5 = TypeAliasType("T5", int, str) # E: Too many positional arguments for "TypeAliasType" \ - # E: Argument 3 to "TypeAliasType" has incompatible type "Type[str]"; expected "Tuple[Union[TypeVar?, ParamSpec?, TypeVarTuple?], ...]" + # E: Argument 3 to "TypeAliasType" has incompatible type "type[str]"; expected "tuple[Union[TypeVar?, ParamSpec?, TypeVarTuple?], ...]" [builtins fixtures/tuple.pyi] [typing fixtures/typing-full.pyi] @@ -1136,7 +1136,7 @@ VariadicAlias1 = TypeAliasType("VariadicAlias1", Tuple[Unpack[Ts]], type_params= VariadicAlias2 = TypeAliasType("VariadicAlias2", Tuple[Unpack[Ts], K], type_params=(Ts, K)) VariadicAlias3 = TypeAliasType("VariadicAlias3", Callable[[Unpack[Ts]], int], type_params=(Ts,)) xv: VariadicAlias1[int, str] = (1, 'a') -yv: VariadicAlias1[str, int] = (1, 'a') # E: Incompatible types in assignment (expression has type "Tuple[int, str]", variable has type "Tuple[str, int]") +yv: VariadicAlias1[str, int] = (1, 'a') # E: Incompatible types in assignment (expression has type "tuple[int, str]", variable has type "tuple[str, int]") zv: VariadicAlias2[int, str] = (1, 'a') def int_in_int_out(x: int) -> int: return x wv: VariadicAlias3[int] = int_in_int_out diff --git a/test-data/unit/check-type-object-type-inference.test b/test-data/unit/check-type-object-type-inference.test index cc3a5514904d..b410815664d1 100644 --- a/test-data/unit/check-type-object-type-inference.test +++ b/test-data/unit/check-type-object-type-inference.test @@ -17,25 +17,25 @@ class F: def g(f: F): f.f(int).e(7) f.f(tuple[int,str]) - f.f(tuple[int,str]).e('x') # E: Argument 1 to "e" of "E" has incompatible type "str"; expected "Tuple[int, str]" - f.f(tuple[int,str]).e( (7,8) ) # E: Argument 1 to "e" of "E" has incompatible type "Tuple[int, int]"; expected "Tuple[int, str]" + f.f(tuple[int,str]).e('x') # E: Argument 1 to "e" of "E" has incompatible type "str"; expected "tuple[int, str]" + f.f(tuple[int,str]).e( (7,8) ) # E: Argument 1 to "e" of "E" has incompatible type "tuple[int, int]"; expected "tuple[int, str]" f.f(tuple[int,str]).e( (7,'x') ) # OK - reveal_type(f.f(tuple[int,str]).e) # N: Revealed type is "def (t: Tuple[builtins.int, builtins.str]) -> builtins.str" + reveal_type(f.f(tuple[int,str]).e) # N: Revealed type is "def (t: tuple[builtins.int, builtins.str]) -> builtins.str" def h(f: F): f.f(int).e(7) f.f(tuple) - f.f(tuple).e('y') # E: Argument 1 to "e" of "E" has incompatible type "str"; expected "Tuple[Any, ...]" + f.f(tuple).e('y') # E: Argument 1 to "e" of "E" has incompatible type "str"; expected "tuple[Any, ...]" f.f(tuple).e( (8,'y') ) # OK reveal_type(f.f(tuple).e) # N: Revealed type is "def (t: builtins.tuple[Any, ...]) -> builtins.str" def i(f: F): f.f(tuple[int,tuple[int,str]]) - f.f(tuple[int,tuple[int,str]]).e('z') # E: Argument 1 to "e" of "E" has incompatible type "str"; expected "Tuple[int, Tuple[int, str]]" - f.f(tuple[int,tuple[int,str]]).e( (8,9) ) # E: Argument 1 to "e" of "E" has incompatible type "Tuple[int, int]"; expected "Tuple[int, Tuple[int, str]]" - f.f(tuple[int,tuple[int,str]]).e( (17, (28, 29)) ) # E: Argument 1 to "e" of "E" has incompatible type "Tuple[int, Tuple[int, int]]"; expected "Tuple[int, Tuple[int, str]]" + f.f(tuple[int,tuple[int,str]]).e('z') # E: Argument 1 to "e" of "E" has incompatible type "str"; expected "tuple[int, tuple[int, str]]" + f.f(tuple[int,tuple[int,str]]).e( (8,9) ) # E: Argument 1 to "e" of "E" has incompatible type "tuple[int, int]"; expected "tuple[int, tuple[int, str]]" + f.f(tuple[int,tuple[int,str]]).e( (17, (28, 29)) ) # E: Argument 1 to "e" of "E" has incompatible type "tuple[int, tuple[int, int]]"; expected "tuple[int, tuple[int, str]]" f.f(tuple[int,tuple[int,str]]).e( (27,(28,'z')) ) # OK - reveal_type(f.f(tuple[int,tuple[int,str]]).e) # N: Revealed type is "def (t: Tuple[builtins.int, Tuple[builtins.int, builtins.str]]) -> builtins.str" + reveal_type(f.f(tuple[int,tuple[int,str]]).e) # N: Revealed type is "def (t: tuple[builtins.int, tuple[builtins.int, builtins.str]]) -> builtins.str" x = tuple[int,str][str] # False negative [builtins fixtures/tuple.pyi] diff --git a/test-data/unit/check-typeddict.test b/test-data/unit/check-typeddict.test index cae90d56c3a6..f9d7ce7fc975 100644 --- a/test-data/unit/check-typeddict.test +++ b/test-data/unit/check-typeddict.test @@ -443,7 +443,7 @@ reveal_type(D(x=[])) # N: Revealed type is "TypedDict('__main__.D', {'x': built from typing import Dict, MutableMapping, TypedDict Point = TypedDict('Point', {'x': int, 'y': int}) def as_dict(p: Point) -> Dict[str, int]: - return p # E: Incompatible return value type (got "Point", expected "Dict[str, int]") + return p # E: Incompatible return value type (got "Point", expected "dict[str, int]") def as_mutable_mapping(p: Point) -> MutableMapping[str, object]: return p # E: Incompatible return value type (got "Point", expected "MutableMapping[str, object]") [builtins fixtures/dict.pyi] @@ -470,9 +470,9 @@ c: C def f(a: A) -> None: pass l = [a, b] # Join generates an anonymous TypedDict -f(l) # E: Argument 1 to "f" has incompatible type "List[TypedDict({'x': int})]"; expected "A" +f(l) # E: Argument 1 to "f" has incompatible type "list[TypedDict({'x': int})]"; expected "A" ll = [b, c] -f(ll) # E: Argument 1 to "f" has incompatible type "List[TypedDict({'x': int, 'z': str})]"; expected "A" +f(ll) # E: Argument 1 to "f" has incompatible type "list[TypedDict({'x': int, 'z': str})]"; expected "A" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -826,7 +826,7 @@ class C: A = TypedDict('A', {'x': int}) def g(self): A = TypedDict('A', {'y': int}) -C.A # E: "Type[C]" has no attribute "A" +C.A # E: "type[C]" has no attribute "A" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -923,7 +923,7 @@ A = TypedDict('A', {'@type': Literal['a-type'], 'value': int}) B = TypedDict('B', {'@type': Literal['b-type'], 'value': int}) c: Union[A, B] = {'@type': 'a-type', 'value': 'Test'} # E: Type of TypedDict is ambiguous, none of ("A", "B") matches cleanly \ - # E: Incompatible types in assignment (expression has type "Dict[str, str]", variable has type "Union[A, B]") + # E: Incompatible types in assignment (expression has type "dict[str, str]", variable has type "Union[A, B]") [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -1231,9 +1231,9 @@ c: C def f(a: A) -> None: pass l = [a, b] # Join generates an anonymous TypedDict -f(l) # E: Argument 1 to "f" has incompatible type "List[TypedDict({'x'?: int})]"; expected "A" +f(l) # E: Argument 1 to "f" has incompatible type "list[TypedDict({'x'?: int})]"; expected "A" ll = [b, c] -f(ll) # E: Argument 1 to "f" has incompatible type "List[TypedDict({'x'?: int, 'z'?: str})]"; expected "A" +f(ll) # E: Argument 1 to "f" has incompatible type "list[TypedDict({'x'?: int, 'z'?: str})]"; expected "A" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -1694,7 +1694,7 @@ a.clear() # E: "A" has no attribute "clear" a.setdefault('invalid', 1) # E: TypedDict "A" has no key "invalid" reveal_type(a.setdefault('x', 1)) # N: Revealed type is "builtins.int" reveal_type(a.setdefault('y', [])) # N: Revealed type is "builtins.list[builtins.int]" -a.setdefault('y', '') # E: Argument 2 to "setdefault" of "TypedDict" has incompatible type "str"; expected "List[int]" +a.setdefault('y', '') # E: Argument 2 to "setdefault" of "TypedDict" has incompatible type "str"; expected "list[int]" x = '' a.setdefault(x, 1) # E: Expected TypedDict key to be string literal alias = a.setdefault @@ -1709,7 +1709,7 @@ a.update({'z': 1}) # E: Unexpected TypedDict key "z" a.update({'z': 1, 'zz': 1}) # E: Unexpected TypedDict keys ("z", "zz") a.update({'z': 1, 'x': 1}) # E: Expected TypedDict key "x" but found keys ("z", "x") d = {'x': 1} -a.update(d) # E: Argument 1 to "update" of "TypedDict" has incompatible type "Dict[str, int]"; expected "TypedDict({'x'?: int, 'y'?: List[int]})" +a.update(d) # E: Argument 1 to "update" of "TypedDict" has incompatible type "dict[str, int]"; expected "TypedDict({'x'?: int, 'y'?: list[int]})" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -1724,7 +1724,7 @@ b: B reveal_type(a.pop('x')) # N: Revealed type is "builtins.int" reveal_type(a.pop('y', [])) # N: Revealed type is "builtins.list[builtins.int]" reveal_type(a.pop('x', '')) # N: Revealed type is "Union[builtins.int, Literal['']?]" -reveal_type(a.pop('x', (1, 2))) # N: Revealed type is "Union[builtins.int, Tuple[Literal[1]?, Literal[2]?]]" +reveal_type(a.pop('x', (1, 2))) # N: Revealed type is "Union[builtins.int, tuple[Literal[1]?, Literal[2]?]]" a.pop('invalid', '') # E: TypedDict "A" has no key "invalid" b.pop('x') # E: Key "x" of TypedDict "B" cannot be deleted x = '' @@ -1863,7 +1863,7 @@ class Config(TypedDict): x: Dict[str, str] y: Config -x == y # E: Non-overlapping equality check (left operand type: "Dict[str, str]", right operand type: "Config") +x == y # E: Non-overlapping equality check (left operand type: "dict[str, str]", right operand type: "Config") [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -1893,7 +1893,7 @@ class Config(TypedDict, total=False): x: Dict[str, str] y: Config -x == y # E: Non-overlapping equality check (left operand type: "Dict[str, str]", right operand type: "Config") +x == y # E: Non-overlapping equality check (left operand type: "dict[str, str]", right operand type: "Config") [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -1906,7 +1906,7 @@ class Config(TypedDict): b: str x: Config -x == {} # E: Non-overlapping equality check (left operand type: "Config", right operand type: "Dict[Never, Never]") +x == {} # E: Non-overlapping equality check (left operand type: "Config", right operand type: "dict[Never, Never]") [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -2797,11 +2797,11 @@ Alias = TD[List[T]] ad: Alias[str] reveal_type(ad) # N: Revealed type is "TypedDict('__main__.TD', {'key': builtins.int, 'value': builtins.list[builtins.str]})" -Alias[str](key=0, value=0) # E: Incompatible types (expression has type "int", TypedDict item "value" has type "List[str]") +Alias[str](key=0, value=0) # E: Incompatible types (expression has type "int", TypedDict item "value" has type "list[str]") # Generic aliases are *always* filled with Any, so this is different from TD(...) call. Alias(key=0, value=0) # E: Missing type parameters for generic type "Alias" \ - # E: Incompatible types (expression has type "int", TypedDict item "value" has type "List[Any]") + # E: Incompatible types (expression has type "int", TypedDict item "value" has type "list[Any]") [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -2902,7 +2902,7 @@ def method(message: Response) -> None: ... method({'type': 'a', 'value': True}) # OK method({'type': 'b', 'value': 'abc'}) # OK method({'type': 'a', 'value': 'abc'}) # E: Type of TypedDict is ambiguous, none of ("A", "B") matches cleanly \ - # E: Argument 1 to "method" has incompatible type "Dict[str, str]"; expected "Union[A, B]" + # E: Argument 1 to "method" has incompatible type "dict[str, str]"; expected "Union[A, B]" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -2921,7 +2921,7 @@ class D(TypedDict, total=False): def foo(data: Union[A, B]) -> None: ... foo({"foo": {"c": "foo"}}) # OK foo({"foo": {"e": "foo"}}) # E: Type of TypedDict is ambiguous, none of ("A", "B") matches cleanly \ - # E: Argument 1 to "foo" has incompatible type "Dict[str, Dict[str, str]]"; expected "Union[A, B]" + # E: Argument 1 to "foo" has incompatible type "dict[str, dict[str, str]]"; expected "Union[A, B]" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -3196,7 +3196,7 @@ class Bar(TypedDict): pass foo: Dict[str, Any] = {} -bar: Bar = {**foo} # E: Unsupported type "Dict[str, Any]" for ** expansion in TypedDict +bar: Bar = {**foo} # E: Unsupported type "dict[str, Any]" for ** expansion in TypedDict [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -3326,7 +3326,7 @@ d1: Dict[str, int] d2: Dict[int, str] reveal_type(foo1 | d1) # N: Revealed type is "builtins.dict[builtins.str, builtins.object]" -foo1 | d2 # E: Unsupported operand types for | ("Foo" and "Dict[int, str]") +foo1 | d2 # E: Unsupported operand types for | ("Foo" and "dict[int, str]") class Bar(TypedDict): @@ -3344,7 +3344,7 @@ reveal_type(bar | {'key': 'a', 'value': 1}) # N: Revealed type is "builtins.dic reveal_type(bar | foo1) # N: Revealed type is "TypedDict('__main__.Bar', {'key': builtins.int, 'value': builtins.str})" reveal_type(bar | d1) # N: Revealed type is "builtins.dict[builtins.str, builtins.object]" -bar | d2 # E: Unsupported operand types for | ("Bar" and "Dict[int, str]") +bar | d2 # E: Unsupported operand types for | ("Bar" and "dict[int, str]") [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict-iror.pyi] @@ -3363,11 +3363,11 @@ foo | SubDict() main:7: error: No overload variant of "__or__" of "TypedDict" matches argument type "int" main:7: note: Possible overload variants: main:7: note: def __or__(self, TypedDict({'key'?: int}), /) -> Foo -main:7: note: def __or__(self, Dict[str, Any], /) -> Dict[str, object] +main:7: note: def __or__(self, dict[str, Any], /) -> dict[str, object] main:10: error: No overload variant of "__ror__" of "dict" matches argument type "Foo" main:10: note: Possible overload variants: -main:10: note: def __ror__(self, Dict[Any, Any], /) -> Dict[Any, Any] -main:10: note: def [T, T2] __ror__(self, Dict[T, T2], /) -> Dict[Union[Any, T], Union[Any, T2]] +main:10: note: def __ror__(self, dict[Any, Any], /) -> dict[Any, Any] +main:10: note: def [T, T2] __ror__(self, dict[T, T2], /) -> dict[Union[Any, T], Union[Any, T2]] [builtins fixtures/dict-full.pyi] [typing fixtures/typing-typeddict-iror.pyi] @@ -3388,7 +3388,7 @@ d1: Dict[str, int] d2: Dict[int, str] reveal_type(d1 | foo) # N: Revealed type is "builtins.dict[builtins.str, builtins.object]" -d2 | foo # E: Unsupported operand types for | ("Dict[int, str]" and "Foo") +d2 | foo # E: Unsupported operand types for | ("dict[int, str]" and "Foo") 1 | foo # E: Unsupported left operand type for | ("int") @@ -3406,7 +3406,7 @@ reveal_type({'value': 1} | bar) # N: Revealed type is "builtins.dict[builtins.s reveal_type({'key': 'a', 'value': 1} | bar) # N: Revealed type is "builtins.dict[builtins.str, builtins.object]" reveal_type(d1 | bar) # N: Revealed type is "builtins.dict[builtins.str, builtins.object]" -d2 | bar # E: Unsupported operand types for | ("Dict[int, str]" and "Bar") +d2 | bar # E: Unsupported operand types for | ("dict[int, str]" and "Bar") [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict-iror.pyi] @@ -3427,8 +3427,8 @@ foo |= {'b': 2} # E: Unexpected TypedDict key "b" d1: Dict[str, int] d2: Dict[int, str] -foo |= d1 # E: Argument 1 to "__ior__" of "TypedDict" has incompatible type "Dict[str, int]"; expected "TypedDict({'key'?: int})" -foo |= d2 # E: Argument 1 to "__ior__" of "TypedDict" has incompatible type "Dict[int, str]"; expected "TypedDict({'key'?: int})" +foo |= d1 # E: Argument 1 to "__ior__" of "TypedDict" has incompatible type "dict[str, int]"; expected "TypedDict({'key'?: int})" +foo |= d2 # E: Argument 1 to "__ior__" of "TypedDict" has incompatible type "dict[int, str]"; expected "TypedDict({'key'?: int})" class Bar(TypedDict): @@ -3442,8 +3442,8 @@ bar |= {'key': 'a', 'value': 'a', 'b': 'a'} # E: Expected TypedDict keys ("key" # E: Incompatible types (expression has type "str", TypedDict item "key" has type "int") bar |= foo -bar |= d1 # E: Argument 1 to "__ior__" of "TypedDict" has incompatible type "Dict[str, int]"; expected "TypedDict({'key'?: int, 'value'?: str})" -bar |= d2 # E: Argument 1 to "__ior__" of "TypedDict" has incompatible type "Dict[int, str]"; expected "TypedDict({'key'?: int, 'value'?: str})" +bar |= d1 # E: Argument 1 to "__ior__" of "TypedDict" has incompatible type "dict[str, int]"; expected "TypedDict({'key'?: int, 'value'?: str})" +bar |= d2 # E: Argument 1 to "__ior__" of "TypedDict" has incompatible type "dict[int, str]"; expected "TypedDict({'key'?: int, 'value'?: str})" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict-iror.pyi] @@ -3526,7 +3526,7 @@ class Point(TypedDict, total=False): y: int def func(cls: Type[Point]) -> None: - reveal_type(cls) # N: Revealed type is "Type[TypedDict('__main__.Point', {'x': builtins.int, 'y'?: builtins.int})]" + reveal_type(cls) # N: Revealed type is "type[TypedDict('__main__.Point', {'x': builtins.int, 'y'?: builtins.int})]" cls(x=1, y=2) cls(1, 2) # E: Too many positional arguments cls(x=1) @@ -3550,7 +3550,7 @@ class A(Generic[T]): self.a = a def func(self) -> T: - reveal_type(self.a) # N: Revealed type is "Type[T`1]" + reveal_type(self.a) # N: Revealed type is "type[T`1]" self.a(x=1, y=2) self.a(y=2) # E: Missing named argument "x" return self.a(x=1) @@ -3863,7 +3863,7 @@ tp: TP = {**r, **m} tp1: TP = {**tp, **m} tp2: TP = {**r, **m} tp3: TP = {**tp, **r} -tp4: TP = {**tp, **d} # E: Unsupported type "Dict[str, object]" for ** expansion in TypedDict +tp4: TP = {**tp, **d} # E: Unsupported type "dict[str, object]" for ** expansion in TypedDict [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -3984,7 +3984,7 @@ def accepts_dict(d: Dict[str, object]): ... x: TP accepts_mapping(x) accepts_mutable_mapping(x) # E: Argument 1 to "accepts_mutable_mapping" has incompatible type "TP"; expected "MutableMapping[str, object]" -accepts_dict(x) # E: Argument 1 to "accepts_dict" has incompatible type "TP"; expected "Dict[str, object]" +accepts_dict(x) # E: Argument 1 to "accepts_dict" has incompatible type "TP"; expected "dict[str, object]" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] diff --git a/test-data/unit/check-typeguard.test b/test-data/unit/check-typeguard.test index 94aa7ec6ffb8..e17a7f80e756 100644 --- a/test-data/unit/check-typeguard.test +++ b/test-data/unit/check-typeguard.test @@ -84,7 +84,7 @@ T = TypeVar('T') def is_two_element_tuple(a: Tuple[T, ...]) -> TypeGuard[Tuple[T, T]]: pass def main(a: Tuple[T, ...]): if is_two_element_tuple(a): - reveal_type(a) # N: Revealed type is "Tuple[T`-1, T`-1]" + reveal_type(a) # N: Revealed type is "tuple[T`-1, T`-1]" [builtins fixtures/tuple.pyi] [case testTypeGuardPassedAsTypeVarIsBool] @@ -258,7 +258,7 @@ def main1(a: object) -> None: ta = (a,) if is_float(*ta): # E: Type guard requires positional argument - reveal_type(ta) # N: Revealed type is "Tuple[builtins.object]" + reveal_type(ta) # N: Revealed type is "tuple[builtins.object]" reveal_type(a) # N: Revealed type is "builtins.object" la = [a] @@ -452,7 +452,7 @@ def g(x: object) -> None: ... def test(x: List[object]) -> None: if not(f(x) or isinstance(x, A)): return - g(reveal_type(x)) # N: Revealed type is "Union[builtins.list[builtins.str], __main__.]" + g(reveal_type(x)) # N: Revealed type is "Union[builtins.list[builtins.str], __main__.]" [builtins fixtures/tuple.pyi] [case testTypeGuardMultipleCondition-xfail] @@ -615,7 +615,7 @@ def is_two_element_tuple(val: Tuple[_T, ...]) -> TypeGuard[Tuple[_T, _T]]: def func(names: Tuple[str, ...]): reveal_type(names) # N: Revealed type is "builtins.tuple[builtins.str, ...]" if is_two_element_tuple(names): - reveal_type(names) # N: Revealed type is "Tuple[builtins.str, builtins.str]" + reveal_type(names) # N: Revealed type is "tuple[builtins.str, builtins.str]" [builtins fixtures/tuple.pyi] [case testTypeGuardErroneousDefinitionFails] diff --git a/test-data/unit/check-typeis.test b/test-data/unit/check-typeis.test index 356b1abfdf63..bb8beac72c3a 100644 --- a/test-data/unit/check-typeis.test +++ b/test-data/unit/check-typeis.test @@ -454,7 +454,7 @@ def g(x: object) -> None: ... def test(x: List[Any]) -> None: if not(f(x) or isinstance(x, A)): return - g(reveal_type(x)) # N: Revealed type is "Union[builtins.list[builtins.str], __main__.]" + g(reveal_type(x)) # N: Revealed type is "Union[builtins.list[builtins.str], __main__.]" [builtins fixtures/tuple.pyi] [case testTypeIsMultipleCondition] @@ -640,7 +640,7 @@ def is_two_element_tuple(val: Tuple[_T, ...]) -> TypeIs[Tuple[_T, _T]]: def func(names: Tuple[str, ...]): reveal_type(names) # N: Revealed type is "builtins.tuple[builtins.str, ...]" if is_two_element_tuple(names): - reveal_type(names) # N: Revealed type is "Tuple[builtins.str, builtins.str]" + reveal_type(names) # N: Revealed type is "tuple[builtins.str, builtins.str]" [builtins fixtures/tuple.pyi] [case testTypeIsErroneousDefinitionFails] @@ -761,7 +761,7 @@ def f(x: str) -> TypeIs[int]: # E: Narrowed type "int" is not a subtype of inpu T = TypeVar('T') -def g(x: List[T]) -> TypeIs[Sequence[T]]: # E: Narrowed type "Sequence[T]" is not a subtype of input type "List[T]" +def g(x: List[T]) -> TypeIs[Sequence[T]]: # E: Narrowed type "Sequence[T]" is not a subtype of input type "list[T]" pass [builtins fixtures/tuple.pyi] diff --git a/test-data/unit/check-typevar-defaults.test b/test-data/unit/check-typevar-defaults.test index 93d20eb26f6e..33a639eee580 100644 --- a/test-data/unit/check-typevar-defaults.test +++ b/test-data/unit/check-typevar-defaults.test @@ -13,7 +13,7 @@ def f2(a: Callable[P1, None]) -> Callable[P1, None]: ... reveal_type(f2) # N: Revealed type is "def [P1 = [builtins.int, builtins.str]] (a: def (*P1.args, **P1.kwargs)) -> def (*P1.args, **P1.kwargs)" def f3(a: Tuple[Unpack[Ts1]]) -> Tuple[Unpack[Ts1]]: ... -reveal_type(f3) # N: Revealed type is "def [Ts1 = Unpack[Tuple[builtins.int, builtins.str]]] (a: Tuple[Unpack[Ts1`-1 = Unpack[Tuple[builtins.int, builtins.str]]]]) -> Tuple[Unpack[Ts1`-1 = Unpack[Tuple[builtins.int, builtins.str]]]]" +reveal_type(f3) # N: Revealed type is "def [Ts1 = Unpack[tuple[builtins.int, builtins.str]]] (a: tuple[Unpack[Ts1`-1 = Unpack[tuple[builtins.int, builtins.str]]]]) -> tuple[Unpack[Ts1`-1 = Unpack[tuple[builtins.int, builtins.str]]]]" class ClassA1(Generic[T1]): ... @@ -22,7 +22,7 @@ class ClassA3(Generic[Unpack[Ts1]]): ... reveal_type(ClassA1) # N: Revealed type is "def [T1 = builtins.int] () -> __main__.ClassA1[T1`1 = builtins.int]" reveal_type(ClassA2) # N: Revealed type is "def [P1 = [builtins.int, builtins.str]] () -> __main__.ClassA2[P1`1 = [builtins.int, builtins.str]]" -reveal_type(ClassA3) # N: Revealed type is "def [Ts1 = Unpack[Tuple[builtins.int, builtins.str]]] () -> __main__.ClassA3[Unpack[Ts1`1 = Unpack[Tuple[builtins.int, builtins.str]]]]" +reveal_type(ClassA3) # N: Revealed type is "def [Ts1 = Unpack[tuple[builtins.int, builtins.str]]] () -> __main__.ClassA3[Unpack[Ts1`1 = Unpack[tuple[builtins.int, builtins.str]]]]" [builtins fixtures/tuple.pyi] [case testTypeVarDefaultsValid] @@ -181,7 +181,7 @@ reveal_type(func_b1(2)) # N: Revealed type is "def (builtins.int, builtins.str) def func_c1(x: Union[int, Callable[[Unpack[Ts1]], None]]) -> Tuple[Unpack[Ts1]]: ... # reveal_type(func_c1(callback1)) # Revealed type is "Tuple[str]" # TODO -reveal_type(func_c1(2)) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(func_c1(2)) # N: Revealed type is "tuple[builtins.int, builtins.str]" [builtins fixtures/tuple.pyi] [case testTypeVarDefaultsClass1] @@ -544,11 +544,11 @@ def func_a2( d: TA2[float, float, float], e: TA2[float, float, float, float], # E: Bad number of arguments for type alias, expected between 1 and 3, given 4 ) -> None: - reveal_type(a) # N: Revealed type is "Tuple[Any, builtins.int, builtins.str]" - reveal_type(b) # N: Revealed type is "Tuple[builtins.float, builtins.int, builtins.str]" - reveal_type(c) # N: Revealed type is "Tuple[builtins.float, builtins.float, builtins.str]" - reveal_type(d) # N: Revealed type is "Tuple[builtins.float, builtins.float, builtins.float]" - reveal_type(e) # N: Revealed type is "Tuple[Any, builtins.int, builtins.str]" + reveal_type(a) # N: Revealed type is "tuple[Any, builtins.int, builtins.str]" + reveal_type(b) # N: Revealed type is "tuple[builtins.float, builtins.int, builtins.str]" + reveal_type(c) # N: Revealed type is "tuple[builtins.float, builtins.float, builtins.str]" + reveal_type(d) # N: Revealed type is "tuple[builtins.float, builtins.float, builtins.float]" + reveal_type(e) # N: Revealed type is "tuple[Any, builtins.int, builtins.str]" TA3 = Union[Dict[T1, T2], List[T3]] @@ -574,11 +574,11 @@ def func_a4( d: TA4[float, float, float], e: TA4[float, float, float, float], # E: Bad number of arguments for type alias, expected between 2 and 3, given 4 ) -> None: - reveal_type(a) # N: Revealed type is "Tuple[Any, Any, builtins.int]" - reveal_type(b) # N: Revealed type is "Tuple[Any, Any, builtins.int]" - reveal_type(c) # N: Revealed type is "Tuple[builtins.float, builtins.float, builtins.int]" - reveal_type(d) # N: Revealed type is "Tuple[builtins.float, builtins.float, builtins.float]" - reveal_type(e) # N: Revealed type is "Tuple[Any, Any, builtins.int]" + reveal_type(a) # N: Revealed type is "tuple[Any, Any, builtins.int]" + reveal_type(b) # N: Revealed type is "tuple[Any, Any, builtins.int]" + reveal_type(c) # N: Revealed type is "tuple[builtins.float, builtins.float, builtins.int]" + reveal_type(d) # N: Revealed type is "tuple[builtins.float, builtins.float, builtins.float]" + reveal_type(e) # N: Revealed type is "tuple[Any, Any, builtins.int]" [builtins fixtures/dict.pyi] [case testTypeVarDefaultsTypeAlias2] @@ -638,7 +638,7 @@ def func_c1( b: TC1[float], ) -> None: # reveal_type(a) # Revealed type is "Tuple[builtins.int, builtins.str]" # TODO - reveal_type(b) # N: Revealed type is "Tuple[builtins.float]" + reveal_type(b) # N: Revealed type is "tuple[builtins.float]" TC2 = Tuple[T3, Unpack[Ts3]] @@ -649,7 +649,7 @@ def func_c2( ) -> None: # reveal_type(a) # Revealed type is "Tuple[builtins.str, Unpack[builtins.tuple[builtins.float, ...]]]" # TODO # reveal_type(b) # Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]]]" # TODO - reveal_type(c) # N: Revealed type is "Tuple[builtins.int]" + reveal_type(c) # N: Revealed type is "tuple[builtins.int]" TC3 = Tuple[T3, Unpack[Ts4]] @@ -659,8 +659,8 @@ def func_c3( c: TC3[int, Unpack[Tuple[float]]], ) -> None: # reveal_type(a) # Revealed type is "Tuple[builtins.str]" # TODO - reveal_type(b) # N: Revealed type is "Tuple[builtins.int]" - reveal_type(c) # N: Revealed type is "Tuple[builtins.int, builtins.float]" + reveal_type(b) # N: Revealed type is "tuple[builtins.int]" + reveal_type(c) # N: Revealed type is "tuple[builtins.int, builtins.float]" TC4 = Tuple[T1, Unpack[Ts1], T3] @@ -669,9 +669,9 @@ def func_c4( b: TC4[int], c: TC4[int, float], ) -> None: - reveal_type(a) # N: Revealed type is "Tuple[Any, Unpack[builtins.tuple[Any, ...]], builtins.str]" + reveal_type(a) # N: Revealed type is "tuple[Any, Unpack[builtins.tuple[Any, ...]], builtins.str]" # reveal_type(b) # Revealed type is "Tuple[builtins.int, builtins.str]" # TODO - reveal_type(c) # N: Revealed type is "Tuple[builtins.int, builtins.float]" + reveal_type(c) # N: Revealed type is "tuple[builtins.int, builtins.float]" [builtins fixtures/tuple.pyi] [case testTypeVarDefaultsTypeAliasRecursive1] diff --git a/test-data/unit/check-typevar-tuple.test b/test-data/unit/check-typevar-tuple.test index d364439f22e9..41e90c3f8506 100644 --- a/test-data/unit/check-typevar-tuple.test +++ b/test-data/unit/check-typevar-tuple.test @@ -13,17 +13,17 @@ args2: Tuple[bool, str] = (False, 'y') args3: Tuple[int, str, bool] = (2, 'z', True) varargs: Tuple[int, ...] = (1, 2, 3) -reveal_type(f(args)) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(f(args)) # N: Revealed type is "tuple[builtins.int, builtins.str]" reveal_type(f(varargs)) # N: Revealed type is "builtins.tuple[builtins.int, ...]" -f(0) # E: Argument 1 to "f" has incompatible type "int"; expected "Tuple[Never, ...]" +f(0) # E: Argument 1 to "f" has incompatible type "int"; expected "tuple[Never, ...]" def g(a: Tuple[Unpack[Ts]], b: Tuple[Unpack[Ts]]) -> Tuple[Unpack[Ts]]: return a -reveal_type(g(args, args)) # N: Revealed type is "Tuple[builtins.int, builtins.str]" -reveal_type(g(args, args2)) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(g(args, args)) # N: Revealed type is "tuple[builtins.int, builtins.str]" +reveal_type(g(args, args2)) # N: Revealed type is "tuple[builtins.int, builtins.str]" reveal_type(g(args, args3)) # N: Revealed type is "builtins.tuple[Union[builtins.int, builtins.str], ...]" reveal_type(g(any, any)) # N: Revealed type is "builtins.tuple[Any, ...]" [builtins fixtures/tuple.pyi] @@ -54,21 +54,21 @@ f_args: Tuple[int, str] f_args2: Tuple[int] f_args3: Tuple[int, str, bool] -reveal_type(f(f_args)) # N: Revealed type is "Tuple[builtins.str, builtins.str]" -reveal_type(f(f_args2)) # N: Revealed type is "Tuple[builtins.str]" -reveal_type(f(f_args3)) # N: Revealed type is "Tuple[builtins.str, builtins.str, builtins.bool]" -f(empty) # E: Argument 1 to "f" has incompatible type "Tuple[()]"; expected "Tuple[int]" -f(bad_args) # E: Argument 1 to "f" has incompatible type "Tuple[str, str]"; expected "Tuple[int, str]" +reveal_type(f(f_args)) # N: Revealed type is "tuple[builtins.str, builtins.str]" +reveal_type(f(f_args2)) # N: Revealed type is "tuple[builtins.str]" +reveal_type(f(f_args3)) # N: Revealed type is "tuple[builtins.str, builtins.str, builtins.bool]" +f(empty) # E: Argument 1 to "f" has incompatible type "tuple[()]"; expected "tuple[int]" +f(bad_args) # E: Argument 1 to "f" has incompatible type "tuple[str, str]"; expected "tuple[int, str]" # The reason for error in subtle: actual can be empty, formal cannot. -reveal_type(f(var_len_tuple)) # N: Revealed type is "Tuple[builtins.str, Unpack[builtins.tuple[builtins.int, ...]]]" \ - # E: Argument 1 to "f" has incompatible type "Tuple[int, ...]"; expected "Tuple[int, Unpack[Tuple[int, ...]]]" +reveal_type(f(var_len_tuple)) # N: Revealed type is "tuple[builtins.str, Unpack[builtins.tuple[builtins.int, ...]]]" \ + # E: Argument 1 to "f" has incompatible type "tuple[int, ...]"; expected "tuple[int, Unpack[tuple[int, ...]]]" g_args: Tuple[str, int] -reveal_type(g(g_args)) # N: Revealed type is "Tuple[builtins.str, builtins.str]" +reveal_type(g(g_args)) # N: Revealed type is "tuple[builtins.str, builtins.str]" h_args: Tuple[bool, int, str, int, str, object] -reveal_type(h(h_args)) # N: Revealed type is "Tuple[builtins.str, builtins.int]" +reveal_type(h(h_args)) # N: Revealed type is "tuple[builtins.str, builtins.int]" [builtins fixtures/tuple.pyi] [case testTypeVarTupleChaining] @@ -91,8 +91,8 @@ def h(a: Tuple[bool, int, Unpack[Ts], str, object]) -> Tuple[str, Unpack[Ts]]: return x args: Tuple[bool, int, str, int, str, object] -reveal_type(g(args)) # N: Revealed type is "Tuple[builtins.str, builtins.str, builtins.int]" -reveal_type(h(args)) # N: Revealed type is "Tuple[builtins.str, builtins.str, builtins.int]" +reveal_type(g(args)) # N: Revealed type is "tuple[builtins.str, builtins.str, builtins.int]" +reveal_type(h(args)) # N: Revealed type is "tuple[builtins.str, builtins.str, builtins.int]" [builtins fixtures/tuple.pyi] [case testTypeVarTupleGenericClassDefn] @@ -147,7 +147,7 @@ def foo(t: Variadic[int, Unpack[Ts], object]) -> Tuple[int, Unpack[Ts]]: ... v: Variadic[int, str, bool, object] -reveal_type(foo(v)) # N: Revealed type is "Tuple[builtins.int, builtins.str, builtins.bool]" +reveal_type(foo(v)) # N: Revealed type is "tuple[builtins.int, builtins.str, builtins.bool]" [builtins fixtures/tuple.pyi] [case testTypeVarTupleGenericClassWithMethods] @@ -166,7 +166,7 @@ class Variadic(Generic[T, Unpack[Ts], S]): ... v: Variadic[float, str, bool, object] -reveal_type(v.foo(0)) # N: Revealed type is "Tuple[builtins.int, builtins.str, builtins.bool]" +reveal_type(v.foo(0)) # N: Revealed type is "tuple[builtins.int, builtins.str, builtins.bool]" [builtins fixtures/tuple.pyi] [case testTypeVarTupleIsNotValidAliasTarget] @@ -306,7 +306,7 @@ def prefix_tuple( ... z = prefix_tuple(x=0, y=(True, 'a')) -reveal_type(z) # N: Revealed type is "Tuple[builtins.int, builtins.bool, builtins.str]" +reveal_type(z) # N: Revealed type is "tuple[builtins.int, builtins.bool, builtins.str]" [builtins fixtures/tuple.pyi] [case testTypeVarTuplePep646TypeVarTupleUnpacking] @@ -333,7 +333,7 @@ process_batch_channels(x) y: Array[Batch, Channels] process_batch_channels(y) z: Array[Batch] -process_batch_channels(z) # E: Argument 1 to "process_batch_channels" has incompatible type "Array[Batch]"; expected "Array[Batch, Unpack[Tuple[Any, ...]], Channels]" +process_batch_channels(z) # E: Argument 1 to "process_batch_channels" has incompatible type "Array[Batch]"; expected "Array[Batch, Unpack[tuple[Any, ...]], Channels]" u: Array[Unpack[Tuple[Any, ...]]] @@ -356,11 +356,11 @@ Ts2 = TypeVarTuple("Ts2") def bad(x: Tuple[int, Unpack[Ts], str, Unpack[Ts2]]) -> None: # E: More than one Unpack in a type is not allowed ... -reveal_type(bad) # N: Revealed type is "def [Ts, Ts2] (x: Tuple[builtins.int, Unpack[Ts`-1], builtins.str])" +reveal_type(bad) # N: Revealed type is "def [Ts, Ts2] (x: tuple[builtins.int, Unpack[Ts`-1], builtins.str])" def bad2(x: Tuple[int, Unpack[Tuple[int, ...]], str, Unpack[Tuple[str, ...]]]) -> None: # E: More than one Unpack in a type is not allowed ... -reveal_type(bad2) # N: Revealed type is "def (x: Tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]], builtins.str])" +reveal_type(bad2) # N: Revealed type is "def (x: tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]], builtins.str])" [builtins fixtures/tuple.pyi] [case testTypeVarTuplePep646TypeVarStarArgsBasic] @@ -370,23 +370,23 @@ from typing_extensions import TypeVarTuple, Unpack Ts = TypeVarTuple("Ts") def args_to_tuple(*args: Unpack[Ts]) -> Tuple[Unpack[Ts]]: - reveal_type(args) # N: Revealed type is "Tuple[Unpack[Ts`-1]]" - reveal_type(args_to_tuple(1, *args)) # N: Revealed type is "Tuple[Literal[1]?, Unpack[Ts`-1]]" - reveal_type(args_to_tuple(*args, 'a')) # N: Revealed type is "Tuple[Unpack[Ts`-1], Literal['a']?]" - reveal_type(args_to_tuple(1, *args, 'a')) # N: Revealed type is "Tuple[Literal[1]?, Unpack[Ts`-1], Literal['a']?]" + reveal_type(args) # N: Revealed type is "tuple[Unpack[Ts`-1]]" + reveal_type(args_to_tuple(1, *args)) # N: Revealed type is "tuple[Literal[1]?, Unpack[Ts`-1]]" + reveal_type(args_to_tuple(*args, 'a')) # N: Revealed type is "tuple[Unpack[Ts`-1], Literal['a']?]" + reveal_type(args_to_tuple(1, *args, 'a')) # N: Revealed type is "tuple[Literal[1]?, Unpack[Ts`-1], Literal['a']?]" args_to_tuple(*args, *args) # E: Passing multiple variadic unpacks in a call is not supported ok = (1, 'a') - reveal_type(args_to_tuple(*ok, *ok)) # N: Revealed type is "Tuple[builtins.int, builtins.str, builtins.int, builtins.str]" + reveal_type(args_to_tuple(*ok, *ok)) # N: Revealed type is "tuple[builtins.int, builtins.str, builtins.int, builtins.str]" if int(): return args else: return args_to_tuple(*args) -reveal_type(args_to_tuple(1, 'a')) # N: Revealed type is "Tuple[Literal[1]?, Literal['a']?]" +reveal_type(args_to_tuple(1, 'a')) # N: Revealed type is "tuple[Literal[1]?, Literal['a']?]" vt: Tuple[int, ...] -reveal_type(args_to_tuple(1, *vt)) # N: Revealed type is "Tuple[Literal[1]?, Unpack[builtins.tuple[builtins.int, ...]]]" -reveal_type(args_to_tuple(*vt, 'a')) # N: Revealed type is "Tuple[Unpack[builtins.tuple[builtins.int, ...]], Literal['a']?]" -reveal_type(args_to_tuple(1, *vt, 'a')) # N: Revealed type is "Tuple[Literal[1]?, Unpack[builtins.tuple[builtins.int, ...]], Literal['a']?]" +reveal_type(args_to_tuple(1, *vt)) # N: Revealed type is "tuple[Literal[1]?, Unpack[builtins.tuple[builtins.int, ...]]]" +reveal_type(args_to_tuple(*vt, 'a')) # N: Revealed type is "tuple[Unpack[builtins.tuple[builtins.int, ...]], Literal['a']?]" +reveal_type(args_to_tuple(1, *vt, 'a')) # N: Revealed type is "tuple[Literal[1]?, Unpack[builtins.tuple[builtins.int, ...]], Literal['a']?]" args_to_tuple(*vt, *vt) # E: Passing multiple variadic unpacks in a call is not supported [builtins fixtures/tuple.pyi] @@ -398,34 +398,34 @@ Ts = TypeVarTuple("Ts") def args_to_tuple(*args: Unpack[Ts]) -> Tuple[Unpack[Ts]]: with_prefix_suffix(*args) # E: Too few arguments for "with_prefix_suffix" \ - # E: Argument 1 to "with_prefix_suffix" has incompatible type "*Tuple[Unpack[Ts]]"; expected "bool" + # E: Argument 1 to "with_prefix_suffix" has incompatible type "*tuple[Unpack[Ts]]"; expected "bool" new_args = (True, "foo", *args, 5) with_prefix_suffix(*new_args) return args def with_prefix_suffix(*args: Unpack[Tuple[bool, str, Unpack[Ts], int]]) -> Tuple[bool, str, Unpack[Ts], int]: - reveal_type(args) # N: Revealed type is "Tuple[builtins.bool, builtins.str, Unpack[Ts`-1], builtins.int]" - reveal_type(args_to_tuple(*args)) # N: Revealed type is "Tuple[builtins.bool, builtins.str, Unpack[Ts`-1], builtins.int]" - reveal_type(args_to_tuple(1, *args, 'a')) # N: Revealed type is "Tuple[Literal[1]?, builtins.bool, builtins.str, Unpack[Ts`-1], builtins.int, Literal['a']?]" + reveal_type(args) # N: Revealed type is "tuple[builtins.bool, builtins.str, Unpack[Ts`-1], builtins.int]" + reveal_type(args_to_tuple(*args)) # N: Revealed type is "tuple[builtins.bool, builtins.str, Unpack[Ts`-1], builtins.int]" + reveal_type(args_to_tuple(1, *args, 'a')) # N: Revealed type is "tuple[Literal[1]?, builtins.bool, builtins.str, Unpack[Ts`-1], builtins.int, Literal['a']?]" return args -reveal_type(with_prefix_suffix(True, "bar", "foo", 5)) # N: Revealed type is "Tuple[builtins.bool, builtins.str, Literal['foo']?, builtins.int]" -reveal_type(with_prefix_suffix(True, "bar", 5)) # N: Revealed type is "Tuple[builtins.bool, builtins.str, builtins.int]" +reveal_type(with_prefix_suffix(True, "bar", "foo", 5)) # N: Revealed type is "tuple[builtins.bool, builtins.str, Literal['foo']?, builtins.int]" +reveal_type(with_prefix_suffix(True, "bar", 5)) # N: Revealed type is "tuple[builtins.bool, builtins.str, builtins.int]" with_prefix_suffix(True, "bar", "foo", 1.0) # E: Argument 4 to "with_prefix_suffix" has incompatible type "float"; expected "int" with_prefix_suffix(True, "bar") # E: Too few arguments for "with_prefix_suffix" t = (True, "bar", "foo", 5) -reveal_type(with_prefix_suffix(*t)) # N: Revealed type is "Tuple[builtins.bool, builtins.str, builtins.str, builtins.int]" -reveal_type(with_prefix_suffix(True, *("bar", "foo"), 5)) # N: Revealed type is "Tuple[builtins.bool, builtins.str, Literal['foo']?, builtins.int]" +reveal_type(with_prefix_suffix(*t)) # N: Revealed type is "tuple[builtins.bool, builtins.str, builtins.str, builtins.int]" +reveal_type(with_prefix_suffix(True, *("bar", "foo"), 5)) # N: Revealed type is "tuple[builtins.bool, builtins.str, Literal['foo']?, builtins.int]" -reveal_type(with_prefix_suffix(True, "bar", *["foo1", "foo2"], 5)) # N: Revealed type is "Tuple[builtins.bool, builtins.str, Unpack[builtins.tuple[builtins.str, ...]], builtins.int]" +reveal_type(with_prefix_suffix(True, "bar", *["foo1", "foo2"], 5)) # N: Revealed type is "tuple[builtins.bool, builtins.str, Unpack[builtins.tuple[builtins.str, ...]], builtins.int]" bad_t = (True, "bar") with_prefix_suffix(*bad_t) # E: Too few arguments for "with_prefix_suffix" def foo(*args: Unpack[Ts]) -> None: - reveal_type(with_prefix_suffix(True, "bar", *args, 5)) # N: Revealed type is "Tuple[builtins.bool, builtins.str, Unpack[Ts`-1], builtins.int]" + reveal_type(with_prefix_suffix(True, "bar", *args, 5)) # N: Revealed type is "tuple[builtins.bool, builtins.str, Unpack[Ts`-1], builtins.int]" [builtins fixtures/tuple.pyi] [case testTypeVarTuplePep646TypeVarStarArgsFixedLengthTuple] @@ -433,7 +433,7 @@ from typing import Tuple from typing_extensions import Unpack def foo(*args: Unpack[Tuple[int, str]]) -> None: - reveal_type(args) # N: Revealed type is "Tuple[builtins.int, builtins.str]" + reveal_type(args) # N: Revealed type is "tuple[builtins.int, builtins.str]" foo(0, "foo") foo(0, 1) # E: Argument 2 to "foo" has incompatible type "int"; expected "str" @@ -444,15 +444,15 @@ foo() # E: Too few arguments for "foo" foo(*(0, "foo")) def foo2(*args: Unpack[Tuple[bool, Unpack[Tuple[int, str]], bool]]) -> None: - reveal_type(args) # N: Revealed type is "Tuple[builtins.bool, builtins.int, builtins.str, builtins.bool]" + reveal_type(args) # N: Revealed type is "tuple[builtins.bool, builtins.int, builtins.str, builtins.bool]" # It is hard to normalize callable types in definition, because there is deep relation between `FuncDef.type` # and `FuncDef.arguments`, therefore various typeops need to be sure to normalize Callable types before using them. -reveal_type(foo2) # N: Revealed type is "def (*args: Unpack[Tuple[builtins.bool, builtins.int, builtins.str, builtins.bool]])" +reveal_type(foo2) # N: Revealed type is "def (*args: Unpack[tuple[builtins.bool, builtins.int, builtins.str, builtins.bool]])" class C: def foo2(self, *args: Unpack[Tuple[bool, Unpack[Tuple[int, str]], bool]]) -> None: ... -reveal_type(C().foo2) # N: Revealed type is "def (*args: Unpack[Tuple[builtins.bool, builtins.int, builtins.str, builtins.bool]])" +reveal_type(C().foo2) # N: Revealed type is "def (*args: Unpack[tuple[builtins.bool, builtins.int, builtins.str, builtins.bool]])" [builtins fixtures/tuple.pyi] [case testTypeVarTuplePep646TypeVarStarArgsVariableLengthTuple] @@ -466,7 +466,7 @@ foo(0, 1, 2) foo(0, 1, "bar") # E: Argument 3 to "foo" has incompatible type "str"; expected "int" def foo2(*args: Unpack[Tuple[str, Unpack[Tuple[int, ...]], bool, bool]]) -> None: - reveal_type(args) # N: Revealed type is "Tuple[builtins.str, Unpack[builtins.tuple[builtins.int, ...]], builtins.bool, builtins.bool]" + reveal_type(args) # N: Revealed type is "tuple[builtins.str, Unpack[builtins.tuple[builtins.int, ...]], builtins.bool, builtins.bool]" reveal_type(args[1]) # N: Revealed type is "builtins.int" def foo3(*args: Unpack[Tuple[str, Unpack[Tuple[int, ...]], str, float]]) -> None: @@ -480,7 +480,7 @@ def foo3(*args: Unpack[Tuple[str, Unpack[Tuple[int, ...]], str, float]]) -> None reveal_type(args[-3]) # N: Revealed type is "Union[builtins.str, builtins.int]" args[-4] # E: Tuple index out of range \ # N: Variadic tuple can have length 3 - reveal_type(args[::-1]) # N: Revealed type is "Tuple[builtins.float, builtins.str, Unpack[builtins.tuple[builtins.int, ...]], builtins.str]" + reveal_type(args[::-1]) # N: Revealed type is "tuple[builtins.float, builtins.str, Unpack[builtins.tuple[builtins.int, ...]], builtins.str]" args[::2] # E: Ambiguous slice of a variadic tuple args[:2] # E: Ambiguous slice of a variadic tuple @@ -490,8 +490,8 @@ def foo4(*args: Unpack[Tuple[str, Unpack[Ts], bool, bool]]) -> None: foo2("bar", 1, 2, 3, False, True) foo2(0, 1, 2, 3, False, True) # E: Argument 1 to "foo2" has incompatible type "int"; expected "str" -foo2("bar", "bar", 2, 3, False, True) # E: Argument 2 to "foo2" has incompatible type "str"; expected "Unpack[Tuple[Unpack[Tuple[int, ...]], bool, bool]]" -foo2("bar", 1, 2, 3, 4, True) # E: Argument 5 to "foo2" has incompatible type "int"; expected "Unpack[Tuple[Unpack[Tuple[int, ...]], bool, bool]]" +foo2("bar", "bar", 2, 3, False, True) # E: Argument 2 to "foo2" has incompatible type "str"; expected "Unpack[tuple[Unpack[tuple[int, ...]], bool, bool]]" +foo2("bar", 1, 2, 3, 4, True) # E: Argument 5 to "foo2" has incompatible type "int"; expected "Unpack[tuple[Unpack[tuple[int, ...]], bool, bool]]" foo2(*("bar", 1, 2, 3, False, True)) [builtins fixtures/tuple.pyi] @@ -553,7 +553,7 @@ from typing import Callable, Tuple, TypeVar from typing_extensions import Unpack, TypeVarTuple x: Callable[[str, Unpack[Tuple[int, ...]], bool], None] -reveal_type(x) # N: Revealed type is "def (builtins.str, *Unpack[Tuple[Unpack[builtins.tuple[builtins.int, ...]], builtins.bool]])" +reveal_type(x) # N: Revealed type is "def (builtins.str, *Unpack[tuple[Unpack[builtins.tuple[builtins.int, ...]], builtins.bool]])" T = TypeVar("T") S = TypeVar("S") @@ -562,7 +562,7 @@ A = Callable[[T, Unpack[Ts], S], int] y: A[int, str, bool] reveal_type(y) # N: Revealed type is "def (builtins.int, builtins.str, builtins.bool) -> builtins.int" z: A[Unpack[Tuple[int, ...]]] -reveal_type(z) # N: Revealed type is "def (builtins.int, *Unpack[Tuple[Unpack[builtins.tuple[builtins.int, ...]], builtins.int]]) -> builtins.int" +reveal_type(z) # N: Revealed type is "def (builtins.int, *Unpack[tuple[Unpack[builtins.tuple[builtins.int, ...]], builtins.int]]) -> builtins.int" [builtins fixtures/tuple.pyi] [case testTypeVarTuplePep646CallableInvalidSyntax] @@ -584,7 +584,7 @@ from typing_extensions import ParamSpec x: Callable[[str, *Tuple[int, ...]], None] reveal_type(x) # N: Revealed type is "def (builtins.str, *builtins.int)" y: Callable[[str, *Tuple[int, ...], bool], None] -reveal_type(y) # N: Revealed type is "def (builtins.str, *Unpack[Tuple[Unpack[builtins.tuple[builtins.int, ...]], builtins.bool]])" +reveal_type(y) # N: Revealed type is "def (builtins.str, *Unpack[tuple[Unpack[builtins.tuple[builtins.int, ...]], builtins.bool]])" P = ParamSpec("P") class C(Generic[P]): ... @@ -659,7 +659,7 @@ Ts = TypeVarTuple("Ts") A = List[Tuple[T, Unpack[Ts], T]] x: A[int, str, str] -reveal_type(x) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.str, builtins.str, builtins.int]]" +reveal_type(x) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.str, builtins.str, builtins.int]]" [builtins fixtures/tuple.pyi] [case testVariadicAliasBasicCallable] @@ -700,7 +700,7 @@ Ts = TypeVarTuple("Ts") Start = Tuple[int, str] A = List[Tuple[T, Unpack[Ts], S]] x: A[Unpack[Start], int] -reveal_type(x) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.str, builtins.int]]" +reveal_type(x) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.str, builtins.int]]" [builtins fixtures/tuple.pyi] [case testVariadicAliasUnpackFixedTupleTarget] @@ -714,7 +714,7 @@ Ts = TypeVarTuple("Ts") Prefix = Tuple[int, int] A = Tuple[Unpack[Prefix], Unpack[Ts]] x: A[str, str] -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int, builtins.str, builtins.str]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int, builtins.str, builtins.str]" [builtins fixtures/tuple.pyi] [case testVariadicAliasMultipleUnpacks] @@ -727,7 +727,7 @@ class G(Generic[Unpack[Ts]]): ... A = Tuple[Unpack[Ts], Unpack[Us]] # E: More than one Unpack in a type is not allowed x: A[int, str] -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.str]" B = Callable[[Unpack[Ts], Unpack[Us]], int] # E: More than one Unpack in a type is not allowed y: B[int, str] @@ -748,7 +748,7 @@ class G(Generic[Unpack[Ts]]): ... A = List[Tuple[T, Unpack[Ts], T]] x: A -reveal_type(x) # N: Revealed type is "builtins.list[Tuple[Any, Unpack[builtins.tuple[Any, ...]], Any]]" +reveal_type(x) # N: Revealed type is "builtins.list[tuple[Any, Unpack[builtins.tuple[Any, ...]], Any]]" B = Callable[[T, Unpack[Ts]], int] y: B @@ -770,7 +770,7 @@ class G(Generic[Unpack[Ts]]): ... A = List[Tuple[T, Unpack[Ts], S]] x: A[int] # E: Bad number of arguments for type alias, expected at least 2, given 1 -reveal_type(x) # N: Revealed type is "builtins.list[Tuple[Any, Unpack[builtins.tuple[Any, ...]], Any]]" +reveal_type(x) # N: Revealed type is "builtins.list[tuple[Any, Unpack[builtins.tuple[Any, ...]], Any]]" B = Callable[[T, S, Unpack[Ts]], int] y: B[int] # E: Bad number of arguments for type alias, expected at least 2, given 1 @@ -789,11 +789,11 @@ Ts = TypeVarTuple("Ts") A = Tuple[Unpack[Ts], Optional[A[Unpack[Ts]]]] x: A[int, str] -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.str, Union[..., None]]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.str, Union[..., None]]" *_, last = x if last is not None: - reveal_type(last) # N: Revealed type is "Tuple[builtins.int, builtins.str, Union[Tuple[builtins.int, builtins.str, Union[..., None]], None]]" + reveal_type(last) # N: Revealed type is "tuple[builtins.int, builtins.str, Union[tuple[builtins.int, builtins.str, Union[..., None]], None]]" [builtins fixtures/tuple.pyi] [case testVariadicAliasUpperBoundCheck] @@ -823,7 +823,7 @@ from typing_extensions import TypeVarTuple, Unpack Ts = TypeVarTuple("Ts") A = Tuple[int, Unpack[Ts], str] x: A[()] -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.str]" [builtins fixtures/tuple.pyi] [case testVariadicAliasVariadicTupleArg] @@ -836,7 +836,7 @@ A = Tuple[int, Unpack[Ts]] B = A[str, Unpack[Ts]] C = B[Unpack[Tuple[bool, ...]]] x: C -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.str, Unpack[builtins.tuple[builtins.bool, ...]]]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.str, Unpack[builtins.tuple[builtins.bool, ...]]]" [builtins fixtures/tuple.pyi] [case testVariadicAliasVariadicTupleArgGeneric] @@ -849,7 +849,7 @@ Ts = TypeVarTuple("Ts") A = Tuple[int, Unpack[Ts]] B = A[Unpack[Tuple[T, ...]]] x: B[str] -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.str, ...]]]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.str, ...]]]" [builtins fixtures/tuple.pyi] [case testVariadicAliasVariadicTupleArgSplit] @@ -863,10 +863,10 @@ Ts = TypeVarTuple("Ts") A = Tuple[T, Unpack[Ts], S, T] x: A[int, Unpack[Tuple[bool, ...]], str] -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.bool, ...]], builtins.str, builtins.int]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.bool, ...]], builtins.str, builtins.int]" y: A[Unpack[Tuple[bool, ...]]] -reveal_type(y) # N: Revealed type is "Tuple[builtins.bool, Unpack[builtins.tuple[builtins.bool, ...]], builtins.bool, builtins.bool]" +reveal_type(y) # N: Revealed type is "tuple[builtins.bool, Unpack[builtins.tuple[builtins.bool, ...]], builtins.bool, builtins.bool]" [builtins fixtures/tuple.pyi] [case testBanPathologicalRecursiveTuples] @@ -881,7 +881,7 @@ y: B z: C reveal_type(x) # N: Revealed type is "Any" reveal_type(y) # N: Revealed type is "Any" -reveal_type(z) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[Any, ...]]]" +reveal_type(z) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[Any, ...]]]" [builtins fixtures/tuple.pyi] @@ -1009,7 +1009,7 @@ Ints = Tuple[int, int] c: C[Unpack[Ints]] reveal_type(c.prefix) # N: Revealed type is "builtins.int" reveal_type(c.suffix) # N: Revealed type is "builtins.int" -reveal_type(c.middle) # N: Revealed type is "Tuple[()]" +reveal_type(c.middle) # N: Revealed type is "tuple[()]" [builtins fixtures/tuple.pyi] [case testVariadicUnpackItemInInstanceArguments] @@ -1079,12 +1079,12 @@ class A(Tuple[Unpack[Ts]]): fn: Callable[[Unpack[Ts]], None] x: A[int] -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.A[builtins.int]]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, fallback=__main__.A[builtins.int]]" reveal_type(x[0]) # N: Revealed type is "builtins.int" reveal_type(x.fn) # N: Revealed type is "def (builtins.int)" y: A[int, str] -reveal_type(y) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.A[builtins.int, builtins.str]]" +reveal_type(y) # N: Revealed type is "tuple[builtins.int, builtins.str, fallback=__main__.A[builtins.int, builtins.str]]" reveal_type(y[0]) # N: Revealed type is "builtins.int" reveal_type(y.fn) # N: Revealed type is "def (builtins.int, builtins.str)" @@ -1094,7 +1094,7 @@ reveal_type(z[0]) # N: Revealed type is "builtins.int" reveal_type(z.fn) # N: Revealed type is "def (*builtins.int)" t: A[int, Unpack[Tuple[int, str]], str] -reveal_type(t) # N: Revealed type is "Tuple[builtins.int, builtins.int, builtins.str, builtins.str, fallback=__main__.A[builtins.int, builtins.int, builtins.str, builtins.str]]" +reveal_type(t) # N: Revealed type is "tuple[builtins.int, builtins.int, builtins.str, builtins.str, fallback=__main__.A[builtins.int, builtins.int, builtins.str, builtins.str]]" reveal_type(t[0]) # N: Revealed type is "builtins.int" reveal_type(t.fn) # N: Revealed type is "def (builtins.int, builtins.int, builtins.str, builtins.str)" [builtins fixtures/tuple.pyi] @@ -1110,20 +1110,20 @@ class A(NamedTuple, Generic[Unpack[Ts], T]): val: T y: A[int, str] -reveal_type(y) # N: Revealed type is "Tuple[def (builtins.int), builtins.str, fallback=__main__.A[builtins.int, builtins.str]]" +reveal_type(y) # N: Revealed type is "tuple[def (builtins.int), builtins.str, fallback=__main__.A[builtins.int, builtins.str]]" reveal_type(y[0]) # N: Revealed type is "def (builtins.int)" reveal_type(y.fn) # N: Revealed type is "def (builtins.int)" z: A[Unpack[Tuple[int, ...]]] -reveal_type(z) # N: Revealed type is "Tuple[def (*builtins.int), builtins.int, fallback=__main__.A[Unpack[builtins.tuple[builtins.int, ...]], builtins.int]]" +reveal_type(z) # N: Revealed type is "tuple[def (*builtins.int), builtins.int, fallback=__main__.A[Unpack[builtins.tuple[builtins.int, ...]], builtins.int]]" reveal_type(z.fn) # N: Revealed type is "def (*builtins.int)" t: A[int, Unpack[Tuple[int, str]], str] -reveal_type(t) # N: Revealed type is "Tuple[def (builtins.int, builtins.int, builtins.str), builtins.str, fallback=__main__.A[builtins.int, builtins.int, builtins.str, builtins.str]]" +reveal_type(t) # N: Revealed type is "tuple[def (builtins.int, builtins.int, builtins.str), builtins.str, fallback=__main__.A[builtins.int, builtins.int, builtins.str, builtins.str]]" def test(x: int, y: str) -> None: ... 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]]" +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]" @@ -1200,9 +1200,9 @@ Alias = Tuple[int, Unpack[Ts], str] A = Union[int, str] x: List[Alias[int, Unpack[A], str]] # E: "Union[int, str]" cannot be unpacked (must be tuple or TypeVarTuple) -reveal_type(x) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.int, Unpack[builtins.tuple[Any, ...]], builtins.str, builtins.str]]" +reveal_type(x) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.int, Unpack[builtins.tuple[Any, ...]], builtins.str, builtins.str]]" y: List[Alias[int, Unpack[Undefined], str]] # E: Name "Undefined" is not defined -reveal_type(y) # N: Revealed type is "builtins.list[Tuple[builtins.int, Unpack[builtins.tuple[Any, ...]], builtins.str]]" +reveal_type(y) # N: Revealed type is "builtins.list[tuple[builtins.int, Unpack[builtins.tuple[Any, ...]], builtins.str]]" [builtins fixtures/tuple.pyi] [case testVariadicAliasForwardRefToFixedUnpack] @@ -1215,7 +1215,7 @@ Ts = TypeVarTuple("Ts") Alias = Tuple[T, Unpack[Ts], S] x: Alias[int, Unpack[Other]] Other = Tuple[int, str] -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int, builtins.str]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int, builtins.str]" [builtins fixtures/tuple.pyi] [case testVariadicAliasForwardRefToVariadicUnpack] @@ -1228,7 +1228,7 @@ Ts = TypeVarTuple("Ts") Alias = Tuple[T, Unpack[Ts], S] x: Alias[int, Unpack[Other]] Other = Tuple[int, ...] -reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]], builtins.int]" +reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]], builtins.int]" [builtins fixtures/tuple.pyi] [case testVariadicInstanceStrictPrefixSuffixCheck] @@ -1271,7 +1271,7 @@ class A(Tuple[Unpack[TP]]): ... def test(d: A[int, str]) -> None: if isinstance(d, A): - reveal_type(d) # N: Revealed type is "Tuple[builtins.int, builtins.str, fallback=__main__.A[builtins.int, builtins.str]]" + reveal_type(d) # N: Revealed type is "tuple[builtins.int, builtins.str, fallback=__main__.A[builtins.int, builtins.str]]" else: reveal_type(d) # E: Statement is unreachable @@ -1315,7 +1315,7 @@ f2(t1) f2(t2) f2(t3) f2(t4) -f2(t5) # E: Argument 1 to "f2" has incompatible type "Tuple[int, ...]"; expected "Tuple[float, Unpack[Tuple[float, ...]]]" +f2(t5) # E: Argument 1 to "f2" has incompatible type "tuple[int, ...]"; expected "tuple[float, Unpack[tuple[float, ...]]]" f2(tl) f2(tr) @@ -1324,16 +1324,16 @@ f3(t1) f3(t2) f3(t3) f3(t4) -f3(t5) # E: Argument 1 to "f3" has incompatible type "Tuple[int, ...]"; expected "Tuple[Unpack[Tuple[float, ...]], float]" +f3(t5) # E: Argument 1 to "f3" has incompatible type "tuple[int, ...]"; expected "tuple[Unpack[tuple[float, ...]], float]" f3(tl) f3(tr) f4(t1) -f4(t2) # E: Argument 1 to "f4" has incompatible type "Tuple[int, Unpack[Tuple[int, ...]]]"; expected "Tuple[float, Unpack[Tuple[float, ...]], float]" -f4(t3) # E: Argument 1 to "f4" has incompatible type "Tuple[Unpack[Tuple[int, ...]], int]"; expected "Tuple[float, Unpack[Tuple[float, ...]], float]" +f4(t2) # E: Argument 1 to "f4" has incompatible type "tuple[int, Unpack[tuple[int, ...]]]"; expected "tuple[float, Unpack[tuple[float, ...]], float]" +f4(t3) # E: Argument 1 to "f4" has incompatible type "tuple[Unpack[tuple[int, ...]], int]"; expected "tuple[float, Unpack[tuple[float, ...]], float]" f4(t4) -f4(t5) # E: Argument 1 to "f4" has incompatible type "Tuple[int, ...]"; expected "Tuple[float, Unpack[Tuple[float, ...]], float]" +f4(t5) # E: Argument 1 to "f4" has incompatible type "tuple[int, ...]"; expected "tuple[float, Unpack[tuple[float, ...]], float]" f4(tl) f4(tr) @@ -1350,7 +1350,7 @@ T = TypeVar("T") def f(x: Tuple[int, Unpack[Tuple[T, ...]]]) -> T: ... vt0: Tuple[int, ...] -f(vt0) # E: Argument 1 to "f" has incompatible type "Tuple[int, ...]"; expected "Tuple[int, Unpack[Tuple[int, ...]]]" +f(vt0) # E: Argument 1 to "f" has incompatible type "tuple[int, ...]"; expected "tuple[int, Unpack[tuple[int, ...]]]" vt1: Tuple[Unpack[Tuple[int, ...]], int] reveal_type(f(vt1)) # N: Revealed type is "builtins.int" @@ -1358,12 +1358,12 @@ reveal_type(f(vt1)) # N: Revealed type is "builtins.int" S = TypeVar("S") Ts = TypeVarTuple("Ts") def g(x: Tuple[T, Unpack[Ts], S]) -> Tuple[T, Unpack[Ts], S]: ... -g(vt0) # E: Argument 1 to "g" has incompatible type "Tuple[int, ...]"; expected "Tuple[int, Unpack[Tuple[int, ...]], int]" +g(vt0) # E: Argument 1 to "g" has incompatible type "tuple[int, ...]"; expected "tuple[int, Unpack[tuple[int, ...]], int]" U = TypeVar("U") def h(x: List[Tuple[T, S, U]]) -> Tuple[T, S, U]: ... vt2: Tuple[Unpack[Tuple[int, ...]], int] -vt2 = h(reveal_type([])) # N: Revealed type is "builtins.list[Tuple[builtins.int, builtins.int, builtins.int]]" +vt2 = h(reveal_type([])) # N: Revealed type is "builtins.list[tuple[builtins.int, builtins.int, builtins.int]]" [builtins fixtures/tuple.pyi] [case testVariadicSelfTypeErasure] @@ -1395,7 +1395,7 @@ fii(C()) # E: Argument 1 to "fii" has incompatible type "C"; expected "B[int, i fii(D()) # E: Argument 1 to "fii" has incompatible type "D"; expected "B[int, int]" fis(C()) fis(D()) # E: Argument 1 to "fis" has incompatible type "D"; expected "B[int, str]" -fiv(C()) # E: Argument 1 to "fiv" has incompatible type "C"; expected "B[Unpack[Tuple[int, ...]]]" +fiv(C()) # E: Argument 1 to "fiv" has incompatible type "C"; expected "B[Unpack[tuple[int, ...]]]" fiv(D()) [builtins fixtures/tuple.pyi] @@ -1417,14 +1417,14 @@ civ: C[Unpack[Tuple[int, ...]]] fii(cii) fii(cis) # E: Argument 1 to "fii" has incompatible type "C[int, str]"; expected "B[int, int]" -fii(civ) # E: Argument 1 to "fii" has incompatible type "C[Unpack[Tuple[int, ...]]]"; expected "B[int, int]" +fii(civ) # E: Argument 1 to "fii" has incompatible type "C[Unpack[tuple[int, ...]]]"; expected "B[int, int]" fis(cii) # E: Argument 1 to "fis" has incompatible type "C[int, int]"; expected "B[int, str]" fis(cis) -fis(civ) # E: Argument 1 to "fis" has incompatible type "C[Unpack[Tuple[int, ...]]]"; expected "B[int, str]" +fis(civ) # E: Argument 1 to "fis" has incompatible type "C[Unpack[tuple[int, ...]]]"; expected "B[int, str]" fiv(cii) -fiv(cis) # E: Argument 1 to "fiv" has incompatible type "C[int, str]"; expected "B[Unpack[Tuple[int, ...]]]" +fiv(cis) # E: Argument 1 to "fiv" has incompatible type "C[int, str]"; expected "B[Unpack[tuple[int, ...]]]" fiv(civ) [builtins fixtures/tuple.pyi] @@ -1447,10 +1447,10 @@ civ: C[Unpack[Tuple[int, ...]]] ff(cii) ff(cis) # E: Argument 1 to "ff" has incompatible type "C[int, str]"; expected "B[int, int, int]" -ff(civ) # E: Argument 1 to "ff" has incompatible type "C[Unpack[Tuple[int, ...]]]"; expected "B[int, int, int]" +ff(civ) # E: Argument 1 to "ff" has incompatible type "C[Unpack[tuple[int, ...]]]"; expected "B[int, int, int]" fv(cii) -fv(cis) # E: Argument 1 to "fv" has incompatible type "C[int, str]"; expected "B[Unpack[Tuple[int, ...]]]" +fv(cis) # E: Argument 1 to "fv" has incompatible type "C[int, str]"; expected "B[Unpack[tuple[int, ...]]]" fv(civ) [builtins fixtures/tuple.pyi] @@ -1486,17 +1486,17 @@ class C3(B[int, Unpack[Ts], T]): ... class C4(B[Unpack[Tuple[T, ...]]]): ... c1: C1 -reveal_type(c1.meth()) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(c1.meth()) # N: Revealed type is "tuple[builtins.int, builtins.str]" c2f: C2[int, str] c2v: C2[Unpack[Tuple[int, ...]]] -reveal_type(c2f.meth()) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(c2f.meth()) # N: Revealed type is "tuple[builtins.int, builtins.str]" reveal_type(c2v.meth()) # N: Revealed type is "builtins.tuple[builtins.int, ...]" c3f: C3[int, str] c3v: C3[Unpack[Tuple[int, ...]]] -reveal_type(c3f.meth()) # N: Revealed type is "Tuple[builtins.int, builtins.int, builtins.str]" -reveal_type(c3v.meth()) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]], builtins.int]" +reveal_type(c3f.meth()) # N: Revealed type is "tuple[builtins.int, builtins.int, builtins.str]" +reveal_type(c3v.meth()) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]], builtins.int]" c4: C4[int] reveal_type(c4.meth()) # N: Revealed type is "builtins.tuple[builtins.int, ...]" @@ -1649,9 +1649,9 @@ from typing_extensions import TypeVarTuple, Unpack Ts = TypeVarTuple("Ts") def foo(arg: Tuple[int, Unpack[Ts], str]) -> None: x = *arg, - reveal_type(x) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`-1], builtins.str]" + reveal_type(x) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`-1], builtins.str]" y = 1, *arg, 2 - reveal_type(y) # N: Revealed type is "Tuple[builtins.int, builtins.int, Unpack[Ts`-1], builtins.str, builtins.int]" + reveal_type(y) # N: Revealed type is "tuple[builtins.int, builtins.int, Unpack[Ts`-1], builtins.str, builtins.int]" z = (*arg, *arg) reveal_type(z) # N: Revealed type is "builtins.tuple[builtins.object, ...]" [builtins fixtures/tuple.pyi] @@ -1667,14 +1667,14 @@ b: Tuple[int, Unpack[Tuple[float, ...]], str] x = *a, reveal_type(x) # N: Revealed type is "builtins.tuple[builtins.float, ...]" y = 1, *a, 2 -reveal_type(y) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.int]" +reveal_type(y) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.int]" z = (*a, *a) reveal_type(z) # N: Revealed type is "builtins.tuple[builtins.float, ...]" x2 = *b, -reveal_type(x2) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" +reveal_type(x2) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str]" y2 = 1, *b, 2 -reveal_type(y2) # N: Revealed type is "Tuple[builtins.int, builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str, builtins.int]" +reveal_type(y2) # N: Revealed type is "tuple[builtins.int, builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.str, builtins.int]" z2 = (*b, *b) reveal_type(z2) # N: Revealed type is "builtins.tuple[builtins.object, ...]" [builtins fixtures/tuple.pyi] @@ -1714,16 +1714,16 @@ from typing_extensions import TypeVarTuple, Unpack vtf: Tuple[float, ...] vt: Tuple[int, Unpack[Tuple[float, ...]], int] -reveal_type(vt + (1, 2)) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.int, Literal[1]?, Literal[2]?]" -reveal_type((1, 2) + vt) # N: Revealed type is "Tuple[Literal[1]?, Literal[2]?, builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.int]" +reveal_type(vt + (1, 2)) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.int, Literal[1]?, Literal[2]?]" +reveal_type((1, 2) + vt) # N: Revealed type is "tuple[Literal[1]?, Literal[2]?, builtins.int, Unpack[builtins.tuple[builtins.float, ...]], builtins.int]" reveal_type(vt + vt) # N: Revealed type is "builtins.tuple[Union[builtins.int, builtins.float], ...]" -reveal_type(vtf + (1, 2)) # N: Revealed type is "Tuple[Unpack[builtins.tuple[builtins.float, ...]], Literal[1]?, Literal[2]?]" -reveal_type((1, 2) + vtf) # N: Revealed type is "Tuple[Literal[1]?, Literal[2]?, Unpack[builtins.tuple[builtins.float, ...]]]" +reveal_type(vtf + (1, 2)) # N: Revealed type is "tuple[Unpack[builtins.tuple[builtins.float, ...]], Literal[1]?, Literal[2]?]" +reveal_type((1, 2) + vtf) # N: Revealed type is "tuple[Literal[1]?, Literal[2]?, Unpack[builtins.tuple[builtins.float, ...]]]" Ts = TypeVarTuple("Ts") def foo(arg: Tuple[int, Unpack[Ts], str]) -> None: - reveal_type(arg + (1, 2)) # N: Revealed type is "Tuple[builtins.int, Unpack[Ts`-1], builtins.str, Literal[1]?, Literal[2]?]" - reveal_type((1, 2) + arg) # N: Revealed type is "Tuple[Literal[1]?, Literal[2]?, builtins.int, Unpack[Ts`-1], builtins.str]" + reveal_type(arg + (1, 2)) # N: Revealed type is "tuple[builtins.int, Unpack[Ts`-1], builtins.str, Literal[1]?, Literal[2]?]" + reveal_type((1, 2) + arg) # N: Revealed type is "tuple[Literal[1]?, Literal[2]?, builtins.int, Unpack[Ts`-1], builtins.str]" reveal_type(arg + arg) # N: Revealed type is "builtins.tuple[builtins.object, ...]" [builtins fixtures/tuple.pyi] @@ -1807,7 +1807,7 @@ def add(self: Tuple[T, ...], other: Tuple[T, ...]) -> Tuple[T, ...]: def add(self: Any, other: Any) -> Any: ... def test(a: Tuple[int, str], b: Tuple[bool], c: Tuple[bool, ...]): - reveal_type(add(a, b)) # N: Revealed type is "Tuple[builtins.int, builtins.str, builtins.bool]" + reveal_type(add(a, b)) # N: Revealed type is "tuple[builtins.int, builtins.str, builtins.bool]" reveal_type(add(b, c)) # N: Revealed type is "builtins.tuple[builtins.bool, ...]" [builtins fixtures/tuple.pyi] @@ -1923,7 +1923,7 @@ def foo(func: Callable[[Unpack[Args]], T], *args: Unpack[Args]) -> T: return submit(func, *args) def foo2(func: Callable[[Unpack[Args]], T], *args: Unpack[Args2]) -> T: - return submit(func, *args) # E: Argument 2 to "submit" has incompatible type "*Tuple[Unpack[Args2]]"; expected "Unpack[Args]" + return submit(func, *args) # E: Argument 2 to "submit" has incompatible type "*tuple[Unpack[Args2]]"; expected "Unpack[Args]" def foo3(func: Callable[[int, Unpack[Args2]], T], *args: Unpack[Args2]) -> T: return submit(func, 1, *args) @@ -2015,12 +2015,12 @@ from typing_extensions import TypeVarTuple, Unpack Ts = TypeVarTuple("Ts") class B(Generic[Unpack[Ts]]): def __init__(self, x: Tuple[Unpack[Ts]], *args: Unpack[Ts]) -> None: ... -reveal_type(B) # N: Revealed type is "def [Ts] (x: Tuple[Unpack[Ts`1]], *args: Unpack[Ts`1]) -> __main__.B[Unpack[Ts`1]]" +reveal_type(B) # N: Revealed type is "def [Ts] (x: tuple[Unpack[Ts`1]], *args: Unpack[Ts`1]) -> __main__.B[Unpack[Ts`1]]" T = TypeVar("T") S = TypeVar("S") class C(B[T, S]): ... -reveal_type(C) # N: Revealed type is "def [T, S] (x: Tuple[T`1, S`2], T`1, S`2) -> __main__.C[T`1, S`2]" +reveal_type(C) # N: Revealed type is "def [T, S] (x: tuple[T`1, S`2], T`1, S`2) -> __main__.C[T`1, S`2]" [builtins fixtures/tuple.pyi] [case testVariadicClassGenericSelf] @@ -2035,13 +2035,13 @@ 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]]" \ - # N: Revealed type is "Tuple[Never, Never]" +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]]" \ + # 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]" +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]]" \ - # N: Revealed type is "Tuple[Never, Never]" +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]]" \ + # N: Revealed type is "tuple[Never, Never]" class C(B[T, S]): ... c: C[int, str] @@ -2084,9 +2084,9 @@ Ts = TypeVarTuple("Ts") class B(Generic[Unpack[Ts]]): items: Tuple[Unpack[Ts]] -reveal_type(B) # N: Revealed type is "def [Ts] (items: Tuple[Unpack[Ts`1]]) -> __main__.B[Unpack[Ts`1]]" +reveal_type(B) # N: Revealed type is "def [Ts] (items: tuple[Unpack[Ts`1]]) -> __main__.B[Unpack[Ts`1]]" b = B((1, "yes")) -reveal_type(b.items) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(b.items) # N: Revealed type is "tuple[builtins.int, builtins.str]" T = TypeVar("T") S = TypeVar("S") @@ -2096,9 +2096,9 @@ class C(B[T, S]): first: T second: S -reveal_type(C) # N: Revealed type is "def [T, S] (items: Tuple[T`1, S`2], first: T`1, second: S`2) -> __main__.C[T`1, S`2]" +reveal_type(C) # N: Revealed type is "def [T, S] (items: tuple[T`1, S`2], first: T`1, second: S`2) -> __main__.C[T`1, S`2]" c = C((1, "yes"), 2, "no") -reveal_type(c.items) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(c.items) # N: Revealed type is "tuple[builtins.int, builtins.str]" reveal_type(c.first) # N: Revealed type is "builtins.int" reveal_type(c.second) # N: Revealed type is "builtins.str" [builtins fixtures/dataclasses.pyi] @@ -2127,17 +2127,17 @@ class Good: def meth(self, __x: int, y: str) -> None: ... g: Good -reveal_type(get_items(g)) # N: Revealed type is "Tuple[builtins.int, builtins.str]" -reveal_type(match(g)) # N: Revealed type is "Tuple[builtins.int, builtins.str]" +reveal_type(get_items(g)) # N: Revealed type is "tuple[builtins.int, builtins.str]" +reveal_type(match(g)) # N: Revealed type is "tuple[builtins.int, builtins.str]" b: Bad -get_items(b) # E: Argument 1 to "get_items" has incompatible type "Bad"; expected "P[Unpack[Tuple[Never, ...]]]" \ +get_items(b) # E: Argument 1 to "get_items" has incompatible type "Bad"; expected "P[Unpack[tuple[Never, ...]]]" \ # N: Following member(s) of "Bad" have conflicts: \ # N: Expected: \ - # N: def items(self) -> Tuple[Never, ...] \ + # N: def items(self) -> tuple[Never, ...] \ # N: Got: \ - # N: def items(self) -> List[int] -match(b) # E: Argument 1 to "match" has incompatible type "Bad"; expected "PC[Unpack[Tuple[Never, ...]]]" \ + # N: def items(self) -> list[int] +match(b) # E: Argument 1 to "match" has incompatible type "Bad"; expected "PC[Unpack[tuple[Never, ...]]]" \ # N: Following member(s) of "Bad" have conflicts: \ # N: Expected: \ # N: def meth(self, *args: Never) -> None \ @@ -2161,10 +2161,10 @@ from typing import Callable, Tuple f: Callable[[int, *Tuple[str, ...], int], None] g: Callable[[int, *Tuple[str, ...], int], None] -reveal_type([f, g]) # N: Revealed type is "builtins.list[def (builtins.int, *Unpack[Tuple[Unpack[builtins.tuple[builtins.str, ...]], builtins.int]])]" +reveal_type([f, g]) # N: Revealed type is "builtins.list[def (builtins.int, *Unpack[tuple[Unpack[builtins.tuple[builtins.str, ...]], builtins.int]])]" h: Callable[[int, *Tuple[str, ...], str], None] -reveal_type([f, h]) # N: Revealed type is "builtins.list[def (builtins.int, *Unpack[Tuple[Unpack[builtins.tuple[builtins.str, ...]], Never]])]" +reveal_type([f, h]) # N: Revealed type is "builtins.list[def (builtins.int, *Unpack[tuple[Unpack[builtins.tuple[builtins.str, ...]], Never]])]" [builtins fixtures/tuple.pyi] [case testTypeVarTupleBothUnpacksSimple] @@ -2219,7 +2219,7 @@ cb: Callable[[Unpack[Ints], Unpack[Keywords]], None] reveal_type(cb) # N: Revealed type is "def (*builtins.int, **Unpack[TypedDict('__main__.Keywords', {'a': builtins.str, 'b': builtins.str})])" cb2: Callable[[int, Unpack[Ints], int, Unpack[Keywords]], None] -reveal_type(cb2) # N: Revealed type is "def (builtins.int, *Unpack[Tuple[Unpack[builtins.tuple[builtins.int, ...]], builtins.int]], **Unpack[TypedDict('__main__.Keywords', {'a': builtins.str, 'b': builtins.str})])" +reveal_type(cb2) # N: Revealed type is "def (builtins.int, *Unpack[tuple[Unpack[builtins.tuple[builtins.int, ...]], builtins.int]], **Unpack[TypedDict('__main__.Keywords', {'a': builtins.str, 'b': builtins.str})])" cb2(1, 2, 3, a="a", b="b") cb2(1, a="a", b="b") # E: Too few arguments cb2(1, 2, 3, a="a") # E: Missing named argument "b" @@ -2283,7 +2283,7 @@ keys: Tuple[Unpack[Tuple[int, ...]]] foo(keys, 1) foo(*keys, 1) -bar(keys, 1) # E: Argument 1 to "bar" has incompatible type "Tuple[Unpack[Tuple[int, ...]]]"; expected "int" +bar(keys, 1) # E: Argument 1 to "bar" has incompatible type "tuple[Unpack[tuple[int, ...]]]"; expected "int" bar(*keys, 1) # OK reveal_type(baz(keys, 1)) # N: Revealed type is "builtins.object" @@ -2293,7 +2293,7 @@ reveal_type(baz(*keys, 1)) # N: Revealed type is "builtins.int" [case testVariadicTupleContextNoCrash] from typing import Tuple, Unpack -x: Tuple[int, Unpack[Tuple[int, ...]]] = () # E: Incompatible types in assignment (expression has type "Tuple[()]", variable has type "Tuple[int, Unpack[Tuple[int, ...]]]") +x: Tuple[int, Unpack[Tuple[int, ...]]] = () # E: Incompatible types in assignment (expression has type "tuple[()]", variable has type "tuple[int, Unpack[tuple[int, ...]]]") y: Tuple[int, Unpack[Tuple[int, ...]]] = (1, 2) z: Tuple[int, Unpack[Tuple[int, ...]]] = (1,) w: Tuple[int, Unpack[Tuple[int, ...]]] = (1, *[2, 3, 4]) @@ -2339,10 +2339,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 "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]" [builtins fixtures/tuple.pyi] [case testAliasToCallableWithUnpackInvalid] @@ -2381,7 +2381,7 @@ def func(x: Array[Unpack[Ts]], *args: Unpack[Ts]) -> Tuple[Unpack[Ts]]: ... def a2(x: Array[int, str]) -> None: - reveal_type(func(x, 2, "Hello")) # N: Revealed type is "Tuple[builtins.int, builtins.str]" + reveal_type(func(x, 2, "Hello")) # N: Revealed type is "tuple[builtins.int, builtins.str]" reveal_type(func(x, 2)) # E: Cannot infer type argument 1 of "func" \ # N: Revealed type is "builtins.tuple[Any, ...]" reveal_type(func(x, 2, "Hello", True)) # E: Cannot infer type argument 1 of "func" \ @@ -2429,8 +2429,8 @@ Ts = TypeVarTuple("Ts") @cm def test(*args: Unpack[Ts]) -> Tuple[Unpack[Ts]]: ... -reveal_type(test) # N: Revealed type is "def [Ts] (*args: Unpack[Ts`-1]) -> __main__.CM[Tuple[Unpack[Ts`-1]]]" -reveal_type(test(1, 2, 3)) # N: Revealed type is "__main__.CM[Tuple[Literal[1]?, Literal[2]?, Literal[3]?]]" +reveal_type(test) # N: Revealed type is "def [Ts] (*args: Unpack[Ts`-1]) -> __main__.CM[tuple[Unpack[Ts`-1]]]" +reveal_type(test(1, 2, 3)) # N: Revealed type is "__main__.CM[tuple[Literal[1]?, Literal[2]?, Literal[3]?]]" [builtins fixtures/tuple.pyi] [case testTypeVarTupleAgainstParamSpecActualFailedNoCrash] @@ -2444,7 +2444,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 "Callable[[VarArg(Unpack[Ts])], tuple[Unpack[Ts]]]"; expected "Callable[[VarArg(Never)], list[Never]]" def test(*args: Unpack[Ts]) -> Tuple[Unpack[Ts]]: ... reveal_type(test) # N: Revealed type is "def (*args: Never) -> __main__.CM[Never]" @@ -2465,7 +2465,7 @@ Ts = TypeVarTuple("Ts") @cm def test(x: T, *args: Unpack[Ts]) -> Tuple[T, Unpack[Ts]]: ... -reveal_type(test) # N: Revealed type is "def [T, Ts] (builtins.list[T`2], *args: Unpack[Ts`-2]) -> __main__.CM[Tuple[T`2, Unpack[Ts`-2]]]" +reveal_type(test) # N: Revealed type is "def [T, Ts] (builtins.list[T`2], *args: Unpack[Ts`-2]) -> __main__.CM[tuple[T`2, Unpack[Ts`-2]]]" [builtins fixtures/tuple.pyi] [case testMixingTypeVarTupleAndParamSpec] @@ -2506,7 +2506,7 @@ class Foo(Generic[Unpack[Ts]]): x1: Foo[Unpack[tuple[int, ...]]] y1: Foo[Unpack[tuple[str, ...]]] -x1 is y1 # E: Non-overlapping identity check (left operand type: "Foo[Unpack[Tuple[int, ...]]]", right operand type: "Foo[Unpack[Tuple[str, ...]]]") +x1 is y1 # E: Non-overlapping identity check (left operand type: "Foo[Unpack[tuple[int, ...]]]", right operand type: "Foo[Unpack[tuple[str, ...]]]") x2: Foo[Unpack[tuple[int, ...]]] y2: Foo[Unpack[tuple[int, ...]]] @@ -2518,7 +2518,7 @@ x3 is y3 x4: Foo[Unpack[tuple[str, ...]]] y4: Foo[Unpack[tuple[int, int]]] -x4 is y4 # E: Non-overlapping identity check (left operand type: "Foo[Unpack[Tuple[str, ...]]]", right operand type: "Foo[int, int]") +x4 is y4 # E: Non-overlapping identity check (left operand type: "Foo[Unpack[tuple[str, ...]]]", right operand type: "Foo[int, int]") [builtins fixtures/tuple.pyi] [case testTypeVarTupleErasureNormalized] @@ -2557,9 +2557,9 @@ class Base(Generic[Unpack[Ts]]): Ss = TypeVarTuple("Ss") class Derived(Base[str, Unpack[Ss]]): def test(self) -> None: - reveal_type(self.attr) # N: Revealed type is "Tuple[builtins.str, Unpack[Ss`1]]" - reveal_type(self.prop) # N: Revealed type is "Tuple[builtins.str, Unpack[Ss`1]]" - reveal_type(self.meth()) # N: Revealed type is "Tuple[builtins.str, Unpack[Ss`1]]" + reveal_type(self.attr) # N: Revealed type is "tuple[builtins.str, Unpack[Ss`1]]" + reveal_type(self.prop) # N: Revealed type is "tuple[builtins.str, Unpack[Ss`1]]" + reveal_type(self.meth()) # N: Revealed type is "tuple[builtins.str, Unpack[Ss`1]]" [builtins fixtures/property.pyi] [case testTypeVarTupleProtocolPrefix] @@ -2574,7 +2574,7 @@ class C: def f(x: A[Unpack[Ts]]) -> tuple[Unpack[Ts]]: ... -reveal_type(f(C())) # N: Revealed type is "Tuple[builtins.int]" +reveal_type(f(C())) # N: Revealed type is "tuple[builtins.int]" [builtins fixtures/tuple.pyi] [case testTypeVarTupleHomogeneousCallableNormalized] @@ -2603,8 +2603,8 @@ def test(xs: tuple[Unpack[Ts]], xsi: tuple[int, Unpack[Ts]]) -> None: reveal_type(join(xs, aa)) # N: Revealed type is "builtins.tuple[Any, ...]" reveal_type(join(aa, xs)) # N: Revealed type is "builtins.tuple[Any, ...]" ai: tuple[int, Unpack[tuple[Any, ...]]] - reveal_type(join(xsi, ai)) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[Any, ...]]]" - reveal_type(join(ai, xsi)) # N: Revealed type is "Tuple[builtins.int, Unpack[builtins.tuple[Any, ...]]]" + reveal_type(join(xsi, ai)) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[Any, ...]]]" + reveal_type(join(ai, xsi)) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[Any, ...]]]" [builtins fixtures/tuple.pyi] [case testTypeVarTupleInferAgainstAnyCallableSuffix] diff --git a/test-data/unit/check-typevar-values.test b/test-data/unit/check-typevar-values.test index 36ab3af6d3e9..ab2956374c12 100644 --- a/test-data/unit/check-typevar-values.test +++ b/test-data/unit/check-typevar-values.test @@ -20,7 +20,7 @@ if int(): i = f(1) s = f('') o = f(1) \ - # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[object]") \ + # E: Incompatible types in assignment (expression has type "list[int]", variable has type "list[object]") \ # N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \ # N: Consider using "Sequence" instead, which is covariant [builtins fixtures/list.pyi] diff --git a/test-data/unit/check-union-or-syntax.test b/test-data/unit/check-union-or-syntax.test index 6250374ccbea..924c12658851 100644 --- a/test-data/unit/check-union-or-syntax.test +++ b/test-data/unit/check-union-or-syntax.test @@ -109,7 +109,7 @@ b: X # E: Variable "__main__.X" is not valid as a type \ from __future__ import annotations from typing import List T = int | str # E: Invalid type alias: expression is not a valid type \ - # E: Unsupported left operand type for | ("Type[int]") + # E: Unsupported left operand type for | ("type[int]") class C(List[int | str]): # E: Type expected within [...] \ # E: Invalid base class "List" pass @@ -181,7 +181,7 @@ def f(x: int | str | C) -> None: def g(x: int | str | tuple[int, str] | C) -> None: if isinstance(x, int | str | tuple): - reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str, Tuple[builtins.int, builtins.str]]" + reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str, tuple[builtins.int, builtins.str]]" else: reveal_type(x) # N: Revealed type is "__main__.C" [builtins fixtures/isinstance_python3_10.pyi] diff --git a/test-data/unit/check-unions.test b/test-data/unit/check-unions.test index 8e92b6a91e8a..f8c894a7957b 100644 --- a/test-data/unit/check-unions.test +++ b/test-data/unit/check-unions.test @@ -347,7 +347,7 @@ C = NamedTuple('C', [('x', int)]) def foo(a: Union[A, B, C]): if isinstance(a, (B, C)): - reveal_type(a) # N: Revealed type is "Union[Tuple[builtins.int, fallback=__main__.B], Tuple[builtins.int, fallback=__main__.C]]" + reveal_type(a) # N: Revealed type is "Union[tuple[builtins.int, fallback=__main__.B], tuple[builtins.int, fallback=__main__.C]]" a.x a.y # E: Item "B" of "Union[B, C]" has no attribute "y" \ # E: Item "C" of "Union[B, C]" has no attribute "y" @@ -378,20 +378,20 @@ t_s: Type[str] t_a: Type[Any] # Two identical items -reveal_type(u(t_o, t_o)) # N: Revealed type is "Type[builtins.object]" -reveal_type(u(t_s, t_s)) # N: Revealed type is "Type[builtins.str]" -reveal_type(u(t_a, t_a)) # N: Revealed type is "Type[Any]" +reveal_type(u(t_o, t_o)) # N: Revealed type is "type[builtins.object]" +reveal_type(u(t_s, t_s)) # N: Revealed type is "type[builtins.str]" +reveal_type(u(t_a, t_a)) # N: Revealed type is "type[Any]" reveal_type(u(type, type)) # N: Revealed type is "def (x: builtins.object) -> builtins.type" # One type, other non-type -reveal_type(u(t_s, 1)) # N: Revealed type is "Union[builtins.int, Type[builtins.str]]" -reveal_type(u(1, t_s)) # N: Revealed type is "Union[Type[builtins.str], builtins.int]" +reveal_type(u(t_s, 1)) # N: Revealed type is "Union[builtins.int, type[builtins.str]]" +reveal_type(u(1, t_s)) # N: Revealed type is "Union[type[builtins.str], builtins.int]" reveal_type(u(type, 1)) # N: Revealed type is "Union[builtins.int, def (x: builtins.object) -> builtins.type]" reveal_type(u(1, type)) # N: Revealed type is "Union[def (x: builtins.object) -> builtins.type, builtins.int]" -reveal_type(u(t_a, 1)) # N: Revealed type is "Union[builtins.int, Type[Any]]" -reveal_type(u(1, t_a)) # N: Revealed type is "Union[Type[Any], builtins.int]" -reveal_type(u(t_o, 1)) # N: Revealed type is "Union[builtins.int, Type[builtins.object]]" -reveal_type(u(1, t_o)) # N: Revealed type is "Union[Type[builtins.object], builtins.int]" +reveal_type(u(t_a, 1)) # N: Revealed type is "Union[builtins.int, type[Any]]" +reveal_type(u(1, t_a)) # N: Revealed type is "Union[type[Any], builtins.int]" +reveal_type(u(t_o, 1)) # N: Revealed type is "Union[builtins.int, type[builtins.object]]" +reveal_type(u(1, t_o)) # N: Revealed type is "Union[type[builtins.object], builtins.int]" [case testSimplifyingUnionWithTypeTypes2] from typing import TypeVar, Union, Type, Any @@ -414,12 +414,12 @@ reveal_type(u(t_a, object())) # N: Revealed type is "builtins.object" reveal_type(u(object(), t_a)) # N: Revealed type is "builtins.object" # Union between type objects -reveal_type(u(t_o, t_a)) # N: Revealed type is "Union[Type[Any], Type[builtins.object]]" -reveal_type(u(t_a, t_o)) # N: Revealed type is "Union[Type[builtins.object], Type[Any]]" -reveal_type(u(t_s, t_o)) # N: Revealed type is "Type[builtins.object]" -reveal_type(u(t_o, t_s)) # N: Revealed type is "Type[builtins.object]" -reveal_type(u(t_o, type)) # N: Revealed type is "Type[builtins.object]" -reveal_type(u(type, t_o)) # N: Revealed type is "Type[builtins.object]" +reveal_type(u(t_o, t_a)) # N: Revealed type is "Union[type[Any], type[builtins.object]]" +reveal_type(u(t_a, t_o)) # N: Revealed type is "Union[type[builtins.object], type[Any]]" +reveal_type(u(t_s, t_o)) # N: Revealed type is "type[builtins.object]" +reveal_type(u(t_o, t_s)) # N: Revealed type is "type[builtins.object]" +reveal_type(u(t_o, type)) # N: Revealed type is "type[builtins.object]" +reveal_type(u(type, t_o)) # N: Revealed type is "type[builtins.object]" reveal_type(u(t_a, t)) # N: Revealed type is "builtins.type" reveal_type(u(t, t_a)) # N: Revealed type is "builtins.type" # The following should arguably not be simplified, but it's unclear how to fix then @@ -444,8 +444,8 @@ t_a: Type[A] reveal_type(u(M(*a), t_a)) # N: Revealed type is "__main__.M" reveal_type(u(t_a, M(*a))) # N: Revealed type is "__main__.M" -reveal_type(u(M2(*a), t_a)) # N: Revealed type is "Union[Type[__main__.A], __main__.M2]" -reveal_type(u(t_a, M2(*a))) # N: Revealed type is "Union[__main__.M2, Type[__main__.A]]" +reveal_type(u(M2(*a), t_a)) # N: Revealed type is "Union[type[__main__.A], __main__.M2]" +reveal_type(u(t_a, M2(*a))) # N: Revealed type is "Union[__main__.M2, type[__main__.A]]" [case testSimplifyUnionWithCallable] from typing import TypeVar, Union, Any, Callable @@ -772,7 +772,7 @@ good: Union[Tuple[int, int], Tuple[str, str]] x, y = t = good reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]" reveal_type(y) # N: Revealed type is "Union[builtins.int, builtins.str]" -reveal_type(t) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], Tuple[builtins.str, builtins.str]]" +reveal_type(t) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], tuple[builtins.str, builtins.str]]" [builtins fixtures/tuple.pyi] [out] @@ -783,7 +783,7 @@ good: Union[Tuple[int, int], Tuple[str, str]] t = x, y = good reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]" reveal_type(y) # N: Revealed type is "Union[builtins.int, builtins.str]" -reveal_type(t) # N: Revealed type is "Union[Tuple[builtins.int, builtins.int], Tuple[builtins.str, builtins.str]]" +reveal_type(t) # N: Revealed type is "Union[tuple[builtins.int, builtins.int], tuple[builtins.str, builtins.str]]" [builtins fixtures/tuple.pyi] [out] @@ -934,7 +934,7 @@ a: Any d: Dict[str, Tuple[List[Tuple[str, str]], str]] x, _ = d.get(a, (None, None)) -for y in x: pass # E: Item "None" of "Optional[List[Tuple[str, str]]]" has no attribute "__iter__" (not iterable) +for y in x: pass # E: Item "None" of "Optional[list[tuple[str, str]]]" has no attribute "__iter__" (not iterable) if x: for s, t in x: reveal_type(s) # N: Revealed type is "builtins.str" @@ -949,7 +949,7 @@ x = None d: Dict[str, Tuple[List[Tuple[str, str]], str]] x, _ = d.get(a, (None, None)) -for y in x: pass # E: Item "None" of "Optional[List[Tuple[str, str]]]" has no attribute "__iter__" (not iterable) +for y in x: pass # E: Item "None" of "Optional[list[tuple[str, str]]]" has no attribute "__iter__" (not iterable) if x: for s, t in x: reveal_type(s) # N: Revealed type is "builtins.str" @@ -963,7 +963,7 @@ x: object a: Any d: Dict[str, Tuple[List[Tuple[str, str]], str]] x, _ = d.get(a, (None, None)) -reveal_type(x) # N: Revealed type is "Union[builtins.list[Tuple[builtins.str, builtins.str]], None]" +reveal_type(x) # N: Revealed type is "Union[builtins.list[tuple[builtins.str, builtins.str]], None]" if x: for y in x: pass @@ -976,7 +976,7 @@ from typing import Dict, Tuple, List, Any a: Any d: Dict[str, Tuple[List[Tuple[str, str]], str]] x, _ = d.get(a, ([], "")) -reveal_type(x) # N: Revealed type is "builtins.list[Tuple[builtins.str, builtins.str]]" +reveal_type(x) # N: Revealed type is "builtins.list[tuple[builtins.str, builtins.str]]" for y in x: pass [builtins fixtures/dict.pyi] @@ -1048,7 +1048,7 @@ class Boop(Enum): def do_thing_with_enums(enums: Union[List[Enum], Enum]) -> None: ... boop: List[Boop] = [] -do_thing_with_enums(boop) # E: Argument 1 to "do_thing_with_enums" has incompatible type "List[Boop]"; expected "Union[List[Enum], Enum]" \ +do_thing_with_enums(boop) # E: Argument 1 to "do_thing_with_enums" has incompatible type "list[Boop]"; expected "Union[list[Enum], Enum]" \ # N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \ # N: Consider using "Sequence" instead, which is covariant [builtins fixtures/isinstancelist.pyi] @@ -1253,7 +1253,7 @@ class B: field_2: Mapped[str] = Mapped('2') mix: Union[Type[A], Type[B]] = A -reveal_type(mix) # N: Revealed type is "Union[Type[__main__.A], Type[__main__.B]]" +reveal_type(mix) # N: Revealed type is "Union[type[__main__.A], type[__main__.B]]" reveal_type(mix.field_1) # N: Revealed type is "builtins.list[builtins.int]" reveal_type(mix().field_1) # N: Revealed type is "builtins.int" [builtins fixtures/list.pyi] diff --git a/test-data/unit/check-varargs.test b/test-data/unit/check-varargs.test index 2e93c761b0be..680021a166f2 100644 --- a/test-data/unit/check-varargs.test +++ b/test-data/unit/check-varargs.test @@ -11,8 +11,8 @@ def f( *b: 'B') -> None: ab: Tuple[B, ...] ac: Tuple[C, ...] if int(): - b = ac # E: Incompatible types in assignment (expression has type "Tuple[C, ...]", variable has type "Tuple[B, ...]") - ac = b # E: Incompatible types in assignment (expression has type "Tuple[B, ...]", variable has type "Tuple[C, ...]") + b = ac # E: Incompatible types in assignment (expression has type "tuple[C, ...]", variable has type "tuple[B, ...]") + ac = b # E: Incompatible types in assignment (expression has type "tuple[B, ...]", variable has type "tuple[C, ...]") b = ab ab = b @@ -121,7 +121,7 @@ T4 = TypeVar('T4') def f(a: T1, b: T2, c: T3, d: T4) -> Tuple[T1, T2, T3, T4]: ... x: Tuple[int, str] y: Tuple[float, bool] -reveal_type(f(*x, *y)) # N: Revealed type is "Tuple[builtins.int, builtins.str, builtins.float, builtins.bool]" +reveal_type(f(*x, *y)) # N: Revealed type is "tuple[builtins.int, builtins.str, builtins.float, builtins.bool]" [builtins fixtures/list.pyi] [case testCallVarargsFunctionWithIterableAndPositional] @@ -141,7 +141,7 @@ it1 = (1, 2) it2 = ('',) f(*it1, 1, 2) f(*it1, 1, *it1, 2) -f(*it1, 1, *it2, 2) # E: Argument 3 to "f" has incompatible type "*Tuple[str]"; expected "int" +f(*it1, 1, *it2, 2) # E: Argument 3 to "f" has incompatible type "*tuple[str]"; expected "int" f(*it1, '') # E: Argument 2 to "f" has incompatible type "str"; expected "int" [builtins fixtures/for.pyi] @@ -243,7 +243,7 @@ ab: List[B] a: A b: B -f(*aa) # E: Argument 1 to "f" has incompatible type "*List[A]"; expected "B" +f(*aa) # E: Argument 1 to "f" has incompatible type "*list[A]"; expected "B" f(a, *ab) # Ok f(a, b) (cast(Any, f))(*aa) # IDEA: Move to check-dynamic? @@ -262,9 +262,9 @@ b: B c: C cc: CC -f(*(a, b, b)) # E: Argument 1 to "f" has incompatible type "*Tuple[A, B, B]"; expected "C" -f(*(b, b, c)) # E: Argument 1 to "f" has incompatible type "*Tuple[B, B, C]"; expected "A" -f(a, *(b, b)) # E: Argument 2 to "f" has incompatible type "*Tuple[B, B]"; expected "C" +f(*(a, b, b)) # E: Argument 1 to "f" has incompatible type "*tuple[A, B, B]"; expected "C" +f(*(b, b, c)) # E: Argument 1 to "f" has incompatible type "*tuple[B, B, C]"; expected "A" +f(a, *(b, b)) # E: Argument 2 to "f" has incompatible type "*tuple[B, B]"; expected "C" f(b, *(b, c)) # E: Argument 1 to "f" has incompatible type "B"; expected "A" f(*(a, b)) # E: Missing positional arguments "b", "c" in call to "f" f(*(a, b, c, c)) # E: Too many arguments for "f" @@ -308,13 +308,13 @@ aa: List[A] ab: List[B] a: A b: B -f(*aa) # E: Argument 1 to "f" has incompatible type "*List[A]"; expected "B" -f(a, *aa) # E: Argument 2 to "f" has incompatible type "*List[A]"; expected "B" +f(*aa) # E: Argument 1 to "f" has incompatible type "*list[A]"; expected "B" +f(a, *aa) # E: Argument 2 to "f" has incompatible type "*list[A]"; expected "B" f(b, *ab) # E: Argument 1 to "f" has incompatible type "B"; expected "A" f(a, a, *ab) # E: Argument 2 to "f" has incompatible type "A"; expected "B" -f(a, b, *aa) # E: Argument 3 to "f" has incompatible type "*List[A]"; expected "B" +f(a, b, *aa) # E: Argument 3 to "f" has incompatible type "*list[A]"; expected "B" f(b, b, *ab) # E: Argument 1 to "f" has incompatible type "B"; expected "A" -g(*ab) # E: Argument 1 to "g" has incompatible type "*List[B]"; expected "A" +g(*ab) # E: Argument 1 to "g" has incompatible type "*list[B]"; expected "A" f(a, *ab) f(a, b, *ab) f(a, b, b, *ab) @@ -334,14 +334,14 @@ b: B c: C cc: CC -f(*(b, b, b)) # E: Argument 1 to "f" has incompatible type "*Tuple[B, B, B]"; expected "A" -f(*(a, a, b)) # E: Argument 1 to "f" has incompatible type "*Tuple[A, A, B]"; expected "B" -f(*(a, b, a)) # E: Argument 1 to "f" has incompatible type "*Tuple[A, B, A]"; expected "B" -f(a, *(a, b)) # E: Argument 2 to "f" has incompatible type "*Tuple[A, B]"; expected "B" +f(*(b, b, b)) # E: Argument 1 to "f" has incompatible type "*tuple[B, B, B]"; expected "A" +f(*(a, a, b)) # E: Argument 1 to "f" has incompatible type "*tuple[A, A, B]"; expected "B" +f(*(a, b, a)) # E: Argument 1 to "f" has incompatible type "*tuple[A, B, A]"; expected "B" +f(a, *(a, b)) # E: Argument 2 to "f" has incompatible type "*tuple[A, B]"; expected "B" f(b, *(b, b)) # E: Argument 1 to "f" has incompatible type "B"; expected "A" f(b, b, *(b,)) # E: Argument 1 to "f" has incompatible type "B"; expected "A" f(a, a, *(b,)) # E: Argument 2 to "f" has incompatible type "A"; expected "B" -f(a, b, *(a,)) # E: Argument 3 to "f" has incompatible type "*Tuple[A]"; expected "B" +f(a, b, *(a,)) # E: Argument 3 to "f" has incompatible type "*tuple[A]"; expected "B" f(*()) # E: Too few arguments for "f" f(*(a, b, b)) f(a, *(b, b)) @@ -384,7 +384,7 @@ class B(A): pass aa: List[A] ab: List[B] -g(*aa) # E: Argument 1 to "g" has incompatible type "*List[A]"; expected "B" +g(*aa) # E: Argument 1 to "g" has incompatible type "*list[A]"; expected "B" f(*aa) f(*ab) g(*ab) @@ -401,10 +401,10 @@ class B: pass a, b = None, None # type: (A, B) f(*()) # E: Too few arguments for "f" -f(a, *[a]) # E: Argument 2 to "f" has incompatible type "*List[A]"; expected "Optional[B]" \ - # E: Argument 2 to "f" has incompatible type "*List[A]"; expected "B" -f(a, b, *[a]) # E: Argument 3 to "f" has incompatible type "*List[A]"; expected "B" -f(*(a, a, b)) # E: Argument 1 to "f" has incompatible type "*Tuple[A, A, B]"; expected "Optional[B]" +f(a, *[a]) # E: Argument 2 to "f" has incompatible type "*list[A]"; expected "Optional[B]" \ + # E: Argument 2 to "f" has incompatible type "*list[A]"; expected "B" +f(a, b, *[a]) # E: Argument 3 to "f" has incompatible type "*list[A]"; expected "B" +f(*(a, a, b)) # E: Argument 1 to "f" has incompatible type "*tuple[A, A, B]"; expected "Optional[B]" f(*(a,)) f(*(a, b)) f(*(a, b, b, b)) @@ -420,7 +420,7 @@ f(x=1, *[2]) [builtins fixtures/list.pyi] [out] main:3: error: "f" gets multiple values for keyword argument "x" -main:3: error: Argument 1 to "f" has incompatible type "*List[int]"; expected "str" +main:3: error: Argument 1 to "f" has incompatible type "*list[int]"; expected "str" [case testVarArgsAfterKeywordArgInCall2] # see: mypy issue #2729 @@ -429,7 +429,7 @@ f(y='x', *[1]) [builtins fixtures/list.pyi] [out] main:3: error: "f" gets multiple values for keyword argument "y" -main:3: error: Argument 1 to "f" has incompatible type "*List[int]"; expected "str" +main:3: error: Argument 1 to "f" has incompatible type "*list[int]"; expected "str" [case testVarArgsAfterKeywordArgInCall3] def f(x: int, y: str) -> None: pass @@ -543,15 +543,15 @@ b: B aa: List[A] if int(): - a, b = f(*aa) # E: Argument 1 to "f" has incompatible type "*List[A]"; expected "B" + a, b = f(*aa) # E: Argument 1 to "f" has incompatible type "*list[A]"; expected "B" if int(): - b, b = f(*aa) # E: Argument 1 to "f" has incompatible type "*List[A]"; expected "B" + b, b = f(*aa) # E: Argument 1 to "f" has incompatible type "*list[A]"; expected "B" if int(): a, a = f(b, *aa) # E: Argument 1 to "f" has incompatible type "B"; expected "A" if int(): - b, b = f(b, *aa) # E: Argument 2 to "f" has incompatible type "*List[A]"; expected "B" + b, b = f(b, *aa) # E: Argument 2 to "f" has incompatible type "*list[A]"; expected "B" if int(): - b, b = f(b, b, *aa) # E: Argument 3 to "f" has incompatible type "*List[A]"; expected "B" + b, b = f(b, b, *aa) # E: Argument 3 to "f" has incompatible type "*list[A]"; expected "B" if int(): a, b = f(a, *a) # E: Expected iterable as variadic argument if int(): @@ -579,11 +579,11 @@ a: A b: B if int(): - a, a = f(*(a, b)) # E: Argument 1 to "f" has incompatible type "*Tuple[A, B]"; expected "A" + a, a = f(*(a, b)) # E: Argument 1 to "f" has incompatible type "*tuple[A, B]"; expected "A" if int(): b, b = f(a, *(b,)) # E: Argument 1 to "f" has incompatible type "A"; expected "B" if int(): - a, a = f(*(a, b)) # E: Argument 1 to "f" has incompatible type "*Tuple[A, B]"; expected "A" + a, a = f(*(a, b)) # E: Argument 1 to "f" has incompatible type "*tuple[A, B]"; expected "A" if int(): b, b = f(a, *(b,)) # E: Argument 1 to "f" has incompatible type "A"; expected "B" if int(): @@ -612,11 +612,11 @@ class A: pass class B: pass if int(): - a, aa = G().f(*[a]) # E: Incompatible types in assignment (expression has type "List[A]", variable has type "A") + a, aa = G().f(*[a]) # E: Incompatible types in assignment (expression has type "list[A]", variable has type "A") if int(): - aa, a = G().f(*[a]) # E: Incompatible types in assignment (expression has type "List[Never]", variable has type "A") + aa, a = G().f(*[a]) # E: Incompatible types in assignment (expression has type "list[Never]", variable has type "A") if int(): - ab, aa = G().f(*[a]) # E: Argument 1 to "f" of "G" has incompatible type "*List[A]"; expected "B" + ab, aa = G().f(*[a]) # E: Argument 1 to "f" of "G" has incompatible type "*list[A]"; expected "B" if int(): ao, ao = G().f(*[a]) if int(): @@ -686,15 +686,15 @@ a = {'a': [1, 2]} b = {'b': ['c', 'd']} c = {'c': 1.0} d = {'d': 1} -f(a) # E: Argument 1 to "f" has incompatible type "Dict[str, List[int]]"; expected "Dict[str, Sequence[int]]" \ +f(a) # E: Argument 1 to "f" has incompatible type "dict[str, list[int]]"; expected "dict[str, Sequence[int]]" \ # N: "dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \ # N: Consider using "Mapping" instead, which is covariant in the value type -f(b) # E: Argument 1 to "f" has incompatible type "Dict[str, List[str]]"; expected "Dict[str, Sequence[int]]" +f(b) # E: Argument 1 to "f" has incompatible type "dict[str, list[str]]"; expected "dict[str, Sequence[int]]" g(c) -g(d) # E: Argument 1 to "g" has incompatible type "Dict[str, int]"; expected "Dict[str, float]" \ +g(d) # E: Argument 1 to "g" has incompatible type "dict[str, int]"; expected "dict[str, float]" \ # N: "dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \ # N: Consider using "Mapping" instead, which is covariant in the value type -h(c) # E: Argument 1 to "h" has incompatible type "Dict[str, float]"; expected "Dict[str, int]" +h(c) # E: Argument 1 to "h" has incompatible type "dict[str, float]"; expected "dict[str, int]" h(d) [builtins fixtures/dict.pyi] [typing fixtures/typing-medium.pyi] @@ -703,13 +703,13 @@ h(d) from typing import List, Union def f(numbers: List[Union[int, float]]) -> None: pass a = [1, 2] -f(a) # E: Argument 1 to "f" has incompatible type "List[int]"; expected "List[Union[int, float]]" \ +f(a) # E: Argument 1 to "f" has incompatible type "list[int]"; expected "list[Union[int, float]]" \ # N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \ # N: Consider using "Sequence" instead, which is covariant x = [1] y = ['a'] if int(): - x = y # E: Incompatible types in assignment (expression has type "List[str]", variable has type "List[int]") + x = y # E: Incompatible types in assignment (expression has type "list[str]", variable has type "list[int]") [builtins fixtures/list.pyi] [case testInvariantTypeConfusingNames] @@ -720,8 +720,8 @@ def f(x: Listener) -> None: pass def g(y: DictReader) -> None: pass a = [1, 2] b = {'b': 1} -f(a) # E: Argument 1 to "f" has incompatible type "List[int]"; expected "Listener" -g(b) # E: Argument 1 to "g" has incompatible type "Dict[str, int]"; expected "DictReader" +f(a) # E: Argument 1 to "f" has incompatible type "list[int]"; expected "Listener" +g(b) # E: Argument 1 to "g" has incompatible type "dict[str, int]"; expected "DictReader" [builtins fixtures/dict.pyi] [case testInvariantTypeConfusingNames2] @@ -822,7 +822,7 @@ Weird = TypedDict("Weird", {"@": int}) def foo(**kwargs: Unpack[Weird]) -> None: reveal_type(kwargs["@"]) # N: Revealed type is "builtins.int" foo(**{"@": 42}) -foo(**{"no": "way"}) # E: Argument 1 to "foo" has incompatible type "**Dict[str, str]"; expected "int" +foo(**{"no": "way"}) # E: Argument 1 to "foo" has incompatible type "**dict[str, str]"; expected "int" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] diff --git a/test-data/unit/check-warnings.test b/test-data/unit/check-warnings.test index 895b16e5e3c3..a2d201fa301d 100644 --- a/test-data/unit/check-warnings.test +++ b/test-data/unit/check-warnings.test @@ -207,7 +207,7 @@ def g() -> Any: pass def f() -> typ: return g() [builtins fixtures/tuple.pyi] [out] -main:11: error: Returning Any from function declared to return "Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int]" +main:11: error: Returning Any from function declared to return "tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int]" [case testReturnAnySilencedFromTypedFunction] # flags: --warn-return-any diff --git a/test-data/unit/cmdline.test b/test-data/unit/cmdline.test index 012e1e6b7fe6..c65f55620d67 100644 --- a/test-data/unit/cmdline.test +++ b/test-data/unit/cmdline.test @@ -478,7 +478,7 @@ disallow_any_generics = True [file m.py] def j(s: frozenset) -> None: pass [out] -m.py:1: error: Missing type parameters for generic type "FrozenSet" +m.py:1: error: Missing type parameters for generic type "frozenset" [case testDisallowAnyGenericsTypingCollections] # cmd: mypy m.py @@ -525,7 +525,7 @@ strict_optional = True ignore_errors = False [out] a/b/c/d/e/__init__.py:2: error: Missing type parameters for generic type "List" -a/b/c/d/e/__init__.py:3: error: Argument 1 to "g" has incompatible type "None"; expected "List[Any]" +a/b/c/d/e/__init__.py:3: error: Argument 1 to "g" has incompatible type "None"; expected "list[Any]" [case testMissingFile] # cmd: mypy nope.py @@ -650,7 +650,7 @@ def foo() -> str: return 9 [out] s4.py:2: error: Incompatible return value type (got "int", expected "str") -s3.py:2: error: Incompatible return value type (got "List[int]", expected "int") +s3.py:2: error: Incompatible return value type (got "list[int]", expected "int") s1.py:2: error: Incompatible return value type (got "int", expected "str") [case testShadowFileWithPretty] @@ -830,7 +830,7 @@ x = [] # type: List[float] y = [] # type: List[int] x = y [out] -bad.py:4: error: Incompatible types in assignment (expression has type "List[int]", variable has type "List[float]") +bad.py:4: error: Incompatible types in assignment (expression has type "list[int]", variable has type "list[float]") bad.py:4: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance bad.py:4: note: Consider using "Sequence" instead, which is covariant Found 1 error in 1 file (checked 1 source file) diff --git a/test-data/unit/fine-grained-inspect.test b/test-data/unit/fine-grained-inspect.test index 0e05769370a2..5caa1a94387b 100644 --- a/test-data/unit/fine-grained-inspect.test +++ b/test-data/unit/fine-grained-inspect.test @@ -23,7 +23,7 @@ NameExpr -> "C[T]" MemberExpr -> "T" NameExpr -> "C[T]" MemberExpr -> "T" -12:5:12:5 -> "Type[foo.C[builtins.int]]" +12:5:12:5 -> "type[foo.C[builtins.int]]" 12:5:12:9 -> "foo.C[builtins.int]" 12:1:12:10 -> "builtins.int" CallExpr:12:5:12:9 -> "C[int]" diff --git a/test-data/unit/fine-grained-python312.test b/test-data/unit/fine-grained-python312.test index 2cb2148a66fe..b85b5bd3e320 100644 --- a/test-data/unit/fine-grained-python312.test +++ b/test-data/unit/fine-grained-python312.test @@ -74,8 +74,8 @@ from builtins import tuple as B [typing fixtures/typing-full.pyi] [out] == -main:3: error: Incompatible types in assignment (expression has type "int", variable has type "Tuple[int, str]") -main:4: error: Incompatible types in assignment (expression has type "str", variable has type "Tuple[int, str]") +main:3: error: Incompatible types in assignment (expression has type "int", variable has type "tuple[int, str]") +main:4: error: Incompatible types in assignment (expression has type "str", variable has type "tuple[int, str]") [case testPEP695NestedGenericClassMethodUpdated] from a import f diff --git a/test-data/unit/fine-grained.test b/test-data/unit/fine-grained.test index b1ab9e235117..670ab42e1983 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 "Callable[[], A]" [case testConstructorSignatureChanged3] from a import C @@ -2674,9 +2674,9 @@ def g() -> None: pass def g() -> int: pass [builtins fixtures/dict.pyi] [out] -main:7: error: Need type annotation for "x" (hint: "x: Dict[, ] = ...") +main:7: error: Need type annotation for "x" (hint: "x: dict[, ] = ...") == -main:7: error: Need type annotation for "x" (hint: "x: Dict[, ] = ...") +main:7: error: Need type annotation for "x" (hint: "x: dict[, ] = ...") [case testRefreshPartialTypeInClass] import a @@ -2692,9 +2692,9 @@ def g() -> None: pass def g() -> int: pass [builtins fixtures/dict.pyi] [out] -main:5: error: Need type annotation for "x" (hint: "x: Dict[, ] = ...") +main:5: error: Need type annotation for "x" (hint: "x: dict[, ] = ...") == -main:5: error: Need type annotation for "x" (hint: "x: Dict[, ] = ...") +main:5: error: Need type annotation for "x" (hint: "x: dict[, ] = ...") [case testRefreshPartialTypeInferredAttributeIndex] from c import C @@ -2833,7 +2833,7 @@ class M(type): == a.py:4: error: Incompatible types in assignment (expression has type "int", variable has type "str") == -a.py:4: error: "Type[C]" has no attribute "x" +a.py:4: error: "type[C]" has no attribute "x" == [case testMetaclassAttributesDirect] @@ -2862,7 +2862,7 @@ class M(type): == a.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "str") == -a.py:3: error: "Type[C]" has no attribute "x" +a.py:3: error: "type[C]" has no attribute "x" == [case testMetaclassOperators] @@ -2886,7 +2886,7 @@ class M(type): pass [out] == -a.py:4: error: Unsupported operand types for + ("Type[C]" and "Type[C]") +a.py:4: error: Unsupported operand types for + ("type[C]" and "type[C]") [case testMetaclassOperatorsDirect] import a @@ -2907,7 +2907,7 @@ class M(type): def __add__(self, other: M) -> M: pass [out] -a.py:3: error: Unsupported operand types for + ("Type[C]" and "Type[C]") +a.py:3: error: Unsupported operand types for + ("type[C]" and "type[C]") == [case testFineMetaclassUpdate] @@ -2931,7 +2931,7 @@ class B(metaclass=c.M): pass class M(type): pass [out] -a.py:6: error: Argument 1 to "f" has incompatible type "Type[B]"; expected "M" +a.py:6: error: Argument 1 to "f" has incompatible type "type[B]"; expected "M" == [case testFineMetaclassRecalculation] @@ -2990,7 +2990,7 @@ class M(type): x: int [out] == -a.py:3: error: "Type[B]" has no attribute "x" +a.py:3: error: "type[B]" has no attribute "x" [case testFineMetaclassRemoveFromClass2] import a @@ -3015,7 +3015,7 @@ class M(type): x: int [out] == -a.py:3: error: Argument 1 to "test" has incompatible type "Type[B]"; expected "M" +a.py:3: error: Argument 1 to "test" has incompatible type "type[B]"; expected "M" [case testBadMetaclassCorrected] import a @@ -3052,7 +3052,7 @@ class C(metaclass=c.M): class M(type): x: int [out] -a.py:3: error: "Type[C]" has no attribute "x" +a.py:3: error: "type[C]" has no attribute "x" == [case testIndirectSubclassReferenceMetaclass] @@ -3088,7 +3088,7 @@ class M(type): == a.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "str") == -b.py:2: error: "Type[D]" has no attribute "x" +b.py:2: error: "type[D]" has no attribute "x" == [case testMetaclassDeletion] @@ -3407,8 +3407,8 @@ lol(b.x) [builtins fixtures/tuple.pyi] [out] == -c.py:7: error: Argument 1 to "lol" has incompatible type "M"; expected "Tuple[Tuple[int]]" -c.py:9: error: Argument 1 to "lol" has incompatible type "M"; expected "Tuple[Tuple[int]]" +c.py:7: error: Argument 1 to "lol" has incompatible type "M"; expected "tuple[tuple[int]]" +c.py:9: error: Argument 1 to "lol" has incompatible type "M"; expected "tuple[tuple[int]]" [case testNamedTupleUpdate4] import b @@ -3522,9 +3522,9 @@ reveal_type(a.n) [out] == == -c.py:4: note: Revealed type is "Tuple[Union[Tuple[Union[..., None], builtins.int, fallback=b.M], None], builtins.int, fallback=a.N]" +c.py:4: note: Revealed type is "tuple[Union[tuple[Union[..., None], builtins.int, fallback=b.M], None], builtins.int, fallback=a.N]" c.py:5: error: Incompatible types in assignment (expression has type "Optional[N]", variable has type "int") -c.py:7: note: Revealed type is "Tuple[Union[Tuple[Union[..., None], builtins.int, fallback=b.M], None], builtins.int, fallback=a.N]" +c.py:7: note: Revealed type is "tuple[Union[tuple[Union[..., None], builtins.int, fallback=b.M], None], builtins.int, fallback=a.N]" [case testTupleTypeUpdateNonRecursiveToRecursiveFine] import c @@ -3555,7 +3555,7 @@ def f(x: a.N) -> None: [out] == == -c.py:4: note: Revealed type is "Tuple[Union[Tuple[Union[..., None], builtins.int, fallback=b.M], None], builtins.int, fallback=a.N]" +c.py:4: note: Revealed type is "tuple[Union[tuple[Union[..., None], builtins.int, fallback=b.M], None], builtins.int, fallback=a.N]" c.py:5: error: Incompatible types in assignment (expression has type "Optional[N]", variable has type "int") [case testTypeAliasUpdateNonRecursiveToRecursiveFine] @@ -3587,7 +3587,7 @@ def f(x: a.N) -> None: [out] == == -c.py:4: note: Revealed type is "Tuple[Union[Tuple[Union[..., None], builtins.int], None], builtins.int]" +c.py:4: note: Revealed type is "tuple[Union[tuple[Union[..., None], builtins.int], None], builtins.int]" c.py:5: error: Incompatible types in assignment (expression has type "Optional[N]", variable has type "int") [case testTypedDictRefresh] @@ -5422,7 +5422,7 @@ class C(Enum): [typing fixtures/typing-medium.pyi] [out] == -a.py:5: error: "Type[C]" has no attribute "Y" +a.py:5: error: "type[C]" has no attribute "Y" [case testClassBasedEnumPropagation2] import a @@ -5522,7 +5522,7 @@ C = Enum('C', 'X') [typing fixtures/typing-medium.pyi] [out] == -a.py:5: error: "Type[C]" has no attribute "Y" +a.py:5: error: "type[C]" has no attribute "Y" [case testFuncBasedEnumPropagation2] import a @@ -6167,7 +6167,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 "Callable[[int], Any]" [case testDunderNewDefine] import a @@ -6781,7 +6781,7 @@ class M(type): x: int [out] == -a.py:4: error: Argument 1 to "func" has incompatible type "Type[B]"; expected "P" +a.py:4: error: Argument 1 to "func" has incompatible type "type[B]"; expected "P" [case testProtocolVsProtocolSubUpdated] import a @@ -7509,7 +7509,7 @@ def g() -> Tuple[str, str]: pass [builtins fixtures/tuple.pyi] [out] == -main:5: error: Incompatible return value type (got "List[str]", expected "List[int]") +main:5: error: Incompatible return value type (got "list[str]", expected "list[int]") [case testUnpackInExpression1-only_when_nocache] from typing import Tuple, List @@ -7532,8 +7532,8 @@ def t() -> Tuple[str]: ... [builtins fixtures/list.pyi] [out] == -main:5: error: Incompatible return value type (got "Tuple[int, str]", expected "Tuple[int, int]") -main:8: error: List item 1 has incompatible type "Tuple[str]"; expected "int" +main:5: error: Incompatible return value type (got "tuple[int, str]", expected "tuple[int, int]") +main:8: error: List item 1 has incompatible type "tuple[str]"; expected "int" [case testUnpackInExpression2-only_when_nocache] from typing import Set @@ -7553,7 +7553,7 @@ def t() -> Tuple[str]: pass [builtins fixtures/set.pyi] [out] == -main:5: error: Argument 2 to has incompatible type "*Tuple[str]"; expected "int" +main:5: error: Argument 2 to has incompatible type "*tuple[str]"; expected "int" [case testUnpackInExpression3-only_when_nocache] from typing import Dict @@ -7573,7 +7573,7 @@ def d() -> Dict[int, int]: pass [builtins fixtures/dict.pyi] [out] == -main:5: error: Unpacked dict entry 1 has incompatible type "Dict[int, int]"; expected "SupportsKeysAndGetItem[int, str]" +main:5: error: Unpacked dict entry 1 has incompatible type "dict[int, int]"; expected "SupportsKeysAndGetItem[int, str]" [case testAwaitAndAsyncDef-only_when_nocache] from a import g @@ -7814,7 +7814,7 @@ class B: [builtins fixtures/list.pyi] [out] == -main:6: error: Incompatible types in assignment (expression has type "List[str]", base class "B" defined the type as "List[int]") +main:6: error: Incompatible types in assignment (expression has type "list[str]", base class "B" defined the type as "list[int]") [case testLiskovFineVariableCleanDefInMethodNested-only_when_nocache] from b import B @@ -8060,7 +8060,7 @@ A = NamedTuple('A', F) # type: ignore [builtins fixtures/list.pyi] [out] == -b.py:3: note: Revealed type is "Tuple[(), fallback=a.A]" +b.py:3: note: Revealed type is "tuple[(), fallback=a.A]" [case testImportOnTopOfAlias1] from a import A @@ -8100,7 +8100,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 "Callable[[str], str]", local name has type "type[list[Any]]") [case testFakeOverloadCrash] import b @@ -9937,7 +9937,7 @@ x = 0 # Arbitrary change to trigger reprocessing [builtins fixtures/dict.pyi] [out] == -a.py:3: note: Revealed type is "Tuple[Literal[1]?, Literal['x']?]" +a.py:3: note: Revealed type is "tuple[Literal[1]?, Literal['x']?]" [case testVariadicClassFineUpdateRegularToVariadic] from typing import Any diff --git a/test-data/unit/merge.test b/test-data/unit/merge.test index 8c806623403b..7463571b76b4 100644 --- a/test-data/unit/merge.test +++ b/test-data/unit/merge.test @@ -671,12 +671,12 @@ TypeInfo<2>( _NT<6> __annotations__<7> (builtins.dict[builtins.str<8>, Any]<9>) __doc__<10> (builtins.str<8>) - __match_args__<11> (Tuple[Literal['x']]) + __match_args__<11> (tuple[Literal['x']]) __new__<12> _asdict<13> _field_defaults<14> (builtins.dict[builtins.str<8>, Any]<9>) _field_types<15> (builtins.dict[builtins.str<8>, Any]<9>) - _fields<16> (Tuple[builtins.str<8>]) + _fields<16> (tuple[builtins.str<8>]) _make<17> _replace<18> _source<19> (builtins.str<8>) @@ -695,12 +695,12 @@ TypeInfo<2>( _NT<6> __annotations__<7> (builtins.dict[builtins.str<8>, Any]<9>) __doc__<10> (builtins.str<8>) - __match_args__<11> (Tuple[Literal['x'], Literal['y']]) + __match_args__<11> (tuple[Literal['x'], Literal['y']]) __new__<12> _asdict<13> _field_defaults<14> (builtins.dict[builtins.str<8>, Any]<9>) _field_types<15> (builtins.dict[builtins.str<8>, Any]<9>) - _fields<16> (Tuple[builtins.str<8>, builtins.str<8>]) + _fields<16> (tuple[builtins.str<8>, builtins.str<8>]) _make<17> _replace<18> _source<19> (builtins.str<8>) @@ -736,7 +736,7 @@ TypeInfo<2>( _asdict<12> _field_defaults<13> (builtins.dict[builtins.str<8>, Any]<9>) _field_types<14> (builtins.dict[builtins.str<8>, Any]<9>) - _fields<15> (Tuple[builtins.str<8>]) + _fields<15> (tuple[builtins.str<8>]) _make<16> _replace<17> _source<18> (builtins.str<8>) @@ -759,7 +759,7 @@ TypeInfo<2>( _asdict<12> _field_defaults<13> (builtins.dict[builtins.str<8>, Any]<9>) _field_types<14> (builtins.dict[builtins.str<8>, Any]<9>) - _fields<15> (Tuple[builtins.str<8>, builtins.str<8>]) + _fields<15> (tuple[builtins.str<8>, builtins.str<8>]) _make<16> _replace<17> _source<18> (builtins.str<8>) @@ -795,10 +795,10 @@ class A: pass a: Type[A] [out] ## target -NameExpr:3: Type[target.A<0>] +NameExpr:3: type[target.A<0>] ==> ## target -NameExpr:3: Type[target.A<0>] +NameExpr:3: type[target.A<0>] [case testTypeVar_types] import target diff --git a/test-data/unit/parse.test b/test-data/unit/parse.test index 82065c95faf8..b1c0918365a6 100644 --- a/test-data/unit/parse.test +++ b/test-data/unit/parse.test @@ -548,7 +548,7 @@ MypyFile:1( NameExpr(x) NameExpr(y)) NameExpr(z) - Tuple[int?, a?[c?]])) + tuple[int?, a?[c?]])) [case testMultipleVarDef2] (xx, z, i) = 1 # type: (a[c], Any, int) @@ -560,7 +560,7 @@ MypyFile:1( NameExpr(z) NameExpr(i)) IntExpr(1) - Tuple[a?[c?], Any?, int?])) + tuple[a?[c?], Any?, int?])) [case testMultipleVarDef3] (xx, (z, i)) = 1 # type: (a[c], (Any, int)) @@ -573,7 +573,7 @@ MypyFile:1( NameExpr(z) NameExpr(i))) IntExpr(1) - Tuple[a?[c?], Tuple[Any?, int?]])) + tuple[a?[c?], tuple[Any?, int?]])) [case testAnnotateAssignmentViaSelf] class A: @@ -617,7 +617,7 @@ MypyFile:1( TupleExpr:2( IntExpr(1) IntExpr(2)) - Tuple[foo?, bar?])) + tuple[foo?, bar?])) [case testWhitespaceAndCommentAnnotation] x = 1#type:int diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index 8c442a23d80a..081d21f14857 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -626,8 +626,8 @@ a + 1 [out] _testMapStr.py:4: error: No overload variant of "__add__" of "list" matches argument type "int" _testMapStr.py:4: note: Possible overload variants: -_testMapStr.py:4: note: def __add__(self, List[str], /) -> List[str] -_testMapStr.py:4: note: def [_S] __add__(self, List[_S], /) -> List[Union[_S, str]] +_testMapStr.py:4: note: def __add__(self, list[str], /) -> list[str] +_testMapStr.py:4: note: def [_S] __add__(self, list[_S], /) -> list[Union[_S, str]] [case testRelativeImport] import typing @@ -762,7 +762,7 @@ def p(t: Tuple[str, ...]) -> None: ''.startswith(('x', b'y')) [out] _program.py:6: error: "str" not callable -_program.py:8: error: Argument 1 to "startswith" of "str" has incompatible type "Tuple[str, bytes]"; expected "Union[str, Tuple[str, ...]]" +_program.py:8: error: Argument 1 to "startswith" of "str" has incompatible type "tuple[str, bytes]"; expected "Union[str, tuple[str, ...]]" [case testMultiplyTupleByInteger] n = 4 @@ -771,8 +771,8 @@ t + 1 [out] _program.py:3: error: No overload variant of "__add__" of "tuple" matches argument type "int" _program.py:3: note: Possible overload variants: -_program.py:3: note: def __add__(self, Tuple[str, ...], /) -> Tuple[str, ...] -_program.py:3: note: def [_T] __add__(self, Tuple[_T, ...], /) -> Tuple[Union[str, _T], ...] +_program.py:3: note: def __add__(self, tuple[str, ...], /) -> tuple[str, ...] +_program.py:3: note: def [_T] __add__(self, tuple[_T, ...], /) -> tuple[Union[str, _T], ...] [case testMultiplyTupleByIntegerReverse] n = 4 @@ -781,8 +781,8 @@ t + 1 [out] _program.py:3: error: No overload variant of "__add__" of "tuple" matches argument type "int" _program.py:3: note: Possible overload variants: -_program.py:3: note: def __add__(self, Tuple[str, ...], /) -> Tuple[str, ...] -_program.py:3: note: def [_T] __add__(self, Tuple[_T, ...], /) -> Tuple[Union[str, _T], ...] +_program.py:3: note: def __add__(self, tuple[str, ...], /) -> tuple[str, ...] +_program.py:3: note: def [_T] __add__(self, tuple[_T, ...], /) -> tuple[Union[str, _T], ...] [case testDictWithKeywordArgs] from typing import Dict, Any, List @@ -794,7 +794,7 @@ d4 = dict(a=1, b='') # type: Dict[str, Any] result = dict(x=[], y=[]) # type: Dict[str, List[str]] [out] _program.py:3: error: Dict entry 1 has incompatible type "str": "str"; expected "str": "int" -_program.py:5: error: "Dict[str, int]" has no attribute "xyz" +_program.py:5: error: "dict[str, int]" has no attribute "xyz" [case testDefaultDict] # flags: --new-type-inference @@ -823,11 +823,11 @@ 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[_T]]"; expected "Optional[Callable[[], str]]" +_program.py:7: error: Argument 1 to "defaultdict" has incompatible type "type[list[_T]]"; expected "Optional[Callable[[], 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]]" -_program.py:24: error: Invalid index type "str" for "MyDDict[Dict[Never, Never]]"; expected type "int" +_program.py:20: error: Argument 1 to "tst" has incompatible type "defaultdict[str, list[Never]]"; expected "defaultdict[int, list[Never]]" +_program.py:24: error: Invalid index type "str" for "MyDDict[dict[Never, Never]]"; expected type "int" [case testCollectionsAliases] import typing as t @@ -1005,7 +1005,7 @@ a[0] = 'x', 1 a[1] = 2, 'y' a[:] = [('z', 3)] [out] -_program.py:4: error: Incompatible types in assignment (expression has type "Tuple[int, str]", target has type "Tuple[str, int]") +_program.py:4: error: Incompatible types in assignment (expression has type "tuple[int, str]", target has type "tuple[str, int]") [case testContextManager] import contextlib @@ -1194,8 +1194,8 @@ other = 4 + get_c_type() + 5 reveal_type(res) reveal_type(other) [out] -_testMetaclassOpAccess.py:21: note: Revealed type is "Type[_testMetaclassOpAccess.A]" -_testMetaclassOpAccess.py:22: note: Revealed type is "Type[_testMetaclassOpAccess.C]" +_testMetaclassOpAccess.py:21: note: Revealed type is "type[_testMetaclassOpAccess.A]" +_testMetaclassOpAccess.py:22: note: Revealed type is "type[_testMetaclassOpAccess.C]" [case testMetaclassOpAccessUnion] from typing import Type, Union @@ -1285,8 +1285,8 @@ class C: __slots__: List[int] = [] [out] _testInvalidSlots.py:3: error: Invalid type for "__slots__" (actual type "int", expected type "Union[str, Iterable[str]]") -_testInvalidSlots.py:5: error: Invalid type for "__slots__" (actual type "Tuple[int, int]", expected type "Union[str, Iterable[str]]") -_testInvalidSlots.py:7: error: Invalid type for "__slots__" (actual type "List[int]", expected type "Union[str, Iterable[str]]") +_testInvalidSlots.py:5: error: Invalid type for "__slots__" (actual type "tuple[int, int]", expected type "Union[str, Iterable[str]]") +_testInvalidSlots.py:7: error: Invalid type for "__slots__" (actual type "list[int]", expected type "Union[str, Iterable[str]]") [case testDictWithStarStarSpecialCase] from typing import Dict @@ -1297,7 +1297,7 @@ def f() -> Dict[int, str]: def d() -> Dict[int, int]: return {} [out] -_testDictWithStarStarSpecialCase.py:4: error: Unpacked dict entry 1 has incompatible type "Dict[int, int]"; expected "SupportsKeysAndGetItem[int, str]" +_testDictWithStarStarSpecialCase.py:4: error: Unpacked dict entry 1 has incompatible type "dict[int, int]"; expected "SupportsKeysAndGetItem[int, str]" [case testLoadsOfOverloads] from typing import overload, Any, TypeVar, Iterable, List, Dict, Callable, Union @@ -1357,7 +1357,7 @@ X = namedtuple('X', ['a', 'b']) x = X(a=1, b='s') [out] -_testNamedTupleNew.py:12: note: Revealed type is "Tuple[builtins.int, fallback=_testNamedTupleNew.Child]" +_testNamedTupleNew.py:12: note: Revealed type is "tuple[builtins.int, fallback=_testNamedTupleNew.Child]" [case testNamedTupleTypeInheritanceSpecialCase] from typing import NamedTuple, Tuple @@ -1383,7 +1383,7 @@ _testNamedTupleTypeInheritanceSpecialCase.py:8: note: Revealed type is "builtins _testNamedTupleTypeInheritanceSpecialCase.py:9: note: Revealed type is "builtins.tuple[builtins.str, ...]" _testNamedTupleTypeInheritanceSpecialCase.py:10: note: Revealed type is "builtins.dict[builtins.str, Any]" _testNamedTupleTypeInheritanceSpecialCase.py:17: error: Argument 1 to "accepts_named_tuple" has incompatible type "int"; expected "NamedTuple" -_testNamedTupleTypeInheritanceSpecialCase.py:18: error: Argument 1 to "accepts_named_tuple" has incompatible type "Tuple[int, int]"; expected "NamedTuple" +_testNamedTupleTypeInheritanceSpecialCase.py:18: error: Argument 1 to "accepts_named_tuple" has incompatible type "tuple[int, int]"; expected "NamedTuple" [case testNewAnalyzerBasicTypeshed_newsemanal] from typing import Dict, List, Tuple @@ -1424,8 +1424,8 @@ frozenset({1}) == [1] # Error {1: 2}.values() == {2} # Error {1: 2}.keys() == [1] # OK [out] -_testStrictEqualityAllowlist.py:5: error: Non-overlapping equality check (left operand type: "FrozenSet[int]", right operand type: "List[int]") -_testStrictEqualityAllowlist.py:12: error: Non-overlapping equality check (left operand type: "dict_values[int, int]", right operand type: "Set[int]") +_testStrictEqualityAllowlist.py:5: error: Non-overlapping equality check (left operand type: "frozenset[int]", right operand type: "list[int]") +_testStrictEqualityAllowlist.py:12: error: Non-overlapping equality check (left operand type: "dict_values[int, int]", right operand type: "set[int]") [case testUnreachableWithStdlibContextManagers] # mypy: warn-unreachable, strict-optional @@ -1551,7 +1551,7 @@ if isinstance(obj, Hashable): if isinstance(obj, Awaitable): reveal_type(obj) [out] -_testSpecialTypingProtocols.py:6: note: Revealed type is "Tuple[builtins.int]" +_testSpecialTypingProtocols.py:6: note: Revealed type is "tuple[builtins.int]" _testSpecialTypingProtocols.py:8: error: Statement is unreachable [case testTypeshedRecursiveTypesExample] @@ -1632,8 +1632,8 @@ def foo(x: T) -> T: return x [out] _testTypeAliasWithNewStyleUnion.py:5: note: Revealed type is "typing._SpecialForm" -_testTypeAliasWithNewStyleUnion.py:25: note: Revealed type is "Union[Type[builtins.int], builtins.str]" -_testTypeAliasWithNewStyleUnion.py:28: note: Revealed type is "Union[Type[builtins.int], builtins.str]" +_testTypeAliasWithNewStyleUnion.py:25: note: Revealed type is "Union[type[builtins.int], builtins.str]" +_testTypeAliasWithNewStyleUnion.py:28: note: Revealed type is "Union[type[builtins.int], builtins.str]" [case testTypeAliasWithNewStyleUnionInStub] import m @@ -1686,12 +1686,12 @@ CU4: TypeAlias = int | Callable[[str | bool], str] [out] m.pyi:5: note: Revealed type is "typing._SpecialForm" m.pyi:22: note: Revealed type is "typing._SpecialForm" -_testTypeAliasWithNewStyleUnionInStub.py:3: note: Revealed type is "Union[Type[builtins.int], builtins.str]" -_testTypeAliasWithNewStyleUnionInStub.py:5: note: Revealed type is "Union[Type[builtins.int], builtins.str]" -_testTypeAliasWithNewStyleUnionInStub.py:7: note: Revealed type is "Union[Type[builtins.int], builtins.str]" -_testTypeAliasWithNewStyleUnionInStub.py:9: note: Revealed type is "Union[Type[builtins.int], builtins.str]" -_testTypeAliasWithNewStyleUnionInStub.py:11: note: Revealed type is "Union[builtins.str, Type[builtins.int]]" -_testTypeAliasWithNewStyleUnionInStub.py:13: note: Revealed type is "Union[builtins.str, Type[builtins.int]]" +_testTypeAliasWithNewStyleUnionInStub.py:3: note: Revealed type is "Union[type[builtins.int], builtins.str]" +_testTypeAliasWithNewStyleUnionInStub.py:5: note: Revealed type is "Union[type[builtins.int], builtins.str]" +_testTypeAliasWithNewStyleUnionInStub.py:7: note: Revealed type is "Union[type[builtins.int], builtins.str]" +_testTypeAliasWithNewStyleUnionInStub.py:9: note: Revealed type is "Union[type[builtins.int], builtins.str]" +_testTypeAliasWithNewStyleUnionInStub.py:11: note: Revealed type is "Union[builtins.str, type[builtins.int]]" +_testTypeAliasWithNewStyleUnionInStub.py:13: note: Revealed type is "Union[builtins.str, type[builtins.int]]" [case testEnumNameWorkCorrectlyOn311] # flags: --python-version 3.11 @@ -1727,11 +1727,11 @@ D: TypeAlias = str | int _testTypeAliasNotSupportedWithNewStyleUnion.py:3: error: Invalid type alias: expression is not a valid type _testTypeAliasNotSupportedWithNewStyleUnion.py:3: error: Unsupported left operand type for | ("GenericAlias") _testTypeAliasNotSupportedWithNewStyleUnion.py:4: error: Invalid type alias: expression is not a valid type -_testTypeAliasNotSupportedWithNewStyleUnion.py:4: error: Unsupported left operand type for | ("Type[str]") +_testTypeAliasNotSupportedWithNewStyleUnion.py:4: error: Unsupported left operand type for | ("type[str]") _testTypeAliasNotSupportedWithNewStyleUnion.py:5: error: Invalid type alias: expression is not a valid type -_testTypeAliasNotSupportedWithNewStyleUnion.py:5: error: Unsupported left operand type for | ("Type[str]") +_testTypeAliasNotSupportedWithNewStyleUnion.py:5: error: Unsupported left operand type for | ("type[str]") _testTypeAliasNotSupportedWithNewStyleUnion.py:6: error: Invalid type alias: expression is not a valid type -_testTypeAliasNotSupportedWithNewStyleUnion.py:6: error: Unsupported left operand type for | ("Type[str]") +_testTypeAliasNotSupportedWithNewStyleUnion.py:6: error: Unsupported left operand type for | ("type[str]") [case testTypedDictUnionGetFull] from typing import Dict @@ -1780,15 +1780,15 @@ WrongEllipsis = tuple[float, float, ...] | str # Error reveal_type(tuple[int, str]((1, "x"))) [out] -_testTupleWithDifferentArgsPy310.py:15: note: Revealed type is "Union[builtins.str, Tuple[builtins.float, builtins.float, builtins.str]]" -_testTupleWithDifferentArgsPy310.py:16: note: Revealed type is "Union[Tuple[builtins.float], builtins.str]" +_testTupleWithDifferentArgsPy310.py:15: note: Revealed type is "Union[builtins.str, tuple[builtins.float, builtins.float, builtins.str]]" +_testTupleWithDifferentArgsPy310.py:16: note: Revealed type is "Union[tuple[builtins.float], builtins.str]" _testTupleWithDifferentArgsPy310.py:17: note: Revealed type is "Union[builtins.tuple[builtins.float, ...], builtins.str]" -_testTupleWithDifferentArgsPy310.py:18: note: Revealed type is "Tuple[builtins.float, builtins.str]" +_testTupleWithDifferentArgsPy310.py:18: note: Revealed type is "tuple[builtins.float, builtins.str]" _testTupleWithDifferentArgsPy310.py:19: note: Revealed type is "builtins.tuple[builtins.float, ...]" -_testTupleWithDifferentArgsPy310.py:20: note: Revealed type is "builtins.list[Tuple[builtins.int, builtins.str]]" +_testTupleWithDifferentArgsPy310.py:20: note: Revealed type is "builtins.list[tuple[builtins.int, builtins.str]]" _testTupleWithDifferentArgsPy310.py:26: error: Invalid type: try using Literal[1] instead? _testTupleWithDifferentArgsPy310.py:27: error: Unexpected "..." -_testTupleWithDifferentArgsPy310.py:29: note: Revealed type is "Tuple[builtins.int, builtins.str]" +_testTupleWithDifferentArgsPy310.py:29: note: Revealed type is "tuple[builtins.int, builtins.str]" [case testEnumIterMetaInference] import socket @@ -1930,7 +1930,7 @@ Foo().__dict__ = {} _testInferenceOfDunderDictOnClassObjects.py:2: note: Revealed type is "types.MappingProxyType[builtins.str, Any]" _testInferenceOfDunderDictOnClassObjects.py:3: note: Revealed type is "builtins.dict[builtins.str, Any]" _testInferenceOfDunderDictOnClassObjects.py:4: error: Property "__dict__" defined in "type" is read-only -_testInferenceOfDunderDictOnClassObjects.py:4: error: Incompatible types in assignment (expression has type "Dict[Never, Never]", variable has type "MappingProxyType[str, Any]") +_testInferenceOfDunderDictOnClassObjects.py:4: error: Incompatible types in assignment (expression has type "dict[Never, Never]", variable has type "MappingProxyType[str, Any]") [case testTypeVarTuple] # flags: --python-version=3.11 diff --git a/test-data/unit/semanal-classes.test b/test-data/unit/semanal-classes.test index b14358509f85..7022da01eeaf 100644 --- a/test-data/unit/semanal-classes.test +++ b/test-data/unit/semanal-classes.test @@ -472,7 +472,7 @@ MypyFile:1( Args( Var(cls) Var(z)) - def (cls: Type[__main__.A], z: builtins.int) -> builtins.str + def (cls: type[__main__.A], z: builtins.int) -> builtins.str Class Block:3( PassStmt:3()))))) @@ -492,7 +492,7 @@ MypyFile:1( f Args( Var(cls)) - def (cls: Type[__main__.A]) -> builtins.str + def (cls: type[__main__.A]) -> builtins.str Class Block:3( PassStmt:3()))))) @@ -583,7 +583,7 @@ MypyFile:1( ClassDef:2( A TupleType( - Tuple[builtins.int, builtins.str]) + tuple[builtins.int, builtins.str]) BaseType( builtins.tuple[Union[builtins.int, builtins.str], ...]) PassStmt:2())) diff --git a/test-data/unit/semanal-namedtuple.test b/test-data/unit/semanal-namedtuple.test index 16944391da86..62bd87f1995a 100644 --- a/test-data/unit/semanal-namedtuple.test +++ b/test-data/unit/semanal-namedtuple.test @@ -10,10 +10,10 @@ MypyFile:1( ImportFrom:1(collections, [namedtuple]) AssignmentStmt:2( NameExpr(N* [__main__.N]) - NamedTupleExpr:2(N, Tuple[Any])) + NamedTupleExpr:2(N, tuple[Any])) FuncDef:3( f - def () -> Tuple[Any, fallback=__main__.N] + def () -> tuple[Any, fallback=__main__.N] Block:3( PassStmt:3()))) @@ -27,10 +27,10 @@ MypyFile:1( ImportFrom:1(collections, [namedtuple]) AssignmentStmt:2( NameExpr(N* [__main__.N]) - NamedTupleExpr:2(N, Tuple[Any, Any])) + NamedTupleExpr:2(N, tuple[Any, Any])) FuncDef:3( f - def () -> Tuple[Any, Any, fallback=__main__.N] + def () -> tuple[Any, Any, fallback=__main__.N] Block:3( PassStmt:3()))) @@ -44,10 +44,10 @@ MypyFile:1( ImportFrom:1(collections, [namedtuple]) AssignmentStmt:2( NameExpr(N* [__main__.N]) - NamedTupleExpr:2(N, Tuple[Any, Any])) + NamedTupleExpr:2(N, tuple[Any, Any])) FuncDef:3( f - def () -> Tuple[Any, Any, fallback=__main__.N] + def () -> tuple[Any, Any, fallback=__main__.N] Block:3( PassStmt:3()))) @@ -61,10 +61,10 @@ MypyFile:1( ImportFrom:1(collections, [namedtuple]) AssignmentStmt:2( NameExpr(N* [__main__.N]) - NamedTupleExpr:2(N, Tuple[Any, Any])) + NamedTupleExpr:2(N, tuple[Any, Any])) FuncDef:3( f - def () -> Tuple[Any, Any, fallback=__main__.N] + def () -> tuple[Any, Any, fallback=__main__.N] Block:3( PassStmt:3()))) @@ -78,7 +78,7 @@ MypyFile:1( ImportFrom:1(typing, [NamedTuple]) AssignmentStmt:2( NameExpr(N* [__main__.N]) - NamedTupleExpr:2(N, Tuple[builtins.int, builtins.str]))) + NamedTupleExpr:2(N, tuple[builtins.int, builtins.str]))) [case testNamedTupleWithTupleFieldNamesWithItemTypes] from typing import NamedTuple @@ -90,7 +90,7 @@ MypyFile:1( ImportFrom:1(typing, [NamedTuple]) AssignmentStmt:2( NameExpr(N* [__main__.N]) - NamedTupleExpr:2(N, Tuple[builtins.int, builtins.str]))) + NamedTupleExpr:2(N, tuple[builtins.int, builtins.str]))) [case testNamedTupleBaseClass] from collections import namedtuple @@ -102,11 +102,11 @@ MypyFile:1( ImportFrom:1(collections, [namedtuple]) AssignmentStmt:2( NameExpr(N* [__main__.N]) - NamedTupleExpr:2(N, Tuple[Any])) + NamedTupleExpr:2(N, tuple[Any])) ClassDef:3( A TupleType( - Tuple[Any, fallback=__main__.N]) + tuple[Any, fallback=__main__.N]) BaseType( __main__.N) PassStmt:3())) @@ -121,7 +121,7 @@ MypyFile:1( ClassDef:2( A TupleType( - Tuple[Any, fallback=__main__.N@2]) + tuple[Any, fallback=__main__.N@2]) BaseType( __main__.N@2) PassStmt:2())) @@ -136,7 +136,7 @@ MypyFile:1( ClassDef:2( A TupleType( - Tuple[builtins.int, fallback=__main__.N@2]) + tuple[builtins.int, fallback=__main__.N@2]) BaseType( __main__.N@2) PassStmt:2())) @@ -239,7 +239,7 @@ MypyFile:1( ClassDef:4( A TupleType( - Tuple[builtins.int, fallback=__main__.N@4]) + tuple[builtins.int, fallback=__main__.N@4]) Decorators( NameExpr(final [typing.final])) BaseType( diff --git a/test-data/unit/semanal-typealiases.test b/test-data/unit/semanal-typealiases.test index 88d234134350..e2c1c4863157 100644 --- a/test-data/unit/semanal-typealiases.test +++ b/test-data/unit/semanal-typealiases.test @@ -177,12 +177,12 @@ MypyFile:1( ImportFrom:1(typing, [Tuple]) AssignmentStmt:2( NameExpr(T* [__main__.T]) - TypeAliasExpr(Tuple[builtins.int, builtins.str])) + TypeAliasExpr(tuple[builtins.int, builtins.str])) FuncDef:3( f Args( Var(x)) - def (x: Tuple[builtins.int, builtins.str]) + def (x: tuple[builtins.int, builtins.str]) Block:3( PassStmt:3()))) @@ -439,8 +439,8 @@ MypyFile:1( ImportFrom:1(typing, [Union, Tuple, Any]) AssignmentStmt:2( NameExpr(A* [__main__.A]) - TypeAliasExpr(Union[builtins.int, Tuple[builtins.int, Any]])) + TypeAliasExpr(Union[builtins.int, tuple[builtins.int, Any]])) AssignmentStmt:3( NameExpr(a [__main__.a]) IntExpr(1) - Union[builtins.int, Tuple[builtins.int, Any]])) + Union[builtins.int, tuple[builtins.int, Any]])) diff --git a/test-data/unit/semanal-types.test b/test-data/unit/semanal-types.test index 83c44738f055..a91d334af146 100644 --- a/test-data/unit/semanal-types.test +++ b/test-data/unit/semanal-types.test @@ -163,7 +163,7 @@ MypyFile:1( TupleExpr:4( NameExpr(None [builtins.None]) NameExpr(None [builtins.None])) - Tuple[__main__.A, __main__.B]) + tuple[__main__.A, __main__.B]) AssignmentStmt:5( NameExpr(x* [__main__.x]) TupleExpr:5( @@ -366,7 +366,7 @@ MypyFile:1( ExpressionStmt:2( CastExpr:2( NameExpr(None [builtins.None]) - Tuple[builtins.int, builtins.str]))) + tuple[builtins.int, builtins.str]))) [case testCastToFunctionType] from typing import Callable, cast @@ -493,7 +493,7 @@ MypyFile:1( f Args( Var(x)) - def [t] (x: Tuple[builtins.int, t`-1]) + def [t] (x: tuple[builtins.int, t`-1]) Block:4( PassStmt:4()))) @@ -694,11 +694,11 @@ MypyFile:1( AssignmentStmt:3( NameExpr(t1 [__main__.t1]) NameExpr(None [builtins.None]) - Tuple[builtins.object]) + tuple[builtins.object]) AssignmentStmt:4( NameExpr(t2 [__main__.t2]) NameExpr(None [builtins.None]) - Tuple[builtins.int, builtins.object])) + tuple[builtins.int, builtins.object])) [case testVariableLengthTuple] from typing import Tuple diff --git a/test-data/unit/typexport-basic.test b/test-data/unit/typexport-basic.test index 512b572801d2..77e7763824d6 100644 --- a/test-data/unit/typexport-basic.test +++ b/test-data/unit/typexport-basic.test @@ -214,7 +214,7 @@ f( B()) [builtins fixtures/tuple-simple.pyi] [out] -CallExpr(6) : Tuple[A, B] +CallExpr(6) : tuple[A, B] CallExpr(7) : A CallExpr(8) : B @@ -294,8 +294,8 @@ import typing x = () [builtins fixtures/primitives.pyi] [out] -NameExpr(2) : Tuple[()] -TupleExpr(2) : Tuple[()] +NameExpr(2) : tuple[()] +TupleExpr(2) : tuple[()] [case testInferTwoTypes] ## NameExpr @@ -313,8 +313,8 @@ def f() -> None: x = () [builtins fixtures/primitives.pyi] [out] -NameExpr(3) : Tuple[()] -TupleExpr(3) : Tuple[()] +NameExpr(3) : tuple[()] +TupleExpr(3) : tuple[()] -- Basic generics From dcde1aa7f2cdef87752db7140d4ed4c8fe4f9cfc Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 30 May 2025 12:41:45 +0200 Subject: [PATCH 4/4] Use PYTHON3_VERSION_MIN --- mypy/test/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypy/test/helpers.py b/mypy/test/helpers.py index 2fc20f6ec6e7..ae432ff6981b 100644 --- a/mypy/test/helpers.py +++ b/mypy/test/helpers.py @@ -261,9 +261,9 @@ def testfile_pyversion(path: str) -> tuple[int, int]: if m := re.search(r"python3([0-9]+)\.test$", path): # For older unsupported version like python38, # default to that earliest supported version. - return max((3, int(m.group(1))), defaults.PYTHON3_VERSION) + return max((3, int(m.group(1))), defaults.PYTHON3_VERSION_MIN) else: - return defaults.PYTHON3_VERSION + return defaults.PYTHON3_VERSION_MIN def normalize_error_messages(messages: list[str]) -> list[str]: