diff --git a/mypy/messages.py b/mypy/messages.py index 2e07d7f63498..5457cea04a18 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -1784,7 +1784,7 @@ def reveal_locals(self, type_map: dict[str, Type | None], context: Context) -> N def unsupported_type_type(self, item: Type, context: Context) -> None: self.fail( - f'Cannot instantiate type "Type[{format_type_bare(item, self.options)}]"', context + f'Cannot instantiate type "type[{format_type_bare(item, self.options)}]"', context ) def redundant_cast(self, typ: Type, context: Context) -> None: diff --git a/mypy/semanal.py b/mypy/semanal.py index c5f4443588f8..855c279756e8 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -3985,7 +3985,7 @@ def check_and_set_up_type_alias(self, s: AssignmentStmt) -> bool: if isinstance(existing.node, TypeAlias) and not s.is_alias_def: self.fail( 'Cannot assign multiple types to name "{}"' - ' without an explicit "Type[...]" annotation'.format(lvalue.name), + ' without an explicit "type[...]" annotation'.format(lvalue.name), lvalue, ) return False diff --git a/mypy/suggestions.py b/mypy/suggestions.py index f27ad7cdb637..a662dd7b98e9 100644 --- a/mypy/suggestions.py +++ b/mypy/suggestions.py @@ -53,7 +53,6 @@ SymbolTable, TypeInfo, Var, - reverse_builtin_aliases, ) from mypy.options import Options from mypy.plugin import FunctionContext, MethodContext, Plugin @@ -830,8 +829,6 @@ def visit_instance(self, t: Instance) -> str: s = t.type.fullname or t.type.name or None if s is None: return "" - if s in reverse_builtin_aliases: - s = reverse_builtin_aliases[s] mod_obj = split_target(self.graph, s) assert mod_obj diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index 93b575e25309..f8b841185fc6 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -3688,7 +3688,7 @@ def process(cls: Type[U]): [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] diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index 89693a6a7be0..dbc39d79d921 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -1019,7 +1019,7 @@ class C: if int(): a = B if int(): - b = int # E: Cannot assign multiple types to name "b" without an explicit "Type[...]" annotation + b = int # E: Cannot assign multiple types to name "b" without an explicit "type[...]" annotation if int(): c = int def f(self, x: a) -> None: pass # E: Variable "__main__.C.a" is not valid as a type \ diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index 5f7646c62e96..718d730132ae 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -73,7 +73,7 @@ U = Union[int, str] [case testProhibitReassigningAliases] A = float if int(): - A = int # E: Cannot assign multiple types to name "A" without an explicit "Type[...]" annotation + A = int # E: Cannot assign multiple types to name "A" without an explicit "type[...]" annotation [out] [case testProhibitReassigningSubscriptedAliases] @@ -81,7 +81,7 @@ from typing import Callable A = Callable[[], float] if int(): A = Callable[[], int] \ - # E: Cannot assign multiple types to name "A" without an explicit "Type[...]" annotation \ + # E: Cannot assign multiple types to name "A" without an explicit "type[...]" annotation \ # E: Value of type "int" is not indexable # the second error is because of `Callable = 0` in lib-stub/typing.pyi [builtins fixtures/list.pyi] @@ -93,7 +93,7 @@ T = TypeVar('T') A = Tuple[T, T] if int(): - A = Union[T, int] # E: Cannot assign multiple types to name "A" without an explicit "Type[...]" annotation + A = Union[T, int] # E: Cannot assign multiple types to name "A" without an explicit "type[...]" annotation [builtins fixtures/tuple.pyi] [typing fixtures/typing-full.pyi] @@ -926,12 +926,12 @@ class Child(Parent): pass p = Parent() c = Child() -NormalImplicit = 4 # E: Cannot assign multiple types to name "NormalImplicit" without an explicit "Type[...]" annotation \ +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]") -NormalExplicit = 4 # E: Cannot assign multiple types to name "NormalExplicit" without an explicit "Type[...]" annotation \ +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]") -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 +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]") diff --git a/test-data/unit/fine-grained-suggest.test b/test-data/unit/fine-grained-suggest.test index ba6006300a4c..7034b5e48943 100644 --- a/test-data/unit/fine-grained-suggest.test +++ b/test-data/unit/fine-grained-suggest.test @@ -17,8 +17,8 @@ def bar() -> None: [out] bar.py:3: (str) bar.py:4: (arg=str) -bar.py:6: (*typing.List[str]) -bar.py:8: (**typing.Dict[str, str]) +bar.py:6: (*list[str]) +bar.py:8: (**dict[str, str]) == [case testSuggestCallsitesStep2] @@ -41,8 +41,8 @@ def bar() -> None: == bar.py:3: (str) bar.py:4: (arg=str) -bar.py:6: (*typing.List[str]) -bar.py:8: (**typing.Dict[str, str]) +bar.py:6: (*list[str]) +bar.py:8: (**dict[str, str]) [case testMaxGuesses] # suggest: foo.foo @@ -691,8 +691,8 @@ No guesses that match criteria! (int, int) -> Any No guesses that match criteria! == -(typing.List[Any]) -> int -(typing.List[Any]) -> int +(list[Any]) -> int +(list[Any]) -> int [case testSuggestFlexAny2] @@ -965,7 +965,7 @@ def g(): ... z = foo(f(), g()) [builtins fixtures/isinstancelist.pyi] [out] -(foo.List[Any], UNKNOWN) -> Tuple[foo.List[Any], Any] +(list[Any], UNKNOWN) -> Tuple[list[Any], Any] == [case testSuggestBadImport] @@ -1007,11 +1007,11 @@ spam({'x': 5}) [builtins fixtures/dict.pyi] [out] -() -> typing.Dict[str, int] -() -> typing.Dict[Any, Any] -() -> foo:List[typing.Dict[str, int]] -() -> foo.List[int] -(typing.Dict[str, int]) -> None +() -> dict[str, int] +() -> dict[Any, Any] +() -> list[dict[str, int]] +() -> list[int] +(dict[str, int]) -> None == [case testSuggestWithErrors] @@ -1161,18 +1161,18 @@ tuple1(t) [out] (int, int) -> int (int, int) -> int -(int) -> foo.List[int] -(foo.List[int]) -> int +(int) -> list[int] +(list[int]) -> int (Union[int, str]) -> None (Callable[[int], int]) -> int (Callable[[float], int]) -> int (Optional[int]) -> None (Union[None, int, str]) -> None -(Optional[foo.List[int]]) -> int -(Union[foo.Set[int], foo.List[int]]) -> None +(Optional[list[int]]) -> int +(Union[set[int], list[int]]) -> None (Optional[int]) -> None (Optional[Any]) -> None -(foo.Dict[int, int]) -> None +(dict[int, int]) -> None (Tuple[int, int]) -> None ==