Created
February 17, 2018 00:36
-
-
Save gvanrossum/9056228850772e1873d3cf58736df145 to your computer and use it in GitHub Desktop.
Possible band-aid fix for https://github.com/python/mypy/issues/4581
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/mypy/checker.py b/mypy/checker.py | |
index 7b0180f79..488ae825f 100644 | |
--- a/mypy/checker.py | |
+++ b/mypy/checker.py | |
@@ -991,9 +991,11 @@ class TypeChecker(NodeVisitor[None], CheckerPluginInterface): | |
if is_unsafe_overlapping_signatures(forward_tweaked, | |
reverse_tweaked): | |
+ rev_name = reverse_class.name() if reverse_class is not None else None | |
+ fwd_name = forward_base.type.name() if forward_base and hasattr(forward_base, 'type ') and forward_base.type else None | |
self.msg.operator_method_signatures_overlap( | |
- reverse_class.name(), reverse_name, | |
- forward_base.type.name(), forward_name, context) | |
+ rev_name, reverse_name, | |
+ fwd_name, forward_name, context) | |
elif isinstance(forward_item, Overloaded): | |
for item in forward_item.items(): | |
self.check_overlapping_op_methods( | |
diff --git a/mypy/messages.py b/mypy/messages.py | |
index 3edc1fee9..57ae30082 100644 | |
--- a/mypy/messages.py | |
+++ b/mypy/messages.py | |
@@ -934,10 +934,12 @@ class MessageBuilder: | |
def operator_method_signatures_overlap( | |
self, reverse_class: str, reverse_method: str, forward_class: str, | |
forward_method: str, context: Context) -> None: | |
- self.fail('Signatures of "{}" of "{}" and "{}" of "{}" ' | |
+ rev_class_msg = ' of "{}"'.format(reverse_class) if reverse_class else "" | |
+ fwd_class_msg = ' of "{}"'.format(forward_class) if forward_class else "" | |
+ self.fail('Signatures of "{}"{} and "{}"{} ' | |
'are unsafely overlapping'.format( | |
- reverse_method, reverse_class, | |
- forward_method, forward_class), | |
+ reverse_method, rev_class_msg, | |
+ forward_method, fwd_class_msg), | |
context) | |
def forward_operator_not_callable( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment