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 it possible to avoid the warning when replacing docstrings #32118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ end

Adds a new docstring `str` to the docsystem of `__module__` for `binding` and signature `sig`.
"""
function doc!(__module__::Module, b::Binding, str::DocStr, @nospecialize sig = Union{})
function doc!(__module__::Module, b::Binding, str::DocStr, @nospecialize(sig) = Union{}, shouldwarn::Bool=true)
initmeta(__module__)
m = get!(meta(__module__), b, MultiDoc())
if haskey(m.docs, sig)
# We allow for docstrings to be updated, but print a warning since it is possible
# that over-writing a docstring *may* have been accidental. The warning
# is suppressed for symbols in Main, for interactive use (#23011).
__module__ == Main || @warn "Replacing docs for `$b :: $sig` in module `$(__module__)`"
__module__ == Main || !shouldwarn || @warn "Replacing docs for `$b :: $sig` in module `$(__module__)`"
else
# The ordering of docstrings for each Binding is defined by the order in which they
# are initially added. Replacing a specific docstring does not change it's ordering.
Expand Down
18 changes: 18 additions & 0 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1159,3 +1159,21 @@ end
end
@test M27832.xs == ":(\$(Expr(:\$, :fn)))"
Core.atdoc!(_last_atdoc)

# Replacing docstrings
module Revise309
"""
A docstring
"""
c = 0
end
let b = Binding(Revise309, :c)
dstr = meta(Revise309)[b].docs[Union{}]
logs = Test.collect_test_logs() do
Base.Docs.doc!(Revise309, b, dstr, Union{}, false)
end
@test isempty(logs[1])
@test_logs (:warn, r"^Replacing docs for .*Revise309\.c") begin
Base.Docs.doc!(Revise309, b, dstr)
end
end