-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List possible overload variants when none match #5296
Changes from 2 commits
3ebeee4
67d8e7d
c363f62
2f73a18
83f0275
873521b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -749,7 +749,10 @@ def deleted_as_lvalue(self, typ: DeletedType, context: Context) -> None: | |
s = " '{}'".format(typ.source) | ||
self.fail('Assignment to variable{} outside except: block'.format(s), context) | ||
|
||
def no_variant_matches_arguments(self, overload: Overloaded, arg_types: List[Type], | ||
def no_variant_matches_arguments(self, | ||
plausible_targets: List[CallableType], | ||
overload: Overloaded, | ||
arg_types: List[Type], | ||
context: Context) -> None: | ||
name = callable_name(overload) | ||
if name: | ||
|
@@ -768,6 +771,13 @@ def no_variant_matches_arguments(self, overload: Overloaded, arg_types: List[Typ | |
self.fail('No overload variant{} matches argument types {}' | ||
.format(name_str, arg_types_str), context) | ||
|
||
self.note('Possible overload variant(s):', context) | ||
self.pretty_overload(plausible_targets, | ||
overload, | ||
context, | ||
offset=2, | ||
max_items=2) | ||
|
||
def wrong_number_values_to_unpack(self, provided: int, expected: int, | ||
context: Context) -> None: | ||
if provided < expected: | ||
|
@@ -1207,13 +1217,13 @@ def report_protocol_problems(self, subtype: Union[Instance, TupleType, TypedDict | |
self.note(self.pretty_callable(exp), context, offset=2 * OFFSET) | ||
else: | ||
assert isinstance(exp, Overloaded) | ||
self.pretty_overload(exp, context, OFFSET, MAX_ITEMS) | ||
self.pretty_overload(exp.items(), exp, context, OFFSET, MAX_ITEMS) | ||
self.note('Got:', context, offset=OFFSET) | ||
if isinstance(got, CallableType): | ||
self.note(self.pretty_callable(got), context, offset=2 * OFFSET) | ||
else: | ||
assert isinstance(got, Overloaded) | ||
self.pretty_overload(got, context, OFFSET, MAX_ITEMS) | ||
self.pretty_overload(got.items(), got, context, OFFSET, MAX_ITEMS) | ||
self.print_more(conflict_types, context, OFFSET, MAX_ITEMS) | ||
|
||
# Report flag conflicts (i.e. settable vs read-only etc.) | ||
|
@@ -1233,13 +1243,17 @@ def report_protocol_problems(self, subtype: Union[Instance, TupleType, TypedDict | |
.format(supertype.type.name(), name), context) | ||
self.print_more(conflict_flags, context, OFFSET, MAX_ITEMS) | ||
|
||
def pretty_overload(self, tp: Overloaded, context: Context, | ||
def pretty_overload(self, targets: List[CallableType], func: Overloaded, context: Context, | ||
offset: int, max_items: int) -> None: | ||
for item in tp.items()[:max_items]: | ||
if len(targets) == 0: | ||
targets = func.items() | ||
for item in targets[:max_items]: | ||
self.note('@overload', context, offset=2 * offset) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The extra line with |
||
self.note(self.pretty_callable(item), context, offset=2 * offset) | ||
if len(tp.items()) > max_items: | ||
self.note('<{} more overload(s) not shown>'.format(len(tp.items()) - max_items), | ||
shown = min(max_items, len(targets)) | ||
max_available = len(func.items()) | ||
if shown < max_available: | ||
self.note('<{} more overload(s) not shown>'.format(max_available - shown), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apart form the uglines around plurals, it seems there are two possible reasons why not all overloads are shown:
I think it would be good to differentiate between these in the messages somehow. |
||
context, offset=2 * offset) | ||
|
||
def print_more(self, conflicts: Sequence[Any], context: Context, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not targets:
would be more idiomatic.