Skip to content

Commit

Permalink
document module docstring scope (#54429)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpapp committed May 25, 2024
1 parent 951cd19 commit d8f37c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 14 additions & 4 deletions doc/src/manual/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,20 @@ end
Adds docstring `"..."` to the `Module` `M`. Adding the docstring above the `Module` is the preferred
syntax, however both are equivalent.

The module docstring is evaluated *inside* the scope of the module, allowing
access to all the symbols defined in and imported into the module:

```julia
"The magic number is $(MAGIC)."
module DocStringEval
const MAGIC = 42
end
```

Documenting a `baremodule` by placing a docstring above the expression automatically imports
`@doc` into the module. These imports must be done manually when the module expression is not
documented:

```julia
"..."
baremodule M
Expand All @@ -527,10 +541,6 @@ f(x) = x
end
```

Documenting a `baremodule` by placing a docstring above the expression automatically imports
`@doc` into the module. These imports must be done manually when the module expression is not
documented.

### Global Variables

```julia
Expand Down
4 changes: 2 additions & 2 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ module NoDocStrings end
# General tests for docstrings.

const LINE_NUMBER = @__LINE__() + 1
"DocsTest"
"DocsTest, evaluating $(K)" # test that module docstring is evaluated within module
module DocsTest

using Markdown
Expand Down Expand Up @@ -265,7 +265,7 @@ fnospecialize(@nospecialize(x::AbstractArray)) = 2
end

let md = meta(DocsTest)[@var(DocsTest)]
@test docstrings_equal(md.docs[Union{}], doc"DocsTest")
@test docstrings_equal(md.docs[Union{}], doc"DocsTest, evaluating K")
# Check that plain docstrings store a module reference.
# https://github.com/JuliaLang/julia/pull/13017#issuecomment-138618663
@test md.docs[Union{}].data[:module] == DocsTest
Expand Down

2 comments on commit d8f37c9

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

Please sign in to comment.