@@ -862,19 +862,29 @@ function MethodList(mt::Core.MethodTable)
862
862
end
863
863
864
864
"""
865
- methods(f, [types])
865
+ methods(f, [types], [module] )
866
866
867
- Returns the method table for `f`.
867
+ Return the method table for `f`.
868
868
869
- If `types` is specified, returns an array of methods whose types match.
869
+ If `types` is specified, return an array of methods whose types match.
870
+ If `module` is specified, return an array of methods defined in this module.
871
+ A list of modules can also be specified as an array or tuple.
872
+
873
+ !!! compat "Julia 1.4"
874
+ At least Julia 1.4 is required for specifying a module.
870
875
"""
871
- function methods (@nospecialize (f), @nospecialize (t))
876
+ function methods (@nospecialize (f), @nospecialize (t),
877
+ @nospecialize (mod:: Union{Module,AbstractArray{Module},Tuple{Vararg{Module}},Nothing} = nothing ))
878
+ if mod isa Module
879
+ mod = (mod,)
880
+ end
872
881
if isa (f, Core. Builtin)
873
882
throw (ArgumentError (" argument is not a generic function" ))
874
883
end
875
884
t = to_tuple_type (t)
876
885
world = typemax (UInt)
877
- return MethodList (Method[m[3 ] for m in _methods (f, t, - 1 , world)], typeof (f). name. mt)
886
+ MethodList (Method[m[3 ] for m in _methods (f, t, - 1 , world) if mod === nothing || m[3 ]. module in mod],
887
+ typeof (f). name. mt)
878
888
end
879
889
880
890
methods (f:: Core.Builtin ) = MethodList (Method[], typeof (f). name. mt)
@@ -887,9 +897,11 @@ function methods_including_ambiguous(@nospecialize(f), @nospecialize(t))
887
897
ms = ccall (:jl_matching_methods , Any, (Any, Cint, Cint, UInt, Ptr{UInt}, Ptr{UInt}), tt, - 1 , 1 , world, min, max):: Array{Any,1}
888
898
return MethodList (Method[m[3 ] for m in ms], typeof (f). name. mt)
889
899
end
890
- function methods (@nospecialize (f))
900
+
901
+ function methods (@nospecialize (f),
902
+ @nospecialize (mod:: Union{Module,AbstractArray{Module},Tuple{Vararg{Module}},Nothing} = nothing ))
891
903
# return all matches
892
- return methods (f, Tuple{Vararg{Any}})
904
+ return methods (f, Tuple{Vararg{Any}}, mod )
893
905
end
894
906
895
907
function visit (f, mt:: Core.MethodTable )
0 commit comments