Julia: don't warn about redefining docstrings in Main

Created on 28 Jul 2017  Â·  6Comments  Â·  Source: JuliaLang/julia

Similar to #18725, it came up on discourse that we shouldn't emit a warning when redefining docstrings during interactive use, i.e. for definitions in Main:

julia> @doc "foo" f(x) = x+1
f

julia> @doc "foo" f(x) = x+1
WARNING: replacing docs for 'f :: Tuple{Any}' in module 'Main'.
f
docsystem

Most helpful comment

Or we could just delete the warning entirely. We already have a warning for redefining methods that are not in Main, and this seems somewhat redundant with that.

All 6 comments

Looks like an easy patch should do it:

diff --git a/base/docs/Docs.jl b/base/docs/Docs.jl
index 14cbe17..2bd791f 100644
--- a/base/docs/Docs.jl
+++ b/base/docs/Docs.jl
@@ -232,7 +232,7 @@ Adds a new docstring `str` to the docsystem of `__module__` for `binding` and si
 function doc!(__module__::Module, b::Binding, str::DocStr, @nospecialize sig = Union{})
     initmeta(__module__)
     m = get!(meta(__module__), b, MultiDoc())
-    if haskey(m.docs, sig)
+    if haskey(m.docs, sig) && __module__ != Main
         # We allow for docstrings to be updated, but print a warning since it is possible
         # that over-writing a docstring *may* have been accidental.
         warn("replacing docs for '$b :: $sig' in module '$(__module__)'.")

Or we could just delete the warning entirely. We already have a warning for redefining methods that are not in Main, and this seems somewhat redundant with that.

I believe it's possible to replace docs without redefining the method, e.g. by just writing the function name (?). So the warning might still be useful.

I believe it's possible to replace docs without redefining the method, e.g. by just writing the function name (?). So the warning might still be useful.

Yes that has happened to me several times, the warning about overwriting docs is very useful actually.

I always edit functions in Juno and call them in IJulia to check the results. And then revise the code in Juno and "include()" the code file in IJulia again to check the results. In this situation, every time I saw a lot of warnings of redefining docstrings. When there are a lot of functions, the IJulia notebook is occupied by the warnings.

Although this warning would be helpful in some other situations, it is still convenient for the users to suppress the warnings when they want.

We definitely shouldn't have a warning for redefining docstrings in Main, at least, similar to #19888. Redefining things in interactive use is expected and shouldn't trigger warnings.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StefanKarpinski picture StefanKarpinski  Â·  3Comments

Keno picture Keno  Â·  3Comments

yurivish picture yurivish  Â·  3Comments

ararslan picture ararslan  Â·  3Comments

dpsanders picture dpsanders  Â·  3Comments