Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8596dbe

Browse files
authored
Add one-argumentargtypes methods to source reflection functions (#58925)
Follow-up to#58891 (comment),extending the feature to `which`, `functionloc`, `edit` and `less`.
1 parenta355630 commit8596dbe

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

‎base/methodshow.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ end
181181
Return a tuple `(filename,line)` giving the location of a generic `Function` definition.
182182
"""
183183
functionloc(@nospecialize(f),@nospecialize(types))=functionloc(which(f,types))
184+
functionloc(@nospecialize(argtypes::Union{Tuple, Type{<:Tuple}}))=functionloc(which(argtypes))
184185

185186
functionfunctionloc(@nospecialize(f))
186187
mt=methods(f)

‎base/reflection.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ Returns the method that would be called by the given type signature (as a tuple
960960
functionwhich(@nospecialize(tt#=::Type=#))
961961
return_which(tt).method
962962
end
963+
which(@nospecialize(argtypes::Tuple))=which(to_tuple_type(argtypes))
963964

964965
"""
965966
which(module, symbol)

‎stdlib/InteractiveUtils/src/editless.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ function edit(@nospecialize f)
269269
end
270270
edit(m::Method)=edit(functionloc(m)...)
271271
edit(@nospecialize(f), idx::Integer)=edit(methods(f).ms[idx])
272-
edit(f, t)= (@nospecialize;edit(functionloc(f, t)...))
272+
edit(f, t)= (@nospecialize;edit(functionloc(f, t)...))
273+
edit(@nospecialize argtypes::Union{Tuple, Type{<:Tuple}})=edit(functionloc(argtypes)...)
273274
edit(file::Nothing, line::Integer)=error("could not find source file for function")
274275
edit(m::Module)=edit(pathof(m))
275276

‎stdlib/InteractiveUtils/test/runtests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,18 @@ catch err13464
329329
@teststartswith(err13464.msg,"expression is not a function call")
330330
end
331331

332+
@testset"Single-argument forms"begin
333+
a=which(+, (Int, Int))
334+
b=which((typeof(+), Int, Int))
335+
c=which(Tuple{typeof(+), Int, Int})
336+
@test a== b== c
337+
338+
a=functionloc(+, (Int, Int))
339+
b=functionloc((typeof(+), Int, Int))
340+
c=functionloc(Tuple{typeof(+), Int, Int})
341+
@test a== b== c
342+
end
343+
332344
# PR 57909
333345
@testset"Support for type annotations as arguments"begin
334346
@test (@which (::Vector{Int})[::Int]).name===:getindex

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp