From 575a2f25cbcd2d1372d8a2893dc2a9818f518022 Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Wed, 21 Aug 2019 18:07:24 +0100 Subject: [PATCH 1/3] make kwarg-methods whereis as nothing, rather than as ("none",0) --- src/CodeTracking.jl | 12 ++++++++++-- test/runtests.jl | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/CodeTracking.jl b/src/CodeTracking.jl index efe1416..74c9ba6 100644 --- a/src/CodeTracking.jl +++ b/src/CodeTracking.jl @@ -46,9 +46,13 @@ const juliastdlib = joinpath("julia", "stdlib", "v$(VERSION.major).$(VERSION.min Return the file and line of the definition of `method`. `line` is the first line of the method's body. +If for some reason the file can not be determined, then this returns `nothing` """ function whereis(method::Method) - file, line = String(method.file), method.line + method.file == :none && return nothing + + file = String(method.file) + line = method.line startswith(file, "REPL[") && return file, line lin = get(method_info, method.sig, nothing) if lin === nothing @@ -184,12 +188,16 @@ end Return a string with the code that defines `method`. Also return the first line of the definition, including the signature (which may not be the same line number returned by `whereis`). +If the method could not be found for some reason, returns `nothing`. Note this may not be terribly useful for methods that are defined inside `@eval` statements; see [`definition(Expr, method::Method)`](@ref) instead. """ function definition(::Type{String}, method::Method) - file, line = whereis(method) + loc = whereis(method) + loc === nothing && return nothing + + file, line = loc src = src_from_file_or_REPL(file) eol = isequal('\n') linestarts = Int[] diff --git a/test/runtests.jl b/test/runtests.jl index d203172..5730a84 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -96,6 +96,14 @@ isdefined(Main, :Revise) ? includet("script.jl") : include("script.jl") lin = src.linetable[idx] file, line = whereis(lin, m) @test endswith(file, String(lin.file)) + + + # kwargs that result in not finding the file + m = @which sum([1]; dims=1) + loc = whereis(m) + @test loc != ("none", 0) # old incorrect behavour. + @test loc === nothing + @test definition(String, m) === nothing end @testset "With Revise" begin From 4642055774a9a68555173ff42d3c79c6bc9662b9 Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Thu, 22 Aug 2019 11:25:20 +0100 Subject: [PATCH 2/3] Update src/CodeTracking.jl Co-Authored-By: Kristoffer Carlsson --- src/CodeTracking.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CodeTracking.jl b/src/CodeTracking.jl index 74c9ba6..0c7dbd9 100644 --- a/src/CodeTracking.jl +++ b/src/CodeTracking.jl @@ -46,7 +46,7 @@ const juliastdlib = joinpath("julia", "stdlib", "v$(VERSION.major).$(VERSION.min Return the file and line of the definition of `method`. `line` is the first line of the method's body. -If for some reason the file can not be determined, then this returns `nothing` +If for some reason the file can not be determined, then return `nothing` """ function whereis(method::Method) method.file == :none && return nothing From e04b194b7f1ebe6a8c8b54f7359cab8740347259 Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Thu, 22 Aug 2019 11:59:53 +0100 Subject: [PATCH 3/3] Update src/CodeTracking.jl Co-Authored-By: Kristoffer Carlsson --- src/CodeTracking.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CodeTracking.jl b/src/CodeTracking.jl index 0c7dbd9..ff549a4 100644 --- a/src/CodeTracking.jl +++ b/src/CodeTracking.jl @@ -188,7 +188,7 @@ end Return a string with the code that defines `method`. Also return the first line of the definition, including the signature (which may not be the same line number returned by `whereis`). -If the method could not be found for some reason, returns `nothing`. +If the method could not be found for some reason, then return `nothing`. Note this may not be terribly useful for methods that are defined inside `@eval` statements; see [`definition(Expr, method::Method)`](@ref) instead.