JuliaLang / JuliaLang/Reexport.jl

Module names should not be re-exported

Open
#39 2 comments 5 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
171
Forks
19
PR merge metrics
No merged PRs in 30d

Description

Suppose I have
```julia
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](https://github.com/JuliaQuantumControl/QuantumControl.jl) package). I think this can be fixed by changing https://github.com/simonster/Reexport.jl/blob/f0d5b25255bcdb365b8c0ac289d1059f602cf32b/src/Reexport.jl#L48 to
```julia
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:

```julia
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](https://github.com/JuliaQuantumControl/QuantumControl.jl/blob/master/src/reexport.jl). I still had to [work around the issue of clashing sub-module names with some trickery](https://github.com/JuliaQuantumControl/QuantumControl.jl/blob/37d682a662d25c4c34832ed9ec0b8b2670aa8b0d/src/QuantumControl.jl#L10-L18). Still, I wouldn't have minded using Reexport.jl directly

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.