-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Keyword display improvements #16669
Keyword display improvements #16669
Conversation
@dhoegh can you post the new error message for that case? |
A big +1 to progress with this. In the method lists, I wonder if we should display the default kwarg value too? Seems like that's usually the next question once I know there is a keyword argument involved. Also probably want to track the updates in #16580 with how keyword arguments will be handled internally. |
I have updated the example. |
@@ -123,6 +123,16 @@ function showerror(io::IO, ex::MethodError) | |||
ft = typeof(f) | |||
name = ft.name.mt.name | |||
f_is_function = false | |||
kwargs = Dict{Any,Any}() |
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.
i think you meant Array{Any}(0)
here?
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.
Yes, thank you. I have corrected it.
1091f8a
to
e808e07
Compare
Great! Though for consistency with positional arguments, the value of keyword arguments shouldn't be printed on ERROR: MethodError: no method matching addConstraint(::FooCon; uncset=nothing) would rather be: ERROR: MethodError: no method matching addConstraint(::FooCon; uncset::Void) Also, maybe "unsupported" would be better than "unrecognized". |
@nalimilan why would it be Void? Surely its Any? |
@IainNZ AFAIK the displayed type is that of the passed argument, not the one in the signature (indeed, that argument doesn't even exist for that method, so it doesn't have a type). |
That... doesn't make any sense then, right? Doesn't seem like something to perpetuate |
@@ -150,6 +160,13 @@ function showerror(io::IO, ex::MethodError) | |||
print(io, "::$typ") | |||
i == length(arg_types_param) || print(io, ", ") | |||
end | |||
if 0 < length(kwargs) |
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.
use isempty instead of comparing length to 0
069b03c
to
673826b
Compare
I have addressed the comment from tkelman and changed "unrecognized" to "unsupported" based on nalimilan comment. Regarding display of default values, that seem to require more than a trivial amount of look through the AST of the |
Bump, any further comments or thoughts. |
if !isempty(kwargs) | ||
print(io, "; ") | ||
for (i ,(k, v)) in enumerate(kwargs) | ||
print(io, k, "=", v) |
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.
use show(IOContext(io, :limit => true), v)
, not print(io, v)
for v
(also the \space,
are in the wrong order on the previous line)
sorry this took so long to review. I've been coming back to this every few days trying to make sure I was understanding how everything would interact. Can I ask you to add a test for the behavior with multiple kwargs (multiple matching, multiple not matching)? |
Given that this is a display change, which tends to be less likely to break people's code, can't we merge this and then patch it up? |
c353489
to
f49fcb9
Compare
…method in show_method_candidates with a text stating the not matching keyword. Fix JuliaLang#15639
I have fixed the trivial comments and added test for multiple kwargs matching and multiple not matching at line https://github.com/dhoegh/julia/blob/d4e8792075735c9a71e52f3ddad62cb96bf589ad/test/replutil.jl#L112-L115. I have squashed the commit where the review comments was addressed away. My time is very limited right now, so my response time the next couple of weeks could be long. |
Thanks. This is great. |
This PR implements several improvement to how keywords is presented to the user. The additions in each commit is listed bellow
kwargs...
. This change causes the vararg keywords to be displayed in method list and other places.kwerr
throw a MethodError. This allows for display of other method candidates, handled by the fourth commit.Example from #15639:
Note to reviewer please check if the changes in
src/julia-syntax.scm
is correct as this is my first encounter with lisp.