Skip to content

Commit 48c1e9b

Browse files
authored
Fix some notes not being ignored when using an error code (python#7573)
Either change the error code to match the related error, so that both will always be ignored at the same time, or switch a note to an error (in case the relevant error code is hard to predict). Fixes python#7562.
1 parent df62842 commit 48c1e9b

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

mypy/checkexpr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,8 +1472,8 @@ def check_overload_call(self,
14721472
callable_name=callable_name,
14731473
object_type=object_type)
14741474
if union_interrupted:
1475-
self.chk.msg.note("Not all union combinations were tried"
1476-
" because there are too many unions", context)
1475+
self.chk.fail("Not all union combinations were tried"
1476+
" because there are too many unions", context)
14771477
return result
14781478

14791479
def plausible_overload_call_targets(self,

mypy/messages.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ def unexpected_keyword_argument(self, callee: CallableType, name: str,
575575
if not fname: # an alias to function with a different name
576576
fname = 'Called function'
577577
self.note('{} defined here'.format(fname), callee.definition,
578-
file=module.path, origin=context)
578+
file=module.path, origin=context, code=codes.CALL_ARG)
579579

580580
def duplicate_argument_value(self, callee: CallableType, index: int,
581581
context: Context) -> None:
@@ -926,10 +926,11 @@ def overloaded_signatures_ret_specific(self, index: int, context: Context) -> No
926926
'of signature {}'.format(index), context)
927927

928928
def warn_both_operands_are_from_unions(self, context: Context) -> None:
929-
self.note('Both left and right operands are unions', context)
929+
self.note('Both left and right operands are unions', context, code=codes.OPERATOR)
930930

931931
def warn_operand_was_from_union(self, side: str, original: Type, context: Context) -> None:
932-
self.note('{} operand is of type {}'.format(side, format_type(original)), context)
932+
self.note('{} operand is of type {}'.format(side, format_type(original)), context,
933+
code=codes.OPERATOR)
933934

934935
def operator_method_signatures_overlap(
935936
self, reverse_class: TypeInfo, reverse_method: str, forward_class: Type,

test-data/unit/check-errorcodes.test

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Tests for error codes
1+
-- Tests for error codes and ignoring errors using error codes
22
--
33
-- These implicitly use --show-error-codes.
44

@@ -657,6 +657,29 @@ def g(self: A) -> None: pass
657657

658658
A.f = g # E: Cannot assign to a method [assignment]
659659

660+
[case testErrorCodeDefinedHereNoteIgnore]
661+
import m
662+
m.f(kw=1) # type: ignore[call-arg]
663+
[file m.py]
664+
def f() -> None: pass
665+
666+
[case testErrorCodeUnionNoteIgnore]
667+
from typing import Union
668+
669+
class Foo:
670+
def __add__(self, x: Foo) -> Foo: pass
671+
def __radd__(self, x: Foo) -> Foo: pass
672+
673+
class Bar:
674+
def __add__(self, x: Bar) -> Bar: pass
675+
def __radd__(self, x: Bar) -> Bar: pass
676+
677+
a: Union[Foo, Bar]
678+
679+
a + a # type: ignore[operator]
680+
a + Foo() # type: ignore[operator]
681+
Foo() + a # type: ignore[operator]
682+
660683
[case testErrorCodeTypeIgnoreMisspelled1]
661684
x = y # type: ignored[foo]
662685
xx = y # type: ignored [foo]

test-data/unit/check-overloading.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4563,7 +4563,7 @@ def f(*args):
45634563
x: Union[int, str]
45644564
f(x, x, x, x, x, x, x, x)
45654565
[out]
4566-
main:11: note: Not all union combinations were tried because there are too many unions
4566+
main:11: error: Not all union combinations were tried because there are too many unions
45674567
main:11: error: Argument 1 to "f" has incompatible type "Union[int, str]"; expected "int"
45684568
main:11: error: Argument 2 to "f" has incompatible type "Union[int, str]"; expected "int"
45694569
main:11: error: Argument 3 to "f" has incompatible type "Union[int, str]"; expected "int"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy