@@ -452,24 +452,28 @@ kws = keywords(f, first(methods(f)))
452452```
453453"""
454454function keywords (func, m:: Method )
455- table = methods (func). mt
456- # table is a MethodTable object. For some reason, the :kwsorter field is not always
457- # defined. An undefined kwsorter seems to imply that there are no methods in the
458- # MethodTable with keyword arguments.
459- if ! (Base. fieldindex (Core. MethodTable, :kwsorter , false ) > 0 ) || isdefined (table, :kwsorter )
460- # Fetching method keywords stolen from base/replutil.jl:572-576 (commit 3b45cdc9aab0):
461- kwargs = VERSION < v " 1.4.0-DEV.215" ? Base. kwarg_decl (m, typeof (table. kwsorter)) : Base. kwarg_decl (m)
462- if isa (kwargs, Vector) && length (kwargs) > 0
463- filter! (arg -> ! occursin (" #" , string (arg)), kwargs)
464- # Keywords *may* not be sorted correctly. We move the vararg one to the end.
465- index = findfirst (arg -> endswith (string (arg), " ..." ), kwargs)
466- if index != nothing
467- kwargs[index], kwargs[end ] = kwargs[end ], kwargs[index]
468- end
469- return kwargs
455+ kwargs = @static if VERSION < v " 1.4.0-DEV.215"
456+ table:: Core.MethodTable = methods (func). mt
457+ # For some reason, the :kwsorter field is not always defined.
458+ # An undefined kwsorter seems to imply that there are no methods
459+ # in the MethodTable with keyword arguments.
460+ if Base. fieldindex (Core. MethodTable, :kwsorter , false ) > 0 && ! isdefined (table, :kwsorter )
461+ return Symbol[]
470462 end
463+ Base. kwarg_decl (m, typeof (table. kwsorter))
464+ else
465+ Base. kwarg_decl (m)
471466 end
472- return Symbol[]
467+ if ! isa (kwargs, Vector) || isempty (kwargs)
468+ return Symbol[]
469+ end
470+ filter! (arg -> ! occursin (" #" , string (arg)), kwargs)
471+ # Keywords *may* not be sorted correctly. We move the vararg one to the end.
472+ index = findfirst (arg -> endswith (string (arg), " ..." ), kwargs)
473+ if index != nothing
474+ kwargs[index], kwargs[end ] = kwargs[end ], kwargs[index]
475+ end
476+ return kwargs
473477end
474478
475479
0 commit comments