# Docstring for overwritten function

**URL:** <https://discourse.julialang.org/t/docstring-for-overwritten-function/10777>\
**Category:** General Usage\
**Created:** [May 8, 2018, 1:09pm UTC](https://discourse.julialang.org/t/docstring-for-overwritten-function/10777 "2018-05-08T13:09:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sam/32/4101_2.png) [@Sam](https://discourse.julialang.org/u/Sam)\
**Post date:** [May 8, 2018, 1:09pm UTC](https://discourse.julialang.org/t/docstring-for-overwritten-function/10777/1 "2018-05-08T13:09:58Z")

</div>

Hi,

I am writing a Module where I am overwriting the function `sample` from `StatsBase.jl`.

To be able to overwrite the function `sample` I import the function in the file Modulename.jl

```julia
# import sample
import StatsBase: sample

```

And I implement my own `sample` function in another file, looking something like this

```julia

"""
    sample(inputs)

Docstring for my version of sample. 
"""
function sample(inputs)

# stuff 

end 

```

The problem is that when I view the docstring by typing

```julia
julia> ?sample 

```

I see both the docstring for my own implementation of `sample`, and the docstring for the `sample` function in`StatsBase.jl`.

Furthermore, if I type

```julia
julia> ?modulename.sample 

```

Still, both docstrings are printed.

How can I select to only show the docstring for the function `sample` that I implement in my module?

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [May 8, 2018, 8:15pm UTC](https://discourse.julialang.org/t/docstring-for-overwritten-function/10777/2 "2018-05-08T20:15:49Z")

</div>

I have no idea what the exact usage here would be, but `Docs.doc!` seems to be for exactly this sort of docstring replacement. Its code mentions that it replaces the docstring for a binding, though its documentation only says it adds a new docstring.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [May 8, 2018, 10:17pm UTC](https://discourse.julialang.org/t/docstring-for-overwritten-function/10777/3 "2018-05-08T22:17:03Z")

</div>

> [@Sam](#):
>
> To be able to overwrite the function sample I import the function

Why do you want to overwrite it? That is typically pretty bad, and may break things. If you want your own function called `sample` you can just skip importing it and defining your own. That way you will see the docstring for your function with `?ModuleName.sample`.

If you instead mean to add your own _method_ to the sample function, then you can import it and add your docstring. To query the help for just your method you can then do `?sample(args...)` where `args` are the arguments for which your method applies to.

---

<div class="post-metadata">

**Author:** ![Sam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sam/32/4101_2.png) [@Sam](https://discourse.julialang.org/u/Sam)\
**Post date:** [May 9, 2018, 8:23am UTC](https://discourse.julialang.org/t/docstring-for-overwritten-function/10777/4 "2018-05-09T08:23:15Z")

</div>

> [@fredrikekre](#):
>
> To query the help for just your method you can then do ?sample(args…)

Thank you! This did what I wanted to do.

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [July 24, 2018, 1:25pm UTC](https://discourse.julialang.org/t/docstring-for-overwritten-function/10777/5 "2018-07-24T13:25:46Z")

</div>

I’m in the case of needing to do the “pretty bad” thing, in [GitHub - JuliaRandom/RandomExtensions.jl: Extensions to the stdlib/Random module](https://github.com/rfourquet/RandomExtensions.jl). Indeed, the `rand` docstring is in one place in `Random`, instead of spread over at each method. This package updgrades the API, so I wish to replace fully the old docstring with a new one… if anyone has an idea?
