Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docs.undocumented_names #52413

Merged
merged 17 commits into from
Dec 31, 2023
Merged

Add Docs.undocumented_names #52413

merged 17 commits into from
Dec 31, 2023

Conversation

jariji
Copy link
Contributor

@jariji jariji commented Dec 5, 2023

Fixes #51174

Cross-ref: #52139

@jariji
Copy link
Contributor Author

jariji commented Dec 6, 2023

@stevengj ready for review.

@brenhinkeller brenhinkeller added the docsystem The documentation building system label Dec 8, 2023
base/docs/Docs.jl Outdated Show resolved Hide resolved
@stevengj
Copy link
Member

stevengj commented Dec 8, 2023

I suspect we don’t want a function that throws an error here. We probably just want a function that returns a sorted list of undocumented symbols. Then people can just add tests like

@test Docs.undocumented_names(MyMod) == [:known1, :known2]
@test_broken Docs.undocumented_names(MyMod2) == []

base/docs/Docs.jl Outdated Show resolved Hide resolved
base/docs/Docs.jl Outdated Show resolved Hide resolved
stevengj and others added 2 commits December 16, 2023 09:30
Co-authored-by: Steven G. Johnson <stevenj@mit.edu>
@jariji
Copy link
Contributor Author

jariji commented Dec 18, 2023

Expression: Docs.undocumented_names(_ModuleWithSomeDocumentedNames; all = true) == [:g]
   Evaluated: [Symbol("##meta#47"), Symbol("#eval"), Symbol("#f"), Symbol("#g"), Symbol("#include"), :eval, :g, :include] == [:g]

What should happen here? @stevengj

@stevengj
Copy link
Member

Symbol("##meta#47"), Symbol("#eval"), Symbol("#f"), Symbol("#g"), Symbol("#include") are internal names generated by Julia's compiler.

For now, if you want to check the all=true case, I would filter the symbols for !Base.isidentifier to avoid involving compiler internals in the test. In the future, we may want to add an isidentifier::Bool=false option to names as well as this function in order to filter out non-identifier symbols by default.

base/docs/Docs.jl Outdated Show resolved Hide resolved
test/docs.jl Outdated Show resolved Hide resolved
Co-authored-by: Steven G. Johnson <stevenj@mit.edu>
base/docs/Docs.jl Outdated Show resolved Hide resolved
@jariji jariji changed the title Add Docs.check_documented Add Docs.undocumented_names Dec 19, 2023
@jariji
Copy link
Contributor Author

jariji commented Dec 19, 2023

idk what that failure is.

@jariji
Copy link
Contributor Author

jariji commented Dec 31, 2023

This is ready for merge.

@IanButterworth IanButterworth merged commit 1b183b9 into JuliaLang:master Dec 31, 2023
7 checks passed
@LilithHafner
Copy link
Member

Sorry I'm a little late here; I'm not sure implementing this function in Base.Docs is a good idea. It seems like the kind of functionality that is used in development and testing but not in ordinary usage. Consequently, I think it belongs in Test or Aqua where it can be implemented in terms of Base's existing public API (thanks to @jariji's #52139) My opinion here is pretty weak, and I'd be open to possibly keeping it here, but I do think this should be discussed before we commit to adding this public API to Base.Docs

Regardless of the above, we should fix the docstring which currently misrepresents the behavior on undocumetned public but unexported symbols. (IIUC docstring: they are not returned by default; reality: they are returned by default)

@LilithHafner LilithHafner added the triage This should be discussed on a triage call label Dec 31, 2023
@LilithHafner
Copy link
Member

Clarification: IMO having this functionality is definitely a good idea, the question is where to have it.

@stevengj stevengj mentioned this pull request Jan 3, 2024
@stevengj
Copy link
Member

stevengj commented Jan 3, 2024

