Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Base.depwarn() public #55212

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ export __has_internal_change
# 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 @@ -131,6 +129,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 @@ -227,6 +227,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/public.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,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