Skip to content

Commit b09a4b3

Browse files
JamesWrigleyKristofferC
authored andcommitted
Make Base.depwarn() public (#55212)
There's a few reasons for making it public: - It's already mentioned in the manual (#54211). - It's the easiest way to deprecate a function that shouldn't be used anymore at all. - It's already widely used in the ecosystem: https://juliahub.com/ui/Search?type=code&q=Base.depwarn( I also moved the `@deprecate` docs into a new `Managing deprecations` section because I felt it should go together with `Base.depwarn()`. Might be worth backporting to 1.11? (cherry picked from commit 442f9d5)
1 parent 44fc535 commit b09a4b3

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

base/deprecated.jl

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
# and of exporting the function.
1111
#
1212
# For more complex cases, move the body of the deprecated method in this file,
13-
# and call depwarn() directly from inside it. The symbol depwarn() expects is
14-
# the name of the function, which is used to ensure that the deprecation warning
15-
# is only printed the first time for each call place.
13+
# and call depwarn() directly from inside it.
1614

1715
"""
1816
@deprecate old new [export_old=true]
@@ -22,6 +20,8 @@ with the specified signature in the process.
2220
2321
To prevent `old` from being exported, set `export_old` to `false`.
2422
23+
See also [`Base.depwarn()`](@ref).
24+
2525
!!! compat "Julia 1.5"
2626
As of Julia 1.5, functions defined by `@deprecate` do not print warning when `julia`
2727
is run without the `--depwarn=yes` flag set, as the default value of `--depwarn` option
@@ -118,6 +118,26 @@ macro deprecate(old, new, export_old=true)
118118
end
119119
end
120120

121+
"""
122+
Base.depwarn(msg::String, funcsym::Symbol; force=false)
123+
124+
Print `msg` as a deprecation warning. The symbol `funcsym` should be the name
125+
of the calling function, which is used to ensure that the deprecation warning is
126+
only printed the first time for each call place. Set `force=true` to force the
127+
warning to always be shown, even if Julia was started with `--depwarn=no` (the
128+
default).
129+
130+
See also [`@deprecate`](@ref).
131+
132+
# Examples
133+
```julia
134+
function deprecated_func()
135+
Base.depwarn("Don't use `deprecated_func()`!", :deprecated_func)
136+
137+
1 + 1
138+
end
139+
```
140+
"""
121141
@nospecializeinfer function depwarn(msg, funcsym; force::Bool=false)
122142
@nospecialize
123143
# N.B. With this use of `@invokelatest`, we're preventing the addition of backedges from

base/exports.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,4 +1177,5 @@ public
11771177
# misc
11781178
notnothing,
11791179
runtests,
1180-
text_colors
1180+
text_colors,
1181+
depwarn

doc/src/base/base.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,12 @@ Base.@simd
307307
Base.@polly
308308
Base.@generated
309309
Base.@assume_effects
310+
```
311+
312+
## Managing deprecations
313+
```@docs
310314
Base.@deprecate
315+
Base.depwarn
311316
```
312317

313318
## Missing Values

0 commit comments

Comments
 (0)