From c3f7a07505ef73e719e486ebb67923fc1ec6791d Mon Sep 17 00:00:00 2001 From: serenity4 Date: Sat, 31 May 2025 12:42:57 +0200 Subject: [PATCH 1/6] Fixes for nightly --- src/utilities.jl | 8 ++++---- test/tests.jl | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/utilities.jl b/src/utilities.jl index 7506ffd..b23b756 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -452,10 +452,10 @@ kws = keywords(f, first(methods(f))) ``` """ function keywords(func, m::Method) - table = methods(func).mt - # table is a MethodTable object. For some reason, the :kwsorter field is not always - # defined. An undefined kwsorter seems to imply that there are no methods in the - # MethodTable with keyword arguments. + table::Core.MethodTable = VERSION ≥ v"1.13.0-DEV.647" ? Core.GlobalMethods : methods(func).mt + # For some reason, the :kwsorter field is not always defined. + # An undefined kwsorter seems to imply that there are no methods + # in the MethodTable with keyword arguments. if !(Base.fieldindex(Core.MethodTable, :kwsorter, false) > 0) || isdefined(table, :kwsorter) # Fetching method keywords stolen from base/replutil.jl:572-576 (commit 3b45cdc9aab0): kwargs = VERSION < v"1.4.0-DEV.215" ? Base.kwarg_decl(m, typeof(table.kwsorter)) : Base.kwarg_decl(m) diff --git a/test/tests.jl b/test/tests.jl index fead702..913fa9f 100644 --- a/test/tests.jl +++ b/test/tests.jl @@ -40,15 +40,15 @@ end # Its signature is kwarg_decl(m::Method, kwtype::DataType). The second argument # should be the type of the kwsorter from the corresponding MethodTable. @test isa(methods(M.j_1), Base.MethodList) - @test isdefined(methods(M.j_1), :mt) - local mt = methods(M.j_1).mt + get_mt(func) = VERSION ≥ v"1.13.0-DEV.647" ? Core.GlobalMethods : methods(func).mt + local mt = get_mt(M.j_1) @test isa(mt, Core.MethodTable) if Base.fieldindex(Core.MethodTable, :kwsorter, false) > 0 @test isdefined(mt, :kwsorter) end # .kwsorter is not always defined -- namely, it seems when none of the methods # have keyword arguments: - @test isdefined(methods(M.f).mt, :kwsorter) === false + @test isdefined(get_mt(M.f), :kwsorter) === false # M.j_1 has two methods. Fetch the single argument one.. local m = which(M.j_1, (Any,)) @test isa(m, Method) @@ -61,7 +61,7 @@ end # that does not have any arguments m = which(M.j_1, (Any,Any)) # fetch the no-keyword method if VERSION < v"1.4.0-DEV.215" - @test Base.kwarg_decl(m, typeof(methods(M.j_1).mt.kwsorter)) == Tuple{}() + @test Base.kwarg_decl(m, typeof(get_mt(M.j_1).kwsorter)) == Tuple{}() else @test Base.kwarg_decl(m) == [] end @@ -83,7 +83,9 @@ end DSE.format(IMPORTS, buf, doc) str = String(take!(buf)) @test occursin("\n - `Base`\n", str) - @test occursin("\n - `Core`\n", str) + if VERSION < v"1.13-DEV" + @test occursin("\n - `Core`\n", str) + end # Module exports. DSE.format(EXPORTS, buf, doc) From be6499d43c6f07b88a63e524d5da6e9a64917736 Mon Sep 17 00:00:00 2001 From: serenity4 Date: Sun, 1 Jun 2025 11:37:01 +0200 Subject: [PATCH 2/6] Refactor kwarg extraction logic --- src/utilities.jl | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/utilities.jl b/src/utilities.jl index b23b756..8a53b29 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -452,24 +452,24 @@ kws = keywords(f, first(methods(f))) ``` """ function keywords(func, m::Method) - table::Core.MethodTable = VERSION ≥ v"1.13.0-DEV.647" ? Core.GlobalMethods : methods(func).mt - # For some reason, the :kwsorter field is not always defined. - # An undefined kwsorter seems to imply that there are no methods - # in the MethodTable with keyword arguments. - if !(Base.fieldindex(Core.MethodTable, :kwsorter, false) > 0) || isdefined(table, :kwsorter) - # Fetching method keywords stolen from base/replutil.jl:572-576 (commit 3b45cdc9aab0): - kwargs = VERSION < v"1.4.0-DEV.215" ? Base.kwarg_decl(m, typeof(table.kwsorter)) : Base.kwarg_decl(m) - if isa(kwargs, Vector) && length(kwargs) > 0 - filter!(arg -> !occursin("#", string(arg)), kwargs) - # Keywords *may* not be sorted correctly. We move the vararg one to the end. - index = findfirst(arg -> endswith(string(arg), "..."), kwargs) - if index != nothing - kwargs[index], kwargs[end] = kwargs[end], kwargs[index] - end - return kwargs - end + @static if VERSION < v"1.4" + table::Core.MethodTable = methods(func).mt + # For some reason, the :kwsorter field is not always defined. + # An undefined kwsorter seems to imply that there are no methods + # in the MethodTable with keyword arguments. + isdefined(table, :kwsorter) || return Symbol[] + kwargs = Base.kwarg_decl(m, typeof(table.kwsorter)) + else + kwargs = Base.kwarg_decl(m) end - return Symbol[] + isa(kwargs, Vector) && !isempty(kwargs) || return Symbol[] + filter!(arg -> !occursin("#", string(arg)), kwargs) + # Keywords *may* not be sorted correctly. We move the vararg one to the end. + index = findfirst(arg -> endswith(string(arg), "..."), kwargs) + if index != nothing + kwargs[index], kwargs[end] = kwargs[end], kwargs[index] + end + return kwargs end From 08fc5d95250f44647fb9558e5c1a588c8896cf32 Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Sat, 7 Jun 2025 05:45:31 +1200 Subject: [PATCH 3/6] Apply suggestions from code review --- src/utilities.jl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/utilities.jl b/src/utilities.jl index 8a53b29..41aa708 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -452,17 +452,21 @@ kws = keywords(f, first(methods(f))) ``` """ function keywords(func, m::Method) - @static if VERSION < v"1.4" + kwargs = @static if VERSION < v"1.4" table::Core.MethodTable = methods(func).mt # For some reason, the :kwsorter field is not always defined. # An undefined kwsorter seems to imply that there are no methods # in the MethodTable with keyword arguments. - isdefined(table, :kwsorter) || return Symbol[] - kwargs = Base.kwarg_decl(m, typeof(table.kwsorter)) + if !isdefined(table, :kwsorter) + return Symbol[] + end + Base.kwarg_decl(m, typeof(table.kwsorter)) else - kwargs = Base.kwarg_decl(m) + Base.kwarg_decl(m) + end + if !isa(kwargs, Vector) || isempty(kwargs) + return Symbol[] end - isa(kwargs, Vector) && !isempty(kwargs) || return Symbol[] filter!(arg -> !occursin("#", string(arg)), kwargs) # Keywords *may* not be sorted correctly. We move the vararg one to the end. index = findfirst(arg -> endswith(string(arg), "..."), kwargs) From 27c92b4238a71d3c7b3ecbb98e9b279e07ebd38f Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Sat, 7 Jun 2025 05:46:47 +1200 Subject: [PATCH 4/6] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 0a698ef..caa097f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DocStringExtensions" uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" -version = "0.9.4" +version = "0.9.5" [compat] julia = "1" From bcb5b8d1996acf41cf67fa173a6708d085d4a50a Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Sat, 7 Jun 2025 06:06:49 +1200 Subject: [PATCH 5/6] Update src/utilities.jl --- src/utilities.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilities.jl b/src/utilities.jl index 41aa708..a48d43d 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -452,7 +452,7 @@ kws = keywords(f, first(methods(f))) ``` """ function keywords(func, m::Method) - kwargs = @static if VERSION < v"1.4" + kwargs = @static if VERSION < v"1.4.0-DEV.215" table::Core.MethodTable = methods(func).mt # For some reason, the :kwsorter field is not always defined. # An undefined kwsorter seems to imply that there are no methods From a66676cd8f8ddb901399cd0e3b82183efcdc5ae6 Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Sat, 7 Jun 2025 06:07:15 +1200 Subject: [PATCH 6/6] Update src/utilities.jl --- src/utilities.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilities.jl b/src/utilities.jl index a48d43d..e04d459 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -457,7 +457,7 @@ function keywords(func, m::Method) # For some reason, the :kwsorter field is not always defined. # An undefined kwsorter seems to imply that there are no methods # in the MethodTable with keyword arguments. - if !isdefined(table, :kwsorter) + if Base.fieldindex(Core.MethodTable, :kwsorter, false) > 0 && !isdefined(table, :kwsorter) return Symbol[] end Base.kwarg_decl(m, typeof(table.kwsorter))