Deprecate method of extended function

Say I have the following dummy module

module MyModule

struct MyType end

Base.length(m::MyType) = 5

export length

end

What I want to do is @deprecate the length function in favor of a different function, say mylength. The following works:

module MyModule

struct MyType end

mylength(m::MyType) = 6

import Base: length
@deprecate length(m::MyType) mylength(m)

export length, mylength

end

Note the explicit import Base.length. A simple
@deprecate Base.length(m::MyType) mylength(m) doesn’t work.

Is it possible to avoid the explicit import statement somehow?

I think this is a bug — @deprecate could be extended to handle this. Please open an issue if there isn’t an existing one.

Turns out there is one: `@deprecate` should support qualified names · Issue #30310 · JuliaLang/julia · GitHub

2 Likes