Skip to content

Commit e57ece0

Browse files
authored
Use more lower case builtins in error messages (#19177)
1 parent 409d294 commit e57ece0

File tree

7 files changed

+29
-32
lines changed

7 files changed

+29
-32
lines changed

mypy/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@ def reveal_locals(self, type_map: dict[str, Type | None], context: Context) -> N
17841784

17851785
def unsupported_type_type(self, item: Type, context: Context) -> None:
17861786
self.fail(
1787-
f'Cannot instantiate type "Type[{format_type_bare(item, self.options)}]"', context
1787+
f'Cannot instantiate type "type[{format_type_bare(item, self.options)}]"', context
17881788
)
17891789

17901790
def redundant_cast(self, typ: Type, context: Context) -> None:

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3985,7 +3985,7 @@ def check_and_set_up_type_alias(self, s: AssignmentStmt) -> bool:
39853985
if isinstance(existing.node, TypeAlias) and not s.is_alias_def:
39863986
self.fail(
39873987
'Cannot assign multiple types to name "{}"'
3988-
' without an explicit "Type[...]" annotation'.format(lvalue.name),
3988+
' without an explicit "type[...]" annotation'.format(lvalue.name),
39893989
lvalue,
39903990
)
39913991
return False

mypy/suggestions.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
SymbolTable,
5454
TypeInfo,
5555
Var,
56-
reverse_builtin_aliases,
5756
)
5857
from mypy.options import Options
5958
from mypy.plugin import FunctionContext, MethodContext, Plugin
@@ -830,8 +829,6 @@ def visit_instance(self, t: Instance) -> str:
830829
s = t.type.fullname or t.type.name or None
831830
if s is None:
832831
return "<???>"
833-
if s in reverse_builtin_aliases:
834-
s = reverse_builtin_aliases[s]
835832

836833
mod_obj = split_target(self.graph, s)
837834
assert mod_obj

test-data/unit/check-classes.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3688,7 +3688,7 @@ def process(cls: Type[U]):
36883688
[case testTypeUsingTypeCErrorUnsupportedType]
36893689
from typing import Type, Tuple
36903690
def foo(arg: Type[Tuple[int]]):
3691-
arg() # E: Cannot instantiate type "Type[tuple[int]]"
3691+
arg() # E: Cannot instantiate type "type[tuple[int]]"
36923692
[builtins fixtures/tuple.pyi]
36933693

36943694
[case testTypeUsingTypeCOverloadedClass]
@@ -3732,7 +3732,7 @@ def f(a: T): pass
37323732
[case testTypeUsingTypeCTuple]
37333733
from typing import Type, Tuple
37343734
def f(a: Type[Tuple[int, int]]):
3735-
a() # E: Cannot instantiate type "Type[tuple[int, int]]"
3735+
a() # E: Cannot instantiate type "type[tuple[int, int]]"
37363736
[builtins fixtures/tuple.pyi]
37373737

37383738
[case testTypeUsingTypeCNamedTuple]

test-data/unit/check-generics.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ class C:
10191019
if int():
10201020
a = B
10211021
if int():
1022-
b = int # E: Cannot assign multiple types to name "b" without an explicit "Type[...]" annotation
1022+
b = int # E: Cannot assign multiple types to name "b" without an explicit "type[...]" annotation
10231023
if int():
10241024
c = int
10251025
def f(self, x: a) -> None: pass # E: Variable "__main__.C.a" is not valid as a type \

test-data/unit/check-type-aliases.test

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ U = Union[int, str]
7373
[case testProhibitReassigningAliases]
7474
A = float
7575
if int():
76-
A = int # E: Cannot assign multiple types to name "A" without an explicit "Type[...]" annotation
76+
A = int # E: Cannot assign multiple types to name "A" without an explicit "type[...]" annotation
7777
[out]
7878

7979
[case testProhibitReassigningSubscriptedAliases]
8080
from typing import Callable
8181
A = Callable[[], float]
8282
if int():
8383
A = Callable[[], int] \
84-
# E: Cannot assign multiple types to name "A" without an explicit "Type[...]" annotation \
84+
# E: Cannot assign multiple types to name "A" without an explicit "type[...]" annotation \
8585
# E: Value of type "int" is not indexable
8686
# the second error is because of `Callable = 0` in lib-stub/typing.pyi
8787
[builtins fixtures/list.pyi]
@@ -93,7 +93,7 @@ T = TypeVar('T')
9393

9494
A = Tuple[T, T]
9595
if int():
96-
A = Union[T, int] # E: Cannot assign multiple types to name "A" without an explicit "Type[...]" annotation
96+
A = Union[T, int] # E: Cannot assign multiple types to name "A" without an explicit "type[...]" annotation
9797
[builtins fixtures/tuple.pyi]
9898
[typing fixtures/typing-full.pyi]
9999

@@ -926,12 +926,12 @@ class Child(Parent): pass
926926
p = Parent()
927927
c = Child()
928928

