Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show of parameterized methods #10794

Closed
mauro3 opened this issue Apr 11, 2015 · 2 comments
Closed

Show of parameterized methods #10794

mauro3 opened this issue Apr 11, 2015 · 2 comments

Comments

@mauro3
Copy link
Contributor

mauro3 commented Apr 11, 2015

Below example shows that the method display does not make it clear whether the function parameter T features in the Array parameter or not.

julia> f{T}(::Array, x::T) = 1
f (generic function with 1 method)

julia> f{T}(::Array{T}, x::T) = 1
f (generic function with 2 methods)

julia> methods(f)
#2 methods for generic function "f":
f{T}(::Array{T,N},x::T) at none:1
f{T}(::Array{T,N},x::T) at none:1

for instance in methods(call) it looks like a lot of them are parametrized on the first argument but are not.

Maybe display like this instead:

ulia> methods(f)
#2 methods for generic function "f":
f{T}(::Array{_,_},x::T) at none:1
f{T}(::Array{T,N},x::T) at none:1
@ihnorton ihnorton changed the title Show of paramtereized methods Show of parameterized methods Apr 13, 2015
@JeffBezanson
Copy link
Member

Here's a simple patch that I like for handling this; see if you like it:

diff --git a/base/methodshow.jl b/base/methodshow.jl
index e101dee..541a379 100644
--- a/base/methodshow.jl
+++ b/base/methodshow.jl
@@ -19,6 +19,9 @@ function argtype_decl(n, t) # -> (argname, argtype)
             return s, string(t.parameters[1], "...")
         end
     end
+    if isa(t,DataType) && t === t.name.primary
+        return s, string(t.name)
+    end
     return s, string(t)
 end

@mauro3
Copy link
Contributor Author

mauro3 commented Apr 17, 2015

Yes, I think that is better but not perfect. Here the output now:

julia> f{T,N}(a::Array, b::Array{T}, c::Array{T,N}) = 1
f (generic function with 1 method)

julia> methods(f)
# 1 method for generic function "f":
f{T,N}(a::Array,b::Array{T,N},c::Array{T,N}) at none:1

So the second Array prints N even though it shouldn't.

I put together PR #10861 which should address this:

f{T,N}(a::Array    , b::Array{T},  c::Array{T,N},d::T,e::Int32,f::Vector,    g::Vector{T}, h::Array{Vector,1}) = 1

f{T,N}(a::Array{*,*},b::Array{T,*},c::Array{T,N},d::T,e::Int32,f::Array{*,1},g::Array{T,1},h::Array{Array{*,1},1})

What do you think? An option would be to just print a space instead of the *, or anything. Not printing something for missing parameters would only work if we print the typealiases instead of the actual types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants