Skip to content

Commit 442f9d5

Browse files
authored
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?
1 parent c14fe35 commit 442f9d5

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
@@ -119,9 +119,7 @@ export __has_internal_change
119119
# and of exporting the function.
120120
#
121121
# For more complex cases, move the body of the deprecated method in this file,
122-
# and call depwarn() directly from inside it. The symbol depwarn() expects is
123-
# the name of the function, which is used to ensure that the deprecation warning
124-
# is only printed the first time for each call place.
122+
# and call depwarn() directly from inside it.
125123

126124
"""
127125
@deprecate old new [export_old=true]
@@ -131,6 +129,8 @@ with the specified signature in the process.
131129
132130
To prevent `old` from being exported, set `export_old` to `false`.
133131
132+
See also [`Base.depwarn()`](@ref).
133+
134134
!!! compat "Julia 1.5"
135135
As of Julia 1.5, functions defined by `@deprecate` do not print warning when `julia`
136136
is run without the `--depwarn=yes` flag set, as the default value of `--depwarn` option
@@ -227,6 +227,26 @@ macro deprecate(old, new, export_old=true)
227227
end
228228
end
229229

230+
"""
231+
Base.depwarn(msg::String, funcsym::Symbol; force=false)
232+
233+
Print `msg` as a deprecation warning. The symbol `funcsym` should be the name
234+
of the calling function, which is used to ensure that the deprecation warning is
235+
only printed the first time for each call place. Set `force=true` to force the
236+
warning to always be shown, even if Julia was started with `--depwarn=no` (the
237+
default).
238+
239+
See also [`@deprecate`](@ref).
240+
241+
# Examples
242+
```julia
243+
function deprecated_func()
244+
Base.depwarn("Don't use `deprecated_func()`!", :deprecated_func)
245+
246+
1 + 1
247+
end
248+
```
249+
"""
230250
@nospecializeinfer function depwarn(msg, funcsym; force::Bool=false)
231251
@nospecialize
232252
# N.B. With this use of `@invokelatest`, we're preventing the addition of backedges from

base/public.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,5 @@ public
112112
# misc
113113
notnothing,
114114
runtests,
115-
text_colors
115+
text_colors,
116+
depwarn

doc/src/base/base.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,12 @@ Base.@simd
311311
Base.@polly
312312
Base.@generated
313313
Base.@assume_effects
314+
```
315+
316+
## Managing deprecations
317+
```@docs
314318
Base.@deprecate
319+
Base.depwarn
315320
```
316321

317322
## Missing Values

0 commit comments

Comments
 (0)