@@ -452,24 +452,24 @@ kws = keywords(f, first(methods(f)))
452452```
453453"""
454454function keywords (func, m:: Method )
455- table:: Core.MethodTable = VERSION ≥ v " 1.13.0-DEV.647" ? Core. GlobalMethods : methods (func). mt
456- # For some reason, the :kwsorter field is not always defined.
457- # An undefined kwsorter seems to imply that there are no methods
458- # in the 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
470- end
455+ @static if VERSION < v " 1.4"
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+ isdefined (table, :kwsorter ) || return Symbol[]
461+ kwargs = Base. kwarg_decl (m, typeof (table. kwsorter))
462+ else
463+ kwargs = Base. kwarg_decl (m)
471464 end
472- return Symbol[]
465+ isa (kwargs, Vector) && ! isempty (kwargs) || return Symbol[]
466+ filter! (arg -> ! occursin (" #" , string (arg)), kwargs)
467+ # Keywords *may* not be sorted correctly. We move the vararg one to the end.
468+ index = findfirst (arg -> endswith (string (arg), " ..." ), kwargs)
469+ if index != nothing
470+ kwargs[index], kwargs[end ] = kwargs[end ], kwargs[index]
471+ end
472+ return kwargs
473473end
474474
475475
0 commit comments