Skip to content

Feature request: Base.@public macro for declaring a public name without needing to export it #42117

Closed
@DilumAluthge

Description

@DilumAluthge

Summary

I would like to give package developers a way to declare names that are part of their package's public API without needing to export them.

This feature request has two parts:

  1. The Base.@public macro, which declares a name as public without exporting it.
  2. The Base.public_not_exported(m::Module)::Vector{Symbol} function, which returns the list of all non-exported public names in the module m.

This feature request is non-breaking. Therefore, it can be implemented in a Julia 1.x release.

Part 1: Base.@public macro

For example, suppose that my package has a public function named fit. Because that word is so common, I don't want to export it from my package. But I want to indicate that it is part of the public API in a structured way that downstream tools (Documenter.jl, JuliaHub, editors/IDEs, etc.) can understand.

So in this example, I could do something like the following:

module Foo

export cool_stuff # public and exported 
@public fit       # public but not exported 

function cool_stuff end
function fit end

function private_stuff end # private 

end # module

Part 2:Base.public_not_exported function

The signature of the function will be: Base.public_not_exported(m::Module)::Vector{Symbol}.

Example usage:

julia> Base.public_not_exported(Foo)
1-element Vector{Symbol}:
 :fit

Related Discussions

There is some related discussion in JuliaDocs/Documenter.jl#1507. However, I really want this to be something that any tool can use, so I don't want it to be specific to Documenter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    designDesign of APIs or of the language itselfmodulespackagesPackage management and loading

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions