Julia: `@deprecate` should support qualified names

Created on 8 Dec 2018  路  7Comments  路  Source: JuliaLang/julia

Julia 1.0.2

module fun

struct Mine
end

function open(mine::Mine)
    print("hi")
end

Base.open(mine::Mine) = open(mine)

#= @deprecate Base.open(mine::Mine) open(mine::Mine) =#
@deprecate lies(mine::Mine) open(mine::Mine)

end # module

If this is my module, I can add a method to the function Base.open, but I can't deprecate it. (Causes @deprecate warning on import.)

Most helpful comment

Yes, the deprecations stuff is technically internal and private but so useful that everyone uses it anyway! It would be good to review the API for deprecations and make an official stdlib for it and in the future use that for Base's own deprecations.

All 7 comments

Please ask questions on https://discourse.julialang.org/.

I mean it's not a question, I expect to be able to deprecate any method signature I can define. That I can't is what I'd call a bug: something that should function, doesn't.

Is there a subtlety I'm missing?

@joelfrederico it looks like this is no longer valid usage of @deprecate? Maybe I'm doing this wrong, but this is what I get locally:

julia> module fun

       struct Mine
       end

       function open(mine::Mine)
           print("hi")
       end

       Base.open(mine::Mine) = open(mine)

       @deprecate Base.open(mine::Mine) open(mine::Mine)
       @deprecate lies(mine::Mine) open(mine::Mine)

       end # module
ERROR: LoadError: invalid usage of @deprecate
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] @deprecate(::LineNumberNode, ::Module, ::Any, ::Any, ::Any) at ./deprecated.jl:45
 [3] @deprecate(::LineNumberNode, ::Module, ::Any, ::Any) at ./deprecated.jl:22
in expression starting at REPL[1]:12
julia> versioninfo()
Julia Version 1.0.2-pre.110
Commit b196720 (2018-11-03 19:46 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, haswell)

I'm not sure if this is desired or intended, but I do agree that it would be good to be able to do this.

The best answer I got is that @deprecate is undocumented! It was written by Base developers just for use in Base. That means, unfortunately, that we shouldn't be using it at all. Same for depwarn I believe.

Hopefully somebody cleans this up and documents it so it becomes a usable part of Base.

I agree this should work. Something like the following might work around it for now:

@eval Base begin
       @deprecate open(mine::$Mine) $open(mine::$Mine)
end

Yes, the deprecations stuff is technically internal and private but so useful that everyone uses it anyway! It would be good to review the API for deprecations and make an official stdlib for it and in the future use that for Base's own deprecations.

I stumbled across this in the context of my discourse post. Would be great to have this fixed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

felixrehren picture felixrehren  路  3Comments

ararslan picture ararslan  路  3Comments

yurivish picture yurivish  路  3Comments

omus picture omus  路  3Comments

i-apellaniz picture i-apellaniz  路  3Comments