Skip to content

Commit 38b8156

Browse files
expand Docs.undocumented_names to include all public symbols (#52743)
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]>
1 parent 6934379 commit 38b8156

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ New library features
8484
write the output to a stream rather than returning a string ([#48625]).
8585
* `sizehint!(s, n)` now supports an optional `shrink` argument to disable shrinking ([#51929]).
8686
* New function `Docs.hasdoc(module, symbol)` tells whether a name has a docstring ([#52139]).
87-
* New function `Docs.undocumented_names(module; all)` returns a module's undocumented names ([#52413]).
87+
* New function `Docs.undocumented_names(module)` returns a module's undocumented public names ([#52413]).
8888
* Passing an `IOBuffer` as a stdout argument for `Process` spawn now works as
8989
expected, synchronized with `wait` or `success`, so a `Base.BufferStream` is
9090
no longer required there for correctness to avoid data races ([#52461]).

base/docs/Docs.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -676,18 +676,19 @@ end
676676

677677

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

test/docs.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ function break_me_docs end
7979
"This module has names without documentation."
8080
module _ModuleWithUndocumentedNames
8181
export f
82+
public , @foo
8283
f() = 1
84+
g() = 2
85+
(a,b) = a * b
86+
macro foo(); nothing; end
87+
(a,b) = a + b
8388
end
8489

8590
"This module has some documentation."
@@ -90,9 +95,9 @@ f() = 1
9095
g() = 2
9196
end
9297

93-
@test Docs.undocumented_names(_ModuleWithUndocumentedNames) == [:f]
98+
@test Docs.undocumented_names(_ModuleWithUndocumentedNames) == [Symbol("@foo"), :f, :]
9499
@test isempty(Docs.undocumented_names(_ModuleWithSomeDocumentedNames))
95-
@test Docs.undocumented_names(_ModuleWithSomeDocumentedNames; all=true) == [:eval, :g, :include]
100+
@test Docs.undocumented_names(_ModuleWithSomeDocumentedNames; private=true) == [:eval, :g, :include]
96101

97102

98103
# issue #11548

0 commit comments

Comments
 (0)