From 23795c53f05ab11ab67c2ab0544f7a6ae800a48b Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Thu, 4 Nov 2021 00:39:58 +0300 Subject: [PATCH 1/2] Changes how errors are disabled in `visit_comparison_expr` It now has a better API for that. --- mypy/checkexpr.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index b6dec2834449..f8e83748d90e 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -2231,9 +2231,15 @@ def visit_comparison_expr(self, e: ComparisonExpr) -> Type: # Keep track of whether we get type check errors (these won't be reported, they # are just to verify whether something is valid typing wise). local_errors = self.msg.copy() - local_errors.disable_count = 0 - _, method_type = self.check_method_call_by_name( - '__contains__', right_type, [left], [ARG_POS], e, local_errors) + with local_errors.disable_errors(): + _, method_type = self.check_method_call_by_name( + method='__contains__', + base_type=right_type, + args=[left], + arg_kinds=[ARG_POS], + context=e, + local_errors=local_errors, + ) sub_result = self.bool_type() # Container item type for strict type overlap checks. Note: we need to only # check for nominal type, because a usual "Unsupported operands for in" From 9b9524c57dec927fe3dec5f4433c374310815323 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 4 Nov 2021 00:47:16 +0300 Subject: [PATCH 2/2] Change `copy()` -> `clean_copy()` --- mypy/checkexpr.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index f8e83748d90e..623776f8e48e 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -2230,16 +2230,15 @@ def visit_comparison_expr(self, e: ComparisonExpr) -> Type: # Keep track of whether we get type check errors (these won't be reported, they # are just to verify whether something is valid typing wise). - local_errors = self.msg.copy() - with local_errors.disable_errors(): - _, method_type = self.check_method_call_by_name( - method='__contains__', - base_type=right_type, - args=[left], - arg_kinds=[ARG_POS], - context=e, - local_errors=local_errors, - ) + local_errors = self.msg.clean_copy() + _, method_type = self.check_method_call_by_name( + method='__contains__', + base_type=right_type, + args=[left], + arg_kinds=[ARG_POS], + context=e, + local_errors=local_errors, + ) sub_result = self.bool_type() # Container item type for strict type overlap checks. Note: we need to only # check for nominal type, because a usual "Unsupported operands for in"