Skip to content

Commit

Permalink
Don't error on help for keyword functions (#29308)
Browse files Browse the repository at this point in the history
Fixes #23991.

Also allows for help where some arguments are undefined.
  • Loading branch information
simonbyrne authored and JeffBezanson committed Oct 1, 2018
1 parent 29b780e commit a2df80e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
52 changes: 50 additions & 2 deletions stdlib/REPL/src/docview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,56 @@ repl(io::IO, other) = esc(:(@doc $other))
repl(x) = repl(stdout, x)

function _repl(x)
if (isexpr(x, :call) && !any(isexpr(x, :(::)) for x in x.args))
x.args[2:end] = [:(::typeof($arg)) for arg in x.args[2:end]]
if isexpr(x, :call)
# determine the types of the values
kwargs = nothing
pargs = Any[]
for arg in x.args[2:end]
if isexpr(arg, :parameters)
kwargs = map(arg.args) do kwarg
if kwarg isa Symbol
kwarg = :($kwarg::Any)
elseif isexpr(kwarg, :kw)
lhs = kwarg.args[1]
rhs = kwarg.args[2]
if lhs isa Symbol
if rhs isa Symbol
kwarg.args[1] = :($lhs::(@isdefined($rhs) ? typeof($rhs) : Any))
else
kwarg.args[1] = :($lhs::typeof($rhs))
end
end
end
kwarg
end
elseif isexpr(arg, :kw)
if kwargs == nothing
kwargs = Any[]
end
lhs = arg.args[1]
rhs = arg.args[2]
if lhs isa Symbol
if rhs isa Symbol
arg.args[1] = :($lhs::(@isdefined($rhs) ? typeof($rhs) : Any))
else
arg.args[1] = :($lhs::typeof($rhs))
end
end
push!(kwargs, arg)
else
if arg isa Symbol
arg = :($arg::(@isdefined($arg) ? typeof($arg) : Any))
elseif !isexpr(arg, :(::))
arg = :(::typeof($arg))
end
push!(pargs, arg)
end
end
if kwargs == nothing
x.args = Any[x.args[1], pargs...]
else
x.args = Any[x.args[1], Expr(:parameters, kwargs...), pargs...]
end
end
#docs = lookup_doc(x) # TODO
docs = esc(:(@doc $x))
Expand Down
14 changes: 14 additions & 0 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,20 @@ let dt2 = _repl(:(dynamic_test(::String)))
@test dt2.args[1].args[1] == Symbol("@doc")
@test dt2.args[1].args[3] == :(dynamic_test(::String))
end
let dt3 = _repl(:(dynamic_test(a)))
@test dt3 isa Expr
@test dt3.args[1] isa Expr
@test dt3.args[1].head === :macrocall
@test dt3.args[1].args[1] == Symbol("@doc")
@test dt3.args[1].args[3].args[2].head == :(::) # can't test equality due to line numbers
end
let dt4 = _repl(:(dynamic_test(1.0,u=2.0)))
@test dt4 isa Expr
@test dt4.args[1] isa Expr
@test dt4.args[1].head === :macrocall
@test dt4.args[1].args[1] == Symbol("@doc")
@test dt4.args[1].args[3] == :(dynamic_test(::typeof(1.0); u::typeof(2.0)=2.0))
end

# Equality testing

Expand Down

2 comments on commit a2df80e

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.