If it goes anywhere else, it should be in Test (not Aqua) so that it can be used to test Base modules and stdlibs. (That was my initial suggestion from #51174.) I don't remember why we didn't discuss it here, sorry.

@stevengj
Copy link
Member

stevengj commented Jan 3, 2024

I think the argument to put it in Docs was due to @Seelengrab in #51174 (comment) … it was basically about adding a dependency on Docs to Test, when this function doesn't actually use anything in Test:

Why should Test depend on Docs for something that is purely Docs functionality? Either having that in Docs or in an extension of Test weakly depending on Docs would be fine IMO.

(Though since the Docs module is in Base I don't really get this argument?)

If we put it in Test, we might want to simply export it.

@Seelengrab
Copy link
Contributor

Seelengrab commented Jan 3, 2024

You're right, having Docs be a part of Base means the dependency is a non-issue code-loading wise.

Still, the thought was that undocumented_names is not inherently related to testing functionality; there's a lot of things you could do with this (e.g. mark those names specially in Documenter, Pluto, some other tool) that aren't related to unit testing at all. Forcing that code to depend on Test in addition to Docs when the rest of the functionality of Test is not needed seems odd to me.

@jariji jariji deleted the patch-3 branch January 3, 2024 19:28
"""
function undocumented_names(mod::Module; all::Bool=false)
filter!(names(mod; all)) do sym
!hasdoc(mod, sym) && Base.isidentifier(sym)
Copy link
Member

@stevengj stevengj Jan 3, 2024

Choose a reason for hiding this comment

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

I just realized that this filters out macro symbols @foo, which we don't want to exclude. Probably should be

str = string(sym)
!hasdoc(mod, sym) && (Base.isidentifier(sym) || (startswith(str, "@") && Base.isidentifier(str[2:end])))

@DilumAluthge
Copy link
Member

Similar to the argument that I make in #52724, I think that we should rename Docs.undocumented_names to something a bit more specific and less ambiguous, to clarify that we are talking about names without docstrings.

I've opened #52726, which proposes renaming it to Docs.names_without_docstring, but I'm open to other names as well.

@LilithHafner
Copy link
Member

LilithHafner commented Jan 4, 2024

From the dregs of triage (Lilith, Jeff, Jar) after most folks left:

Base.Docs is a fine place for this functionality to go. It's nontrivial to get right, so worth implementing, and it's needed by Base, so worth putting in Base/Docs/Test. It can be used even in the absence of testing, so shouldn't be in Test.

undocumented_names is a reasonable name. The only thing that "documented" could mean, from Base.Docs's perspective, is "has a docstring" because Base.Docs doesn't know about the manual or any Documenter.jl stuff.

_is_hidden_name(s::Symbol) = !isempty(string(x)) && string(x)[1] == '#'

And use this semantic for Docs.undocumented_names(mod; private=false):
For private=false, default: filter(x -> !Base.Docs.hasdoc(mod, x) && !_is_hidden_name(x) && Base.ispublic(mod, x), names(mod, all=true))
For private=true: filter(x -> !Base.Docs.hasdoc(mod, x) && !_is_hidden_name(x), names(mod, all=true))

Following the pattern of names which has keywords that default to false and setting them to true adds more names to be returned.

@LilithHafner LilithHafner removed the triage This should be discussed on a triage call label Jan 4, 2024
LilithHafner added a commit that referenced this pull request Jan 4, 2024
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 <lilithhafner@gmail.com>
stevengj added a commit that referenced this pull request Jan 14, 2024
Following #52413 by @jariji and the discussion in #51174, this adds
tests to ensure that there are no undocumented *(= lacking docstrings)*
public symbols in any documented module.

Many of the tests are broken — we have a lot of undocumented exports. In
such cases I added both a `@test_broken` and a `@test` to ensure that
there are no additional regressions added in the future.

~~(This PR may have to be updated when
#52413 (comment) is
fixed, i.e. when ~~#52727~~ #52743 is merged.)~~ Has been updated.

---------

Co-authored-by: Lilith Orion Hafner <lilithhafner@gmail.com>
KristofferC pushed a commit to JuliaLang/LinearAlgebra.jl that referenced this pull request Nov 14, 2024
Following #52413 by @jariji and the discussion in #51174, this adds
tests to ensure that there are no undocumented *(= lacking docstrings)*
public symbols in any documented module.

Many of the tests are broken — we have a lot of undocumented exports. In
such cases I added both a `@test_broken` and a `@test` to ensure that
there are no additional regressions added in the future.

~~(This PR may have to be updated when
JuliaLang/julia#52413 (comment) is
fixed, i.e. when ~~#52727~~ #52743 is merged.)~~ Has been updated.

---------

Co-authored-by: Lilith Orion Hafner <lilithhafner@gmail.com>
KristofferC pushed a commit to JuliaLang/SharedArrays.jl that referenced this pull request Dec 4, 2024
Following #52413 by @jariji and the discussion in #51174, this adds
tests to ensure that there are no undocumented *(= lacking docstrings)*
public symbols in any documented module.

Many of the tests are broken — we have a lot of undocumented exports. In
such cases I added both a `@test_broken` and a `@test` to ensure that
there are no additional regressions added in the future.

~~(This PR may have to be updated when
JuliaLang/julia#52413 (comment) is
fixed, i.e. when ~~#52727~~ #52743 is merged.)~~ Has been updated.

---------

Co-authored-by: Lilith Orion Hafner <lilithhafner@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docsystem The documentation building system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add a way to test whether exported symbols are documented
7 participants