Skip to content

Commit f544321

Browse files
authored
Extend doc-string for @deprecate (#42892)
1 parent 3453775 commit f544321

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

base/deprecated.jl

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
"""
1818
@deprecate old new [export_old=true]
1919
20-
Deprecate method `old` and specify the replacement call `new`. Prevent `@deprecate` from
21-
exporting `old` by setting `export_old` to `false`. `@deprecate` defines a new method with the same
22-
signature as `old`.
20+
Deprecate method `old` and specify the replacement call `new`, defining a new method `old`
21+
with the specified signature in the process.
22+
23+
To prevent `old` from being exported, set `export_old` to `false`.
2324
2425
!!! compat "Julia 1.5"
2526
As of Julia 1.5, functions defined by `@deprecate` do not print warning when `julia`
@@ -34,6 +35,23 @@ old (generic function with 1 method)
3435
julia> @deprecate old(x) new(x) false
3536
old (generic function with 1 method)
3637
```
38+
39+
Calls to `@deprecate` without explicit type-annotations will define deprecated methods
40+
accepting arguments of type `Any`. To restrict deprecation to a specific signature, annotate
41+
the arguments of `old`. For example,
42+
```jldoctest; filter = r"in Main at.*"
43+
julia> new(x::Int) = x;
44+
45+
julia> new(x::Float64) = 2x;
46+
47+
julia> @deprecate old(x::Int) new(x);
48+
49+
julia> methods(old)
50+
# 1 method for generic function "old":
51+
[1] old(x::Int64) in Main at deprecated.jl:70
52+
```
53+
will define and deprecate a method `old(x::Int)` that mirrors `new(x::Int)` but will not
54+
define nor deprecate the method `old(x::Float64)`.
3755
"""
3856
macro deprecate(old, new, export_old=true)
3957
meta = Expr(:meta, :noinline)

0 commit comments

Comments
 (0)