Skip to content

Commit 61a7f3b

Browse files
ikonsthauntsaninja
andauthored
Remove special casing for "cannot" in error messages (#15428)
Co-authored-by: hauntsaninja <[email protected]>
1 parent cab8c67 commit 61a7f3b

7 files changed

+151
-119
lines changed

mypy/test/helpers.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,9 @@ def run_mypy(args: list[str]) -> None:
4646
def assert_string_arrays_equal(expected: list[str], actual: list[str], msg: str) -> None:
4747
"""Assert that two string arrays are equal.
4848
49-
We consider "can't" and "cannot" equivalent, by replacing the
50-
former with the latter before comparing.
51-
5249
Display any differences in a human-readable form.
5350
"""
5451
actual = clean_up(actual)
55-
actual = [line.replace("can't", "cannot") for line in actual]
56-
expected = [line.replace("can't", "cannot") for line in expected]
57-
5852
if actual != expected:
5953
num_skip_start = num_skipped_prefix_lines(expected, actual)
6054
num_skip_end = num_skipped_suffix_lines(expected, actual)

test-data/unit/check-classes.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,7 @@ tmp/foo.pyi:5: note: @overload
20192019
tmp/foo.pyi:5: note: def __add__(self, int, /) -> int
20202020
tmp/foo.pyi:5: note: @overload
20212021
tmp/foo.pyi:5: note: def __add__(self, str, /) -> str
2022-
tmp/foo.pyi:5: note: Overloaded operator methods cannot have wider argument types in overrides
2022+
tmp/foo.pyi:5: note: Overloaded operator methods can't have wider argument types in overrides
20232023

20242024
[case testOperatorMethodOverrideWideningArgumentType]
20252025
import typing
@@ -2138,7 +2138,7 @@ tmp/foo.pyi:8: note: @overload
21382138
tmp/foo.pyi:8: note: def __add__(self, str, /) -> A
21392139
tmp/foo.pyi:8: note: @overload
21402140
tmp/foo.pyi:8: note: def __add__(self, type, /) -> A
2141-
tmp/foo.pyi:8: note: Overloaded operator methods cannot have wider argument types in overrides
2141+
tmp/foo.pyi:8: note: Overloaded operator methods can't have wider argument types in overrides
21422142

21432143
[case testOverloadedOperatorMethodOverrideWithSwitchedItemOrder]
21442144
from foo import *

test-data/unit/check-overloading.test

Lines changed: 76 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4745,7 +4745,7 @@ main:12: note: @overload
47454745
main:12: note: def __add__(self, Other, /) -> B
47464746
main:12: note: @overload
47474747
main:12: note: def __add__(self, A, /) -> A
4748-
main:12: note: Overloaded operator methods cannot have wider argument types in overrides
4748+
main:12: note: Overloaded operator methods can't have wider argument types in overrides
47494749
main:32: note: Revealed type is "__main__.Other"
47504750

47514751
[case testOverloadErrorMessageManyMatches]
@@ -5405,26 +5405,26 @@ if False:
54055405
def f2(g): ...
54065406
reveal_type(f2(A())) # N: Revealed type is "__main__.A"
54075407
reveal_type(f2(C())) # E: No overload variant of "f2" matches argument type "C" \
5408-
# N: Possible overload variants: \
5409-
# N: def f2(g: A) -> A \
5410-
# N: def f2(g: B) -> B \
5411-
# N: Revealed type is "Any"
5408+
# N: Possible overload variants: \
5409+
# N: def f2(g: A) -> A \
5410+
# N: def f2(g: B) -> B \
5411+
# N: Revealed type is "Any"
54125412

54135413
@overload
54145414
def f3(g: A) -> A: ...
54155415
@overload
54165416
def f3(g: B) -> B: ...
5417-
if maybe_true: # E: Condition cannot be inferred, unable to merge overloads \
5417+
if maybe_true: # E: Condition can't be inferred, unable to merge overloads \
54185418
# E: Name "maybe_true" is not defined
54195419
@overload
54205420
def f3(g: C) -> C: ...
54215421
def f3(g): ...
54225422
reveal_type(f3(A())) # N: Revealed type is "__main__.A"
54235423
reveal_type(f3(C())) # E: No overload variant of "f3" matches argument type "C" \
5424-
# N: Possible overload variants: \
5425-
# N: def f3(g: A) -> A \
5426-
# N: def f3(g: B) -> B \
5427-
# N: Revealed type is "Any"
5424+
# N: Possible overload variants: \
5425+
# N: def f3(g: A) -> A \
5426+
# N: def f3(g: B) -> B \
5427+
# N: Revealed type is "Any"
54285428

54295429
if True:
54305430
@overload
@@ -5731,10 +5731,10 @@ def f1(x): ...
57315731
reveal_type(f1(A())) # N: Revealed type is "__main__.A"
57325732
reveal_type(f1(B())) # N: Revealed type is "__main__.B"
57335733
reveal_type(f1(D())) # E: No overload variant of "f1" matches argument type "D" \
5734-
# N: Possible overload variants: \
5735-
# N: def f1(x: A) -> A \
5736-
# N: def f1(x: B) -> B \
5737-
# N: Revealed type is "Any"
5734+
# N: Possible overload variants: \
5735+
# N: def f1(x: A) -> A \
5736+
# N: def f1(x: B) -> B \
5737+
# N: Revealed type is "Any"
57385738

57395739
@overload
57405740
def f2(x: A) -> A: ...
@@ -5751,14 +5751,14 @@ def f2(x): ...
57515751
reveal_type(f2(A())) # N: Revealed type is "__main__.A"
57525752
reveal_type(f2(B())) # N: Revealed type is "__main__.B"
57535753
reveal_type(f2(C())) # E: No overload variant of "f2" matches argument type "C" \
5754-
# N: Possible overload variants: \
5755-
# N: def f2(x: A) -> A \
5756-
# N: def f2(x: B) -> B \
5757-
# N: Revealed type is "Any"
5754+
# N: Possible overload variants: \
5755+
# N: def f2(x: A) -> A \
5756+
# N: def f2(x: B) -> B \
5757+
# N: Revealed type is "Any"
57585758

57595759
@overload # E: Single overload definition, multiple required
57605760
def f3(x: A) -> A: ...
5761-
if maybe_true: # E: Condition cannot be inferred, unable to merge overloads \
5761+
if maybe_true: # E: Condition can't be inferred, unable to merge overloads \
57625762
# E: Name "maybe_true" is not defined
57635763
@overload
57645764
def f3(x: B) -> B: ...
@@ -5771,13 +5771,13 @@ else:
57715771
def f3(x): ...
57725772
reveal_type(f3(A())) # N: Revealed type is "__main__.A"
57735773
reveal_type(f3(B())) # E: No overload variant of "f3" matches argument type "B" \
5774-
# N: Possible overload variant: \
5775-
# N: def f3(x: A) -> A \
5776-
# N: Revealed type is "Any"
5774+
# N: Possible overload variant: \
5775+
# N: def f3(x: A) -> A \
5776+
# N: Revealed type is "Any"
57775777

57785778
@overload # E: Single overload definition, multiple required
57795779
def f4(x: A) -> A: ...
5780-
if maybe_true: # E: Condition cannot be inferred, unable to merge overloads \
5780+
if maybe_true: # E: Condition can't be inferred, unable to merge overloads \
57815781
# E: Name "maybe_true" is not defined
57825782
@overload
57835783
def f4(x: B) -> B: ...
@@ -5787,9 +5787,10 @@ else:
57875787
def f4(x): ...
57885788
reveal_type(f4(A())) # N: Revealed type is "__main__.A"
57895789
reveal_type(f4(B())) # E: No overload variant of "f4" matches argument type "B" \
5790-
# N: Possible overload variant: \
5791-
# N: def f4(x: A) -> A \
5792-
# N: Revealed type is "Any"
5790+
# N: Possible overload variant: \
5791+
# N: def f4(x: A) -> A \
5792+
# N: Revealed type is "Any"
5793+
57935794

57945795
[case testOverloadIfElse3]
57955796
# flags: --always-false False
@@ -5817,18 +5818,18 @@ else:
58175818
def f1(x): ...
58185819
reveal_type(f1(A())) # N: Revealed type is "__main__.A"
58195820
reveal_type(f1(B())) # E: No overload variant of "f1" matches argument type "B" \
5820-
# N: Possible overload variants: \
5821-
# N: def f1(x: A) -> A \
5822-
# N: def f1(x: D) -> D \
5823-
# N: Revealed type is "Any"
5821+
# N: Possible overload variants: \
5822+
# N: def f1(x: A) -> A \
5823+
# N: def f1(x: D) -> D \
5824+
# N: Revealed type is "Any"
58245825
reveal_type(f1(D())) # N: Revealed type is "__main__.D"
58255826

58265827
@overload # E: Single overload definition, multiple required
58275828
def f2(x: A) -> A: ...
58285829
if False:
58295830
@overload
58305831
def f2(x: B) -> B: ...
5831-
elif maybe_true: # E: Condition cannot be inferred, unable to merge overloads \
5832+
elif maybe_true: # E: Condition can't be inferred, unable to merge overloads \
58325833
# E: Name "maybe_true" is not defined
58335834
@overload
58345835
def f2(x: C) -> C: ...
@@ -5838,13 +5839,13 @@ else:
58385839
def f2(x): ...
58395840
reveal_type(f2(A())) # N: Revealed type is "__main__.A"
58405841
reveal_type(f2(C())) # E: No overload variant of "f2" matches argument type "C" \
5841-
# N: Possible overload variant: \
5842-
# N: def f2(x: A) -> A \
5843-
# N: Revealed type is "Any"
5842+
# N: Possible overload variant: \
5843+
# N: def f2(x: A) -> A \
5844+
# N: Revealed type is "Any"
58445845

58455846
@overload # E: Single overload definition, multiple required
58465847
def f3(x: A) -> A: ...
5847-
if maybe_true: # E: Condition cannot be inferred, unable to merge overloads \
5848+
if maybe_true: # E: Condition can't be inferred, unable to merge overloads \
58485849
# E: Name "maybe_true" is not defined
58495850
@overload
58505851
def f3(x: B) -> B: ...
@@ -5857,14 +5858,14 @@ else:
58575858
def f3(x): ...
58585859
reveal_type(f3(A())) # N: Revealed type is "__main__.A"
58595860
reveal_type(f3(B())) # E: No overload variant of "f3" matches argument type "B" \
5860-
# N: Possible overload variant: \
5861-
# N: def f3(x: A) -> A \
5862-
# N: Revealed type is "Any"
5861+
# N: Possible overload variant: \
5862+
# N: def f3(x: A) -> A \
5863+
# N: Revealed type is "Any"
58635864

58645865
def g(bool_var: bool) -> None:
58655866
@overload
58665867
def f4(x: A) -> A: ...
5867-
if bool_var: # E: Condition cannot be inferred, unable to merge overloads
5868+
if bool_var: # E: Condition can't be inferred, unable to merge overloads
58685869
@overload
58695870
def f4(x: B) -> B: ...
58705871
elif maybe_true: # E: Name "maybe_true" is not defined
@@ -5880,10 +5881,11 @@ def g(bool_var: bool) -> None:
58805881
def f4(x): ...
58815882
reveal_type(f4(E())) # N: Revealed type is "__main__.E"
58825883
reveal_type(f4(B())) # E: No overload variant of "f4" matches argument type "B" \
5883-
# N: Possible overload variants: \
5884-
# N: def f4(x: A) -> A \
5885-
# N: def f4(x: E) -> E \
5886-
# N: Revealed type is "Any"
5884+
# N: Possible overload variants: \
5885+
# N: def f4(x: A) -> A \
5886+
# N: def f4(x: E) -> E \
5887+
# N: Revealed type is "Any"
5888+
58875889

58885890
[case testOverloadIfSkipUnknownExecution]
58895891
# flags: --always-true True
@@ -5901,14 +5903,14 @@ class D: ...
59015903

59025904
@overload # E: Single overload definition, multiple required
59035905
def f1(x: A) -> A: ...
5904-
if maybe_true: # E: Condition cannot be inferred, unable to merge overloads \
5906+
if maybe_true: # E: Condition can't be inferred, unable to merge overloads \
59055907
# E: Name "maybe_true" is not defined
59065908
@overload
59075909
def f1(x: B) -> B: ...
59085910
def f1(x): ...
59095911
reveal_type(f1(A())) # N: Revealed type is "__main__.A"
59105912

5911-
if maybe_true: # E: Condition cannot be inferred, unable to merge overloads \
5913+
if maybe_true: # E: Condition can't be inferred, unable to merge overloads \
59125914
# E: Name "maybe_true" is not defined
59135915
@overload
59145916
def f2(x: A) -> A: ...
@@ -5918,23 +5920,23 @@ def f2(x: B) -> B: ...
59185920
def f2(x: C) -> C: ...
59195921
def f2(x): ...
59205922
reveal_type(f2(A())) # E: No overload variant of "f2" matches argument type "A" \
5921-
# N: Possible overload variants: \
5922-
# N: def f2(x: B) -> B \
5923-
# N: def f2(x: C) -> C \
5924-
# N: Revealed type is "Any"
5923+
# N: Possible overload variants: \
5924+
# N: def f2(x: B) -> B \
5925+
# N: def f2(x: C) -> C \
5926+
# N: Revealed type is "Any"
59255927

59265928
if True:
59275929
@overload # E: Single overload definition, multiple required
59285930
def f3(x: A) -> A: ...
5929-
if maybe_true: # E: Condition cannot be inferred, unable to merge overloads \
5931+
if maybe_true: # E: Condition can't be inferred, unable to merge overloads \
59305932
# E: Name "maybe_true" is not defined
59315933
@overload
59325934
def f3(x: B) -> B: ...
59335935
def f3(x): ...
59345936
reveal_type(f3(A())) # N: Revealed type is "__main__.A"
59355937

59365938
if True:
5937-
if maybe_true: # E: Condition cannot be inferred, unable to merge overloads \
5939+
if maybe_true: # E: Condition can't be inferred, unable to merge overloads \
59385940
# E: Name "maybe_true" is not defined
59395941
@overload
59405942
def f4(x: A) -> A: ...
@@ -5944,10 +5946,10 @@ if True:
59445946
def f4(x: C) -> C: ...
59455947
def f4(x): ...
59465948
reveal_type(f4(A())) # E: No overload variant of "f4" matches argument type "A" \
5947-
# N: Possible overload variants: \
5948-
# N: def f4(x: B) -> B \
5949-
# N: def f4(x: C) -> C \
5950-
# N: Revealed type is "Any"
5949+
# N: Possible overload variants: \
5950+
# N: def f4(x: B) -> B \
5951+
# N: def f4(x: C) -> C \
5952+
# N: Revealed type is "Any"
59515953

59525954
[case testOverloadIfDontSkipUnrelatedOverload]
59535955
# flags: --always-true True
@@ -6187,16 +6189,16 @@ if False:
61876189
def f8(x): ...
61886190
reveal_type(f8(A())) # N: Revealed type is "__main__.A"
61896191
reveal_type(f8(C())) # E: No overload variant of "f8" matches argument type "C" \
6190-
# N: Possible overload variants: \
6191-
# N: def f8(x: A) -> A \
6192-
# N: def f8(x: B) -> B \
6193-
# N: Revealed type is "Any"
6192+
# N: Possible overload variants: \
6193+
# N: def f8(x: A) -> A \
6194+
# N: def f8(x: B) -> B \
6195+
# N: Revealed type is "Any"
61946196

6195-
if maybe_true: # E: Condition cannot be inferred, unable to merge overloads \
6197+
if maybe_true: # E: Condition can't be inferred, unable to merge overloads \
61966198
# E: Name "maybe_true" is not defined
61976199
@overload
61986200
def f9(x: A) -> A: ...
6199-
if another_maybe_true: # E: Condition cannot be inferred, unable to merge overloads \
6201+
if another_maybe_true: # E: Condition can't be inferred, unable to merge overloads \
62006202
# E: Name "another_maybe_true" is not defined
62016203
@overload
62026204
def f9(x: B) -> B: ...
@@ -6206,18 +6208,18 @@ def f9(x: C) -> C: ...
62066208
def f9(x: D) -> D: ...
62076209
def f9(x): ...
62086210
reveal_type(f9(A())) # E: No overload variant of "f9" matches argument type "A" \
6209-
# N: Possible overload variants: \
6210-
# N: def f9(x: C) -> C \
6211-
# N: def f9(x: D) -> D \
6212-
# N: Revealed type is "Any"
6211+
# N: Possible overload variants: \
6212+
# N: def f9(x: C) -> C \
6213+
# N: def f9(x: D) -> D \
6214+
# N: Revealed type is "Any"
62136215
reveal_type(f9(C())) # N: Revealed type is "__main__.C"
62146216

62156217
if True:
6216-
if maybe_true: # E: Condition cannot be inferred, unable to merge overloads \
6218+
if maybe_true: # E: Condition can't be inferred, unable to merge overloads \
62176219
# E: Name "maybe_true" is not defined
62186220
@overload
62196221
def f10(x: A) -> A: ...
6220-
if another_maybe_true: # E: Condition cannot be inferred, unable to merge overloads \
6222+
if another_maybe_true: # E: Condition can't be inferred, unable to merge overloads \
62216223
# E: Name "another_maybe_true" is not defined
62226224
@overload
62236225
def f10(x: B) -> B: ...
@@ -6227,10 +6229,10 @@ if True:
62276229
def f10(x: D) -> D: ...
62286230
def f10(x): ...
62296231
reveal_type(f10(A())) # E: No overload variant of "f10" matches argument type "A" \
6230-
# N: Possible overload variants: \
6231-
# N: def f10(x: C) -> C \
6232-
# N: def f10(x: D) -> D \
6233-
# N: Revealed type is "Any"
6232+
# N: Possible overload variants: \
6233+
# N: def f10(x: C) -> C \
6234+
# N: def f10(x: D) -> D \
6235+
# N: Revealed type is "Any"
62346236
reveal_type(f10(C())) # N: Revealed type is "__main__.C"
62356237

62366238
if some_var: # E: Name "some_var" is not defined
@@ -6251,6 +6253,7 @@ if True:
62516253
def f12(x: B) -> B: ...
62526254
def f12(x): ...
62536255
reveal_type(f12(A())) # N: Revealed type is "__main__.A"
6256+
62546257
[typing fixtures/typing-medium.pyi]
62556258

62566259
[case testOverloadIfUnconditionalFuncDef]
@@ -6406,7 +6409,7 @@ def f1(g: A) -> A: ...
64066409
if True:
64076410
@overload # E: Single overload definition, multiple required
64086411
def f1(g: B) -> B: ...
6409-
if maybe_true: # E: Condition cannot be inferred, unable to merge overloads \
6412+
if maybe_true: # E: Condition can't be inferred, unable to merge overloads \
64106413
# E: Name "maybe_true" is not defined
64116414
@overload
64126415
def f1(g: C) -> C: ...
@@ -6432,7 +6435,7 @@ if True:
64326435
def f3(g: B) -> B: ...
64336436
if True:
64346437
pass # Some other node
6435-
@overload # E: Name "f3" already defined on line 32 \
6438+
@overload # E: Name "f3" already defined on line 32 \
64366439
# E: An overloaded function outside a stub file must have an implementation
64376440
def f3(g: C) -> C: ...
64386441
@overload

test-data/unit/check-recursive-types.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ def local() -> None:
409409
x: L
410410
reveal_type(x) # N: Revealed type is "builtins.list[Union[builtins.int, Any]]"
411411

412-
S = Type[S] # E: Type[...] cannot contain another Type[...]
413-
U = Type[Union[int, U]] # E: Type[...] cannot contain another Type[...]
412+
S = Type[S] # E: Type[...] can't contain another Type[...]
413+
U = Type[Union[int, U]] # E: Type[...] can't contain another Type[...]
414414
x: U
415415
reveal_type(x) # N: Revealed type is "Type[Any]"
416416

0 commit comments

Comments
 (0)