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

Module names should not be re-exported #39

Open
goerz opened this issue Feb 5, 2022 · 0 comments
Open

Module names should not be re-exported #39

goerz opened this issue Feb 5, 2022 · 0 comments

Comments

@goerz
Copy link

goerz commented Feb 5, 2022

Suppose I have

module QuantumControl
using Reexport
@reexport using QuantumControlBase
end

then if a user does using QuantumControl, they'll not just get the members of QuantumControlBase injected into their Main, but also QuantumControlBase itself. Maybe this is by design, but I can't think of any situation where I would want that (and it would break the desired behavior of my actual QuantumControl package). I think this can be fixed by changing

exported_names(m::Module) = filter!(x -> Base.isexported(m, x), names(m; all=true, imported=true))
to

function exported_names(m::Module)
    return filter!(
        x -> (Base.isexported(m, x) && (x != nameof(m))),
        names(m; all=true, imported=true)
    )
end

that is, filtering out m itself.

A possibly related problem is with sub-modules:

module QuantumControl
using Reexport
@reexport using QuantumControlBase
module Shapes
    @reexport using QuantumControlBase.Shapes
end
end

Again, the intent here is for the members of QuantumControlBase.Shapes to be re-exported from QuantumControl.Shapes. This actually doesn't reexport anything, even if I modify exported_names as described above. I think it's because QuantumControl.Shapes and QuantumControlBase.Shapes have the same Shapes name, but I don't have a full grasp on what's going on there.

I've been able to deal with my specific use case by writing my own much more trivial re-export macro. I still had to work around the issue of clashing sub-module names with some trickery. Still, I wouldn't have minded using Reexport.jl directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant