Skip to content

Commit

Permalink
Remove reference to deprecated kwftype
Browse files Browse the repository at this point in the history
  • Loading branch information
Liozou committed Jan 29, 2023
1 parent 6a1bfbf commit 14006a4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
16 changes: 8 additions & 8 deletions base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ function sym_to_string(sym)
end


function kwsortermethod_kwargs(m::Method)
function kwargnames(m::Method)
m.name === :kwcall || return kwarg_decl(m)
kwargs = Symbol[]
for x in Iterators.drop(eachsplit(m.slot_syms, '\0'), m.nargs)
if !isempty(x) && !occursin('#', x)
push!(kwargs, Symbol(x))
end
end
return kwargs
println('\n', m, '\n', collect(Iterators.drop(eachsplit(m.slot_syms, '\0'), m.nargs)), '\n')
end

# type for pretty-printing methods corresponding to the same definition site with different
Expand All @@ -219,8 +219,8 @@ struct FactoredMethod
m::Vector{Method} # the different methods, by order of increasing nargs
kwargs::Vector{Symbol}
end
function FactoredMethod(m::Method, kwsortermethod)
FactoredMethod([m], kwsortermethod ? kwsortermethod_kwargs(m) : kwarg_decl(m))
function FactoredMethod(m::Method)
FactoredMethod([m], kwargnames(m))
end

struct FactoredMethodList
Expand All @@ -229,10 +229,10 @@ struct FactoredMethodList
ms::MethodList
end

function FactoredMethodList(ms::MethodList, kwsortermethod=false)
function FactoredMethodList(ms::MethodList)
isempty(ms) && return FactoredMethodList(FactoredMethod[], Vector{Int}[], ms)
I = sortperm(ms.ms; by=m->(m.line, m.file, m.nargs))
list = FactoredMethod[FactoredMethod(ms[I[1]], kwsortermethod)]
list = FactoredMethod[FactoredMethod(ms[I[1]])]
positions = Vector{Int}[[I[1]]]
for _i in 2:length(ms)
i = I[_i]
Expand All @@ -256,12 +256,12 @@ function FactoredMethodList(ms::MethodList, kwsortermethod=false)
newmethod = false
push!(last(list).m, m)
# we assert that only one of the methods has kwargs, if any
append!(last(list).kwargs, kwsortermethod ? kwsortermethod_kwargs(m) : kwarg_decl(m))
append!(last(list).kwargs, kwargnames(m))
push!(last(positions), i)
end
end
if newmethod
push!(list, FactoredMethod(m, kwsortermethod))
push!(list, FactoredMethod(m))
push!(positions, [i])
end
end
Expand Down
15 changes: 4 additions & 11 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -651,13 +651,6 @@ function complete_methods_args(ex::Expr, context_module::Module, default_any::Bo
return detect_args_kwargs(ex.args, context_module, default_any, false)
end

function iskwsortermethod(@nospecialize(funct), args_ex::Vector{Any})
length(args_ex) < 2 && return false
args_ex[1] === Any || return false
funct == try; Core.kwftype(args_ex[2]); catch ex; ex isa ErrorException || rethrow(); return false; end || return false
true
end

function complete_methods!(out::Vector{Completion}, @nospecialize(funct), args_ex::Vector{Any}, kwargs_ex::Set{Symbol}, max_method_completions::Int, kwargs_flag::Int)
# Input types and number of arguments
varargs_position = findall(Base.isvarargtype, args_ex)
Expand All @@ -683,11 +676,11 @@ function complete_methods!(out::Vector{Completion}, @nospecialize(funct), args_e
isempty(m) && return
first_m = (m[1]::Core.MethodMatch).method
if first_m.sig === Tuple # Builtin
push!(out, MethodCompletion(Any[t_in], Base.FactoredMethod(first_m, false)))
push!(out, MethodCompletion(Any[t_in], Base.FactoredMethod(first_m)))
return
end
ml = Base.MethodList([(match::Core.MethodMatch).method for match in m], Base.get_methodtable(first_m))
fml = Base.FactoredMethodList(ml, iskwsortermethod(funct, args_ex))
fml = Base.FactoredMethodList(ml)
for (fm, pos) in zip(fml.list, fml.positions)
if kwargs_flag == 1
# If there is a semicolon, the number of non-keyword arguments in the
Expand Down Expand Up @@ -869,13 +862,13 @@ function complete_keyword_argument(partial, last_idx, context_module)
kwargs_flag == 2 && return fail # one of the previous kwargs is invalid

# get the list of possible kw method table
kwt = try; Core.kwftype(funct); catch ex; ex isa ErrorException || rethrow(); return fail; end
kwt = typeof(Core.kwcall)
_completions = Completion[]
complete_methods!(_completions, kwt, Any[Any, funct, args_ex...], kwargs_ex, MAX_METHOD_COMPLETIONS, kwargs_flag)
isempty(_completions) && return fail

factoredmethods = if first(_completions) isa TextCompletion
Base.FactoredMethodList(Base.MethodList(kwt.name.mt), true).list
Base.FactoredMethodList(Base.MethodList(kwt.name.mt)).list
else
Base.FactoredMethod[(m::MethodCompletion).method for m in _completions]
end
Expand Down
5 changes: 3 additions & 2 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2607,11 +2607,12 @@ end
@test occursin("(a, [b])", repr)
@test occursin("(x, y::Integer)", repr)
end
f44434_3(a, b::Integer=5) = pass
# use @eval to avoid a warning about method definition overwritten
@eval f44434_3(a, b::Integer=5) = pass
let repr = sprint(show, "text/plain", methods(f44434_3))
@test occursin("(a, [b::Integer])", repr)
end
f44434_3(x, y::Integer) = pass
@eval f44434_3(x, y::Integer) = pass
let repr = sprint(show, "text/plain", methods(f44434_3))
@test !occursin("(a, [b::Integer])", repr)
@test occursin("(a)", repr)
Expand Down

0 comments on commit 14006a4

Please sign in to comment.