Skip to content

Commit

Permalink
Make Base.depwarn() public (#55212)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
JamesWrigley authored and KristofferC committed Aug 19, 2024
1 parent 44fc535 commit b09a4b3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
26 changes: 23 additions & 3 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
# and of exporting the function.
#
# For more complex cases, move the body of the deprecated method in this file,
# and call depwarn() directly from inside it. The symbol depwarn() expects is
# the name of the function, which is used to ensure that the deprecation warning
# is only printed the first time for each call place.
# and call depwarn() directly from inside it.

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

"""
Base.depwarn(msg::String, funcsym::Symbol; force=false)
Print `msg` as a deprecation warning. The symbol `funcsym` should be the name
of the calling function, which is used to ensure that the deprecation warning is
only printed the first time for each call place. Set `force=true` to force the
warning to always be shown, even if Julia was started with `--depwarn=no` (the
default).
See also [`@deprecate`](@ref).
# Examples
```julia
function deprecated_func()
Base.depwarn("Don't use `deprecated_func()`!", :deprecated_func)
1 + 1
end
```
"""
@nospecializeinfer function depwarn(msg, funcsym; force::Bool=false)
@nospecialize
# N.B. With this use of `@invokelatest`, we're preventing the addition of backedges from
Expand Down
3 changes: 2 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1177,4 +1177,5 @@ public
# misc
notnothing,
runtests,
text_colors
text_colors,
depwarn
5 changes: 5 additions & 0 deletions doc/src/base/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,12 @@ Base.@simd
Base.@polly
Base.@generated
Base.@assume_effects
```

## Managing deprecations
```@docs
Base.@deprecate
Base.depwarn
```

## Missing Values
Expand Down

0 comments on commit b09a4b3

Please sign in to comment.