929-
NormalImplicit = 4 # E: Cannot assign multiple types to name "NormalImplicit" without an explicit "Type[...]" annotation \
929+
NormalImplicit = 4 # E: Cannot assign multiple types to name "NormalImplicit" without an explicit "type[...]" annotation \
930930
# E: Incompatible types in assignment (expression has type "int", variable has type "type[Foo]")
931-
NormalExplicit = 4 # E: Cannot assign multiple types to name "NormalExplicit" without an explicit "Type[...]" annotation \
931+
NormalExplicit = 4 # E: Cannot assign multiple types to name "NormalExplicit" without an explicit "type[...]" annotation \
932932
# E: Incompatible types in assignment (expression has type "int", variable has type "type[Foo]")
933-
SpecialImplicit = 4 # E: Cannot assign multiple types to name "SpecialImplicit" without an explicit "Type[...]" annotation
934-
SpecialExplicit = 4 # E: Cannot assign multiple types to name "SpecialExplicit" without an explicit "Type[...]" annotation
933+
SpecialImplicit = 4 # E: Cannot assign multiple types to name "SpecialImplicit" without an explicit "type[...]" annotation
934+
SpecialExplicit = 4 # E: Cannot assign multiple types to name "SpecialExplicit" without an explicit "type[...]" annotation
935935

936936
Parent.NormalImplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "type[Foo]")
937937
Parent.NormalExplicit = 4 # E: Incompatible types in assignment (expression has type "int", variable has type "type[Foo]")

test-data/unit/fine-grained-suggest.test

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def bar() -> None:
1717
[out]
1818
bar.py:3: (str)
1919
bar.py:4: (arg=str)
20-
bar.py:6: (*typing.List[str])
21-
bar.py:8: (**typing.Dict[str, str])
20+
bar.py:6: (*list[str])
21+
bar.py:8: (**dict[str, str])
2222
==
2323

2424
[case testSuggestCallsitesStep2]
@@ -41,8 +41,8 @@ def bar() -> None:
4141
==
4242
bar.py:3: (str)
4343
bar.py:4: (arg=str)
44-
bar.py:6: (*typing.List[str])
45-
bar.py:8: (**typing.Dict[str, str])
44+
bar.py:6: (*list[str])
45+
bar.py:8: (**dict[str, str])
4646

4747
[case testMaxGuesses]
4848
# suggest: foo.foo
@@ -691,8 +691,8 @@ No guesses that match criteria!
691691
(int, int) -> Any
692692
No guesses that match criteria!
693693
==
694-
(typing.List[Any]) -> int
695-
(typing.List[Any]) -> int
694+
(list[Any]) -> int
695+
(list[Any]) -> int
696696

697697

698698
[case testSuggestFlexAny2]
@@ -965,7 +965,7 @@ def g(): ...
965965
z = foo(f(), g())
966966
[builtins fixtures/isinstancelist.pyi]
967967
[out]
968-
(foo.List[Any], UNKNOWN) -> Tuple[foo.List[Any], Any]
968+
(list[Any], UNKNOWN) -> Tuple[list[Any], Any]
969969
==
970970

971971
[case testSuggestBadImport]
@@ -1007,11 +1007,11 @@ spam({'x': 5})
10071007

10081008
[builtins fixtures/dict.pyi]
10091009
[out]
1010-
() -> typing.Dict[str, int]
1011-
() -> typing.Dict[Any, Any]
1012-
() -> foo:List[typing.Dict[str, int]]
1013-
() -> foo.List[int]
1014-
(typing.Dict[str, int]) -> None
1010+
() -> dict[str, int]
1011+
() -> dict[Any, Any]
1012+
() -> list[dict[str, int]]
1013+
() -> list[int]
1014+
(dict[str, int]) -> None
10151015
==
10161016

10171017
[case testSuggestWithErrors]
@@ -1161,18 +1161,18 @@ tuple1(t)
11611161
[out]
11621162
(int, int) -> int
11631163
(int, int) -> int
1164-
(int) -> foo.List[int]
1165-
(foo.List[int]) -> int
1164+
(int) -> list[int]
1165+
(list[int]) -> int
11661166
(Union[int, str]) -> None
11671167
(Callable[[int], int]) -> int
11681168
(Callable[[float], int]) -> int
11691169
(Optional[int]) -> None
11701170
(Union[None, int, str]) -> None
1171-
(Optional[foo.List[int]]) -> int
1172-
(Union[foo.Set[int], foo.List[int]]) -> None
1171+
(Optional[list[int]]) -> int
1172+
(Union[set[int], list[int]]) -> None
11731173
(Optional[int]) -> None
11741174
(Optional[Any]) -> None
1175-
(foo.Dict[int, int]) -> None
1175+
(dict[int, int]) -> None
11761176
(Tuple[int, int]) -> None
11771177
==
11781178

0 commit comments

Comments
 (0)