# Is there any way to remove the docstrings for all methods of a function?

**URL:** <https://discourse.julialang.org/t/is-there-any-way-to-remove-the-docstrings-for-all-methods-of-a-function/1497>\
**Category:** General Usage\
**Tags:** question, documentation\
**Created:** [January 15, 2017, 4:32pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-remove-the-docstrings-for-all-methods-of-a-function/1497 "2017-01-15T16:32:57Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [January 15, 2017, 4:32pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-remove-the-docstrings-for-all-methods-of-a-function/1497/1 "2017-01-15T16:32:57Z")

</div>

Lorem ipsum dolor sit amet

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [January 15, 2017, 4:42pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-remove-the-docstrings-for-all-methods-of-a-function/1497/2 "2017-01-15T16:42:25Z")

</div>

Please elaborate on your question, be more explicit about what do you want to do or know. Do you have an example of desired behavior? Help us help you.

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [January 15, 2017, 4:45pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-remove-the-docstrings-for-all-methods-of-a-function/1497/3 "2017-01-15T16:45:43Z")

</div>

I want to replace the docstring of a function.

Let’s say I define a function with documentation.

```julia
"documentation"
function test_function()
end

```

Now I want to replace the documentation.

```julia
@doc "replacement" test_function

```

But the doc string is only appended to, not replaced.

```julia
@doc test_function

```

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [January 15, 2017, 6:08pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-remove-the-docstrings-for-all-methods-of-a-function/1497/4 "2017-01-15T18:08:49Z")

</div>

Ok, I’ve figured out a bit more what’s going on here.

```julia
"documentation"
function test_function()
end

```

replaces the docstring for a particular method,

while

`@doc "replacement" test_function`

seems to replace the docstring for the function in general.

So I’ve update the title accordingly

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [January 15, 2017, 6:14pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-remove-the-docstrings-for-all-methods-of-a-function/1497/5 "2017-01-15T18:14:19Z")

</div>

I’m not sure I understood your question, but you’ve to keep in mind that you can replace the docstring only for a method that has the same signature. If you use `?functionname` you’ll see the docstrings for all methods, if you want to see the docstring of a specific method, you have to specify the signature `?foo(arguments...)`.

See the following examples:

```julia
julia> foo(x::AbstractFloat) = x
foo (generic function with 1 method)

julia> foo(x::Integer) = 2x
foo (generic function with 2 methods)

julia> foo(x) = 3x
foo (generic function with 3 methods)

julia> @doc "old generic docstring" foo
foo

julia> @doc "old docstring for floating argument" foo(::AbstractFloat)
foo

julia> @doc "old docstring for integer argument" foo(::Integer)
foo

help?> foo
search: floor pointer_from_objref OverflowError RoundFromZero FileMonitor functionloc StackOverflowError @functionloc Factorization

  old generic docstring

  old docstring for floating argument

  old docstring for integer argument

help?> foo(3)
  old docstring for integer argument

help?> foo(4.0)
  old docstring for floating argument

julia> @doc "new generic docstring" foo
WARNING: replacing docs for 'foo :: Union{}' in module 'Main'.
foo

julia> @doc "new docstring for floating argument" foo(::AbstractFloat)
WARNING: replacing docs for 'foo :: Tuple{AbstractFloat}' in module 'Main'.
foo

julia> @doc "new docstring for integer argument" foo(::Integer)
WARNING: replacing docs for 'foo :: Tuple{Integer}' in module 'Main'.
foo

help?> foo
search: floor pointer_from_objref OverflowError RoundFromZero FileMonitor functionloc StackOverflowError @functionloc Factorization

  new generic docstring

  new docstring for floating argument

  new docstring for integer argument

help?> foo(5)
  new docstring for integer argument

help?> foo(7.4)
  new docstring for floating argument

```

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [January 16, 2017, 1:36am UTC](https://discourse.julialang.org/t/is-there-any-way-to-remove-the-docstrings-for-all-methods-of-a-function/1497/6 "2017-01-16T01:36:24Z")

</div>

Ok, that’s pretty helpful to know. But if I wanted to create

`remove_docstrings_from(f::Function)`

it would quite difficult, then? I’d have to figure out all method signatures and individually remove each docstring?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 16, 2017, 7:56am UTC](https://discourse.julialang.org/t/is-there-any-way-to-remove-the-docstrings-for-all-methods-of-a-function/1497/7 "2017-01-16T07:56:01Z")

</div>

It would be helpful to know more about the problem you want to solve. Julia is a dynamic language, in the sense that you can manipulate the image, but people usually just add and overwrite docstrings, removing them is a very rare use case. (like they add variables and methods, removing either is not possible).

However, if you really insist, I guess you could look at the [source](https://github.com/JuliaLang/julia/blob/master/base/docs/Docs.jl#L218) of `Base.Docs.doc!` and figure out a way to do it.

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [November 26, 2017, 10:11pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-remove-the-docstrings-for-all-methods-of-a-function/1497/8 "2017-11-26T22:11:04Z")

</div>

Anyone know how to make that

```julia
remove_docstrings_from(f::Function)

```

suggested by @bramtayl?

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [November 27, 2017, 2:18am UTC](https://discourse.julialang.org/t/is-there-any-way-to-remove-the-docstrings-for-all-methods-of-a-function/1497/9 "2017-11-27T02:18:08Z")

</div>

I think the basic question here is “why would you want to do that”? This hasn’t been answered yet.

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [November 27, 2017, 2:18am UTC](https://discourse.julialang.org/t/is-there-any-way-to-remove-the-docstrings-for-all-methods-of-a-function/1497/10 "2017-11-27T02:18:55Z")

</div>

If you use a method like `delete_method` (in revise), you are still left with a docstring attached to the floating function.

You have to purge that to not get a warning in the console.

* * *

**edit:**

a use case would be:

> loading every file in a directory

// note: you can not validate a function has all dependencies when you include it. (i mean you could, but who has time for that)

therefore, you just keep looping over all the files until everything gets loaded and you have no errors.

delete\_method purges botched functions and then you have to remove the docs. hence the question

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [November 27, 2017, 3:01am UTC](https://discourse.julialang.org/t/is-there-any-way-to-remove-the-docstrings-for-all-methods-of-a-function/1497/11 "2017-11-27T03:01:46Z")

</div>

the code I used to resolve this can be found here:

- [https://github.com/djsegal/Julz.jl/commit/40ae62dc1df8cf345956005c4367655da56280a2#diff-30697c37f95179b8e08850d72cb2d46cR78](https://github.com/djsegal/Julz.jl/commit/40ae62dc1df8cf345956005c4367655da56280a2#diff-30697c37f95179b8e08850d72cb2d46cR78)

---

<div class="post-metadata">

**Author:** ![Jollywatt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jollywatt/32/202198_2.png) [@Jollywatt](https://discourse.julialang.org/u/Jollywatt)\
**Post date:** [December 6, 2022, 9:18am UTC](https://discourse.julialang.org/t/is-there-any-way-to-remove-the-docstrings-for-all-methods-of-a-function/1497/12 "2022-12-06T09:18:09Z")

</div>

For completeness, five years on, here’s how to clear a module’s docstrings for a particular binding:

```julia
function cleardocs!(mod::Module, name::Symbol)
    docs = Docs.meta(mod)
    docs[Docs.Binding(mod, name)] = Docs.MultiDoc() # empty multidoc
end

```

Docstrings for a module are stored in a dictionary accessed with `Doc.meta(mod)`. As far as I know, it seems ok to modify this directly.

* * *

P.S., to answer the “why” question — I needed this because sometimes Revise.jl leads to doc double-ups until you restart the session, which is annoying.
