Skip to content

Commit

Permalink
expand Docs.undocumented_names to include all public symbols (#52743)
Browse files Browse the repository at this point in the history
Expands the semantics of `Docs.undocumented_names` to include all public
symbols, as described in
#52413 (comment)

cc @jariji, @LilithHafner

---------

Co-authored-by: Lilith Orion Hafner <[email protected]>
  • Loading branch information
stevengj and LilithHafner authored Jan 4, 2024
1 parent 6934379 commit 38b8156
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ New library features
write the output to a stream rather than returning a string ([#48625]).
* `sizehint!(s, n)` now supports an optional `shrink` argument to disable shrinking ([#51929]).
* New function `Docs.hasdoc(module, symbol)` tells whether a name has a docstring ([#52139]).
* New function `Docs.undocumented_names(module; all)` returns a module's undocumented names ([#52413]).
* New function `Docs.undocumented_names(module)` returns a module's undocumented public names ([#52413]).
* Passing an `IOBuffer` as a stdout argument for `Process` spawn now works as
expected, synchronized with `wait` or `success`, so a `Base.BufferStream` is
no longer required there for correctness to avoid data races ([#52461]).
Expand Down
19 changes: 10 additions & 9 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -676,18 +676,19 @@ end


"""
undocumented_names(mod::Module; all=false)
undocumented_names(mod::Module; private=false)
Return an array of undocumented symbols in `module` (that is, lacking docstrings).
`all=false` returns only exported symbols; whereas `all=true` also includes
non-exported symbols, following the behavior of [`names`](@ref). Only valid identifiers
are included. Names are returned in sorted order.
Return a sorted vector of undocumented symbols in `module` (that is, lacking docstrings).
`private=false` (the default) returns only identifiers declared with `public` and/or
`export`, whereas `private=true` returns all symbols in the module (excluding
compiler-generated hidden symbols starting with `#`).
See also: [`names`](@ref), [`Docs.hasdoc`](@ref), [`Base.isidentifier`](@ref).
See also: [`names`](@ref), [`Docs.hasdoc`](@ref), [`Base.ispublic`](@ref).
"""
function undocumented_names(mod::Module; all::Bool=false)
filter!(names(mod; all)) do sym
!hasdoc(mod, sym) && Base.isidentifier(sym)
function undocumented_names(mod::Module; private::Bool=false)
filter!(names(mod; all=true)) do sym
!hasdoc(mod, sym) && !startswith(string(sym), '#') &&
(private || Base.ispublic(mod, sym))
end
end

Expand Down
9 changes: 7 additions & 2 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ function break_me_docs end
"This module has names without documentation."
module _ModuleWithUndocumentedNames
export f
public , @foo
f() = 1
g() = 2
(a,b) = a * b
macro foo(); nothing; end
(a,b) = a + b
end

"This module has some documentation."
Expand All @@ -90,9 +95,9 @@ f() = 1
g() = 2
end

@test Docs.undocumented_names(_ModuleWithUndocumentedNames) == [:f]
@test Docs.undocumented_names(_ModuleWithUndocumentedNames) == [Symbol("@foo"), :f, :]
@test isempty(Docs.undocumented_names(_ModuleWithSomeDocumentedNames))
@test Docs.undocumented_names(_ModuleWithSomeDocumentedNames; all=true) == [:eval, :g, :include]
@test Docs.undocumented_names(_ModuleWithSomeDocumentedNames; private=true) == [:eval, :g, :include]


# issue #11548
Expand Down

0 comments on commit 38b8156

Please sign in to comment.