Skip to content

Commit a84ff78

Browse files
serenity4mortenpi
andauthored
Fixes for nightly (#176)
Co-authored-by: Morten Piibeleht <[email protected]>
1 parent bca4b2c commit a84ff78

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DocStringExtensions"
22
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
3-
version = "0.9.4"
3+
version = "0.9.5"
44

55
[compat]
66
julia = "1"

src/utilities.jl

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -452,24 +452,28 @@ kws = keywords(f, first(methods(f)))
452452
```
453453
"""
454454
function 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
473477
end
474478

475479

test/tests.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ end
4040
# Its signature is kwarg_decl(m::Method, kwtype::DataType). The second argument
4141
# should be the type of the kwsorter from the corresponding MethodTable.
4242
@test isa(methods(M.j_1), Base.MethodList)
43-
@test isdefined(methods(M.j_1), :mt)
44-
local mt = methods(M.j_1).mt
43+
get_mt(func) = VERSION v"1.13.0-DEV.647" ? Core.GlobalMethods : methods(func).mt
44+
local mt = get_mt(M.j_1)
4545
@test isa(mt, Core.MethodTable)
4646
if Base.fieldindex(Core.MethodTable, :kwsorter, false) > 0
4747
@test isdefined(mt, :kwsorter)
4848
end
4949
# .kwsorter is not always defined -- namely, it seems when none of the methods
5050
# have keyword arguments:
51-
@test isdefined(methods(M.f).mt, :kwsorter) === false
51+
@test isdefined(get_mt(M.f), :kwsorter) === false
5252
# M.j_1 has two methods. Fetch the single argument one..
5353
local m = which(M.j_1, (Any,))
5454
@test isa(m, Method)
@@ -61,7 +61,7 @@ end
6161
# that does not have any arguments
6262
m = which(M.j_1, (Any,Any)) # fetch the no-keyword method
6363
if VERSION < v"1.4.0-DEV.215"
64-
@test Base.kwarg_decl(m, typeof(methods(M.j_1).mt.kwsorter)) == Tuple{}()
64+
@test Base.kwarg_decl(m, typeof(get_mt(M.j_1).kwsorter)) == Tuple{}()
6565
else
6666
@test Base.kwarg_decl(m) == []
6767
end
@@ -83,7 +83,9 @@ end
8383
DSE.format(IMPORTS, buf, doc)
8484
str = String(take!(buf))
8585
@test occursin("\n - `Base`\n", str)
86-
@test occursin("\n - `Core`\n", str)
86+
if VERSION < v"1.13-DEV"
87+
@test occursin("\n - `Core`\n", str)
88+
end
8789

8890
# Module exports.
8991
DSE.format(EXPORTS, buf, doc)

0 commit comments

Comments
 (0)