|
36 | 36 | ) |
37 | 37 | from mypy.literals import literal |
38 | 38 | from mypy import nodes |
| 39 | +from mypy import operators |
39 | 40 | import mypy.checker |
40 | 41 | from mypy import types |
41 | 42 | from mypy.sametypes import is_same_type |
@@ -2169,7 +2170,7 @@ def visit_op_expr(self, e: OpExpr) -> Type: |
2169 | 2170 | if right_radd_method is None: |
2170 | 2171 | return self.concat_tuples(proper_left_type, proper_right_type) |
2171 | 2172 |
|
2172 | | - if e.op in nodes.op_methods: |
| 2173 | + if e.op in operators.op_methods: |
2173 | 2174 | method = self.get_operator_method(e.op) |
2174 | 2175 | result, method_type = self.check_op(method, left_type, e.right, e, |
2175 | 2176 | allow_reverse=True) |
@@ -2234,7 +2235,7 @@ def visit_comparison_expr(self, e: ComparisonExpr) -> Type: |
2234 | 2235 | self.msg.dangerous_comparison(left_type, cont_type, 'container', e) |
2235 | 2236 | else: |
2236 | 2237 | self.msg.add_errors(local_errors) |
2237 | | - elif operator in nodes.op_methods: |
| 2238 | + elif operator in operators.op_methods: |
2238 | 2239 | method = self.get_operator_method(operator) |
2239 | 2240 | err_count = self.msg.errors.total_errors() |
2240 | 2241 | sub_result, method_type = self.check_op(method, left_type, right, e, |
@@ -2362,7 +2363,7 @@ def get_operator_method(self, op: str) -> str: |
2362 | 2363 | # TODO also check for "from __future__ import division" |
2363 | 2364 | return '__div__' |
2364 | 2365 | else: |
2365 | | - return nodes.op_methods[op] |
| 2366 | + return operators.op_methods[op] |
2366 | 2367 |
|
2367 | 2368 | def check_method_call_by_name(self, |
2368 | 2369 | method: str, |
@@ -2537,7 +2538,7 @@ def lookup_definer(typ: Instance, attr_name: str) -> Optional[str]: |
2537 | 2538 | # which records tuples containing the method, base type, and the argument. |
2538 | 2539 |
|
2539 | 2540 | bias_right = is_proper_subtype(right_type, left_type) |
2540 | | - if op_name in nodes.op_methods_that_shortcut and is_same_type(left_type, right_type): |
| 2541 | + if op_name in operators.op_methods_that_shortcut and is_same_type(left_type, right_type): |
2541 | 2542 | # When we do "A() + A()", for example, Python will only call the __add__ method, |
2542 | 2543 | # never the __radd__ method. |
2543 | 2544 | # |
@@ -2575,8 +2576,8 @@ def lookup_definer(typ: Instance, attr_name: str) -> Optional[str]: |
2575 | 2576 | # When running Python 2, we might also try calling the __cmp__ method. |
2576 | 2577 |
|
2577 | 2578 | is_python_2 = self.chk.options.python_version[0] == 2 |
2578 | | - if is_python_2 and op_name in nodes.ops_falling_back_to_cmp: |
2579 | | - cmp_method = nodes.comparison_fallback_method |
| 2579 | + if is_python_2 and op_name in operators.ops_falling_back_to_cmp: |
| 2580 | + cmp_method = operators.comparison_fallback_method |
2580 | 2581 | left_cmp_op = lookup_operator(cmp_method, left_type) |
2581 | 2582 | right_cmp_op = lookup_operator(cmp_method, right_type) |
2582 | 2583 |
|
@@ -2760,7 +2761,7 @@ def get_reverse_op_method(self, method: str) -> str: |
2760 | 2761 | if method == '__div__' and self.chk.options.python_version[0] == 2: |
2761 | 2762 | return '__rdiv__' |
2762 | 2763 | else: |
2763 | | - return nodes.reverse_op_methods[method] |
| 2764 | + return operators.reverse_op_methods[method] |
2764 | 2765 |
|
2765 | 2766 | def check_boolean_op(self, e: OpExpr, context: Context) -> Type: |
2766 | 2767 | """Type check a boolean operation ('and' or 'or').""" |
@@ -2867,7 +2868,7 @@ def visit_unary_expr(self, e: UnaryExpr) -> Type: |
2867 | 2868 | if op == 'not': |
2868 | 2869 | result = self.bool_type() # type: Type |
2869 | 2870 | else: |
2870 | | - method = nodes.unary_op_methods[op] |
| 2871 | + method = operators.unary_op_methods[op] |
2871 | 2872 | result, method_type = self.check_method_call_by_name(method, operand_type, [], [], e) |
2872 | 2873 | e.method_type = method_type |
2873 | 2874 | return result |
@@ -4533,9 +4534,9 @@ def is_operator_method(fullname: Optional[str]) -> bool: |
4533 | 4534 | return False |
4534 | 4535 | short_name = fullname.split('.')[-1] |
4535 | 4536 | return ( |
4536 | | - short_name in nodes.op_methods.values() or |
4537 | | - short_name in nodes.reverse_op_methods.values() or |
4538 | | - short_name in nodes.unary_op_methods.values()) |
| 4537 | + short_name in operators.op_methods.values() or |
| 4538 | + short_name in operators.reverse_op_methods.values() or |
| 4539 | + short_name in operators.unary_op_methods.values()) |
4539 | 4540 |
|
4540 | 4541 |
|
4541 | 4542 | def get_partial_instance_type(t: Optional[Type]) -> Optional[PartialType]: |
|
0 commit comments