-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add prefer_literal option to overload API #6058
Changes from 7 commits
228cff5
d875e12
e811f41
49551fd
9b8bbc0
7d9286f
6a4fe0f
89a3840
efaa1a7
50d3df6
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 |
---|---|---|
|
@@ -375,33 +375,44 @@ def get_call_type(self, context, args, kws): | |
template = self.template(context) | ||
literal_e = None | ||
nonliteral_e = None | ||
out = None | ||
|
||
|
||
# Try with Literal | ||
try: | ||
out = template.apply(args, kws) | ||
except Exception as exc: | ||
if isinstance(exc, errors.ForceLiteralArg): | ||
raise exc | ||
literal_e = exc | ||
out = None | ||
|
||
# if the unliteral_args and unliteral_kws are the same as the literal | ||
# ones, set up to not bother retrying | ||
unliteral_args = tuple([unliteral(a) for a in args]) | ||
unliteral_kws = {k: unliteral(v) for k, v in kws.items()} | ||
skip = unliteral_args == args and kws == unliteral_kws | ||
|
||
# If the above template application failed and the non-literal args are | ||
# different to the literal ones, try again with literals rewritten as | ||
# non-literals | ||
if not skip and out is None: | ||
try: | ||
out = template.apply(unliteral_args, unliteral_kws) | ||
except Exception as exc: | ||
if isinstance(exc, errors.ForceLiteralArg): | ||
raise exc | ||
nonliteral_e = exc | ||
choice = [True, False] if template.prefer_literal else [False, True] | ||
for uselit in choice: | ||
if uselit: | ||
# Try with Literal | ||
try: | ||
out = template.apply(args, kws) | ||
except Exception as exc: | ||
if isinstance(exc, errors.ForceLiteralArg): | ||
raise exc | ||
literal_e = exc | ||
out = None | ||
else: | ||
break | ||
else: | ||
# if the unliteral_args and unliteral_kws are the same as the literal | ||
# ones, set up to not bother retrying | ||
unliteral_args = tuple([unliteral(a) for a in args]) | ||
unliteral_kws = {k: unliteral(v) for k, v in kws.items()} | ||
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.
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. good pt 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. done in efaa1a7 |
||
skip = unliteral_args == args and kws == unliteral_kws | ||
|
||
# If the above template application failed and the non-literal args are | ||
# different to the literal ones, try again with literals rewritten as | ||
# non-literals | ||
if not skip and out is None: | ||
try: | ||
out = template.apply(unliteral_args, unliteral_kws) | ||
except Exception as exc: | ||
if isinstance(exc, errors.ForceLiteralArg): | ||
if template.prefer_literal: | ||
# For template that prefers literal types, | ||
# reaching here means that the literal types | ||
# have failed typing as well. | ||
raise exc | ||
nonliteral_e = exc | ||
else: | ||
break | ||
|
||
if out is None and (nonliteral_e is not None or literal_e is not None): | ||
header = "- Resolution failure for {} arguments:\n{}\n" | ||
|
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.
should this be documented? OR given the likelihood of it becoming a namedtuple or something for the next release, leave it?
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.
Actually, i should document it and leave a note that it might change.
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.
done in 89a3840