Skip to content

Commit 947f650

Browse files
authored
Use lower case "list" and "dict" in invariance notes (#18594)
All supported Python versions support `list[...]` and `dict[...]`.
1 parent 237933a commit 947f650

11 files changed

+18
-18
lines changed

mypy/messages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3270,15 +3270,15 @@ def append_invariance_notes(
32703270
and expected_type.type.fullname == "builtins.list"
32713271
and is_subtype(arg_type.args[0], expected_type.args[0])
32723272
):
3273-
invariant_type = "List"
3273+
invariant_type = "list"
32743274
covariant_suggestion = 'Consider using "Sequence" instead, which is covariant'
32753275
elif (
32763276
arg_type.type.fullname == "builtins.dict"
32773277
and expected_type.type.fullname == "builtins.dict"
32783278
and is_same_type(arg_type.args[0], expected_type.args[0])
32793279
and is_subtype(arg_type.args[1], expected_type.args[1])
32803280
):
3281-
invariant_type = "Dict"
3281+
invariant_type = "dict"
32823282
covariant_suggestion = (
32833283
'Consider using "Mapping" instead, which is covariant in the value type'
32843284
)

test-data/unit/check-basic.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ from typing import List
379379
x: List[int]
380380
y: List[float]
381381
y = x # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[float]") \
382-
# N: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
382+
# N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
383383
# N: Consider using "Sequence" instead, which is covariant
384384
[builtins fixtures/list.pyi]
385385

@@ -388,7 +388,7 @@ from typing import Dict
388388
x: Dict[str, int]
389389
y: Dict[str, float]
390390
y = x # E: Incompatible types in assignment (expression has type "Dict[str, int]", variable has type "Dict[str, float]") \
391-
# N: "Dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
391+
# N: "dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
392392
# N: Consider using "Mapping" instead, which is covariant in the value type
393393
[builtins fixtures/dict.pyi]
394394

test-data/unit/check-functions.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,14 +2503,14 @@ from typing import Union, Dict, List
25032503
def f() -> List[Union[str, int]]:
25042504
x = ['a']
25052505
return x # E: Incompatible return value type (got "List[str]", expected "List[Union[str, int]]") \
2506-
# N: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
2506+
# N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
25072507
# N: Consider using "Sequence" instead, which is covariant \
25082508
# N: Perhaps you need a type annotation for "x"? Suggestion: "List[Union[str, int]]"
25092509

25102510
def g() -> Dict[str, Union[str, int]]:
25112511
x = {'a': 'a'}
25122512
return x # E: Incompatible return value type (got "Dict[str, str]", expected "Dict[str, Union[str, int]]") \
2513-
# N: "Dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
2513+
# N: "dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
25142514
# N: Consider using "Mapping" instead, which is covariant in the value type \
25152515
# N: Perhaps you need a type annotation for "x"? Suggestion: "Dict[str, Union[str, int]]"
25162516

@@ -2522,7 +2522,7 @@ def h() -> Dict[Union[str, int], str]:
25222522
def i() -> List[Union[int, float]]:
25232523
x: List[int] = [1]
25242524
return x # E: Incompatible return value type (got "List[int]", expected "List[Union[int, float]]") \
2525-
# N: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
2525+
# N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
25262526
# N: Consider using "Sequence" instead, which is covariant
25272527

25282528
[builtins fixtures/dict.pyi]

test-data/unit/check-inference.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ if int():
15351535
if int():
15361536
a = x3 \
15371537
# E: Incompatible types in assignment (expression has type "List[B]", variable has type "List[A]") \
1538-
# N: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
1538+
# N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
15391539
# N: Consider using "Sequence" instead, which is covariant
15401540
[builtins fixtures/list.pyi]
15411541
[typing fixtures/typing-medium.pyi]
@@ -1558,7 +1558,7 @@ if int():
15581558
if int():
15591559
a = x3 \
15601560
# E: Incompatible types in assignment (expression has type "List[B]", variable has type "List[A]") \
1561-
# N: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
1561+
# N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
15621562
# N: Consider using "Sequence" instead, which is covariant
15631563
[builtins fixtures/list.pyi]
15641564
[typing fixtures/typing-medium.pyi]

test-data/unit/check-literal.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ a: List[Literal[1]]
947947
b: List[Literal[1, 2, 3]]
948948

949949
foo(a) # E: Argument 1 to "foo" has incompatible type "List[Literal[1]]"; expected "List[Literal[1, 2]]" \
950-
# N: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
950+
# N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
951951
# N: Consider using "Sequence" instead, which is covariant
952952
foo(b) # E: Argument 1 to "foo" has incompatible type "List[Literal[1, 2, 3]]"; expected "List[Literal[1, 2]]"
953953
bar(a)

test-data/unit/check-optional.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ asdf(x)
786786
strict_optional = False
787787
[out]
788788
main:4: error: Argument 1 to "asdf" has incompatible type "List[str]"; expected "List[Optional[str]]"
789-
main:4: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
789+
main:4: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
790790
main:4: note: Consider using "Sequence" instead, which is covariant
791791
[builtins fixtures/list.pyi]
792792

test-data/unit/check-overloading.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ main:18: note: Revealed type is "builtins.str"
14151415
main:19: note: Revealed type is "Any"
14161416
main:20: note: Revealed type is "Union[builtins.int, builtins.str]"
14171417
main:21: error: Argument 1 to "foo" has incompatible type "List[bool]"; expected "List[int]"
1418-
main:21: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
1418+
main:21: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
14191419
main:21: note: Consider using "Sequence" instead, which is covariant
14201420
main:22: error: Argument 1 to "foo" has incompatible type "List[object]"; expected "List[int]"
14211421
main:23: error: Argument 1 to "foo" has incompatible type "List[Union[int, str]]"; expected "List[int]"

test-data/unit/check-typevar-values.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if int():
2121
s = f('')
2222
o = f(1) \
2323
# E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[object]") \
24-
# N: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
24+
# N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
2525
# N: Consider using "Sequence" instead, which is covariant
2626
[builtins fixtures/list.pyi]
2727

test-data/unit/check-unions.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ def do_thing_with_enums(enums: Union[List[Enum], Enum]) -> None: ...
10501050

10511051
boop: List[Boop] = []
10521052
do_thing_with_enums(boop) # E: Argument 1 to "do_thing_with_enums" has incompatible type "List[Boop]"; expected "Union[List[Enum], Enum]" \
1053-
# N: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
1053+
# N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
10541054
# N: Consider using "Sequence" instead, which is covariant
10551055
[builtins fixtures/isinstancelist.pyi]
10561056

test-data/unit/check-varargs.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,12 @@ b = {'b': ['c', 'd']}
679679
c = {'c': 1.0}
680680
d = {'d': 1}
681681
f(a) # E: Argument 1 to "f" has incompatible type "Dict[str, List[int]]"; expected "Dict[str, Sequence[int]]" \
682-
# N: "Dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
682+
# N: "dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
683683
# N: Consider using "Mapping" instead, which is covariant in the value type
684684
f(b) # E: Argument 1 to "f" has incompatible type "Dict[str, List[str]]"; expected "Dict[str, Sequence[int]]"
685685
g(c)
686686
g(d) # E: Argument 1 to "g" has incompatible type "Dict[str, int]"; expected "Dict[str, float]" \
687-
# N: "Dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
687+
# N: "dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
688688
# N: Consider using "Mapping" instead, which is covariant in the value type
689689
h(c) # E: Argument 1 to "h" has incompatible type "Dict[str, float]"; expected "Dict[str, int]"
690690
h(d)
@@ -696,7 +696,7 @@ from typing import List, Union
696696
def f(numbers: List[Union[int, float]]) -> None: pass
697697
a = [1, 2]
698698
f(a) # E: Argument 1 to "f" has incompatible type "List[int]"; expected "List[Union[int, float]]" \
699-
# N: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
699+
# N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
700700
# N: Consider using "Sequence" instead, which is covariant
701701
x = [1]
702702
y = ['a']

test-data/unit/cmdline.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ y = [] # type: List[int]
832832
x = y
833833
[out]
834834
bad.py:4: error: Incompatible types in assignment (expression has type "List[int]", variable has type "List[float]")
835-
bad.py:4: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
835+
bad.py:4: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
836836
bad.py:4: note: Consider using "Sequence" instead, which is covariant
837837
Found 1 error in 1 file (checked 1 source file)
838838

0 commit comments

Comments
 (0)