# Exporting symbols of imported module

**URL:** <https://discourse.julialang.org/t/exporting-symbols-of-imported-module/19651>\
**Category:** General Usage\
**Created:** [January 15, 2019, 8:51am UTC](https://discourse.julialang.org/t/exporting-symbols-of-imported-module/19651 "2019-01-15T08:51:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [January 15, 2019, 8:51am UTC](https://discourse.julialang.org/t/exporting-symbols-of-imported-module/19651/1 "2019-01-15T08:51:42Z")

</div>

Suppose I write a module `A` that imports another module `B` but I want users that do `using A` to also have access of symbols exported from `B`.  
If I do

```julia
module B
import A
export A.x
end

```

then I get

```julia
ERROR: LoadError: syntax: extra token "." after end of expression

```

Is there any workaround ?

See [Decide what to export · Issue #1761 · jump-dev/JuMP.jl · GitHub](https://github.com/JuliaOpt/JuMP.jl/issues/1761#issuecomment-454301357) for the context.

---

<div class="post-metadata">

**Author:** ![c42f](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c42f/32/52842_2.png) [@c42f](https://discourse.julialang.org/u/c42f)\
**Post date:** [January 15, 2019, 10:11am UTC](https://discourse.julialang.org/t/exporting-symbols-of-imported-module/19651/2 "2019-01-15T10:11:21Z")

</div>

Yes:

```julia
julia> module A
       foo() = 42
       end
Main.A

julia> module B
       import ..A # Would be simply `import A` if A were in the load path rather than in Main
       const foo = A.foo
       export foo
       end
Main.B

julia> using .B

julia> foo()
42

```

Note that this is better than the alternative of `import A: foo; export foo` because it allows tab completion of `A.<TAB>` to work. (A binding must not be marked as imported-from-another-module for tab completion to consider it.)

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [January 15, 2019, 8:49pm UTC](https://discourse.julialang.org/t/exporting-symbols-of-imported-module/19651/3 "2019-01-15T20:49:38Z")

</div>

Thank you for your answer. However, I would like to export all symbols exported by `A` (like what could be done by `@reexport import A` if Reexport were to support this syntax). With your solution, this would mean doing `import A; const foo = A.foo` for all symbols exported by `A` which is equivalent to `using A`. Is it possible to do it without making the symbols of `A` accessible inside module `B` ?

---

<div class="post-metadata">

**Author:** ![c42f](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c42f/32/52842_2.png) [@c42f](https://discourse.julialang.org/u/c42f)\
**Post date:** [January 15, 2019, 9:33pm UTC](https://discourse.julialang.org/t/exporting-symbols-of-imported-module/19651/4 "2019-01-15T21:33:49Z")

</div>

> [@blegat](#):
>
> Is it possible to do it without making the symbols of `A` accessible inside module `B`

Not that I’m aware of.

Why do you want to do this? It seems a little odd to decide that the user wants those symbols after doing `using B`, even though they’re never available within B.

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [January 15, 2019, 10:33pm UTC](https://discourse.julialang.org/t/exporting-symbols-of-imported-module/19651/5 "2019-01-15T22:33:16Z")

</div>

For a JuMP extension like SumOfSquares, we would like to user to only have to do `using SumOfSquares` and not `using SumOfSquares, JuMP` hence we are doing `@reexport using JuMP` (see [Reexport JuMP by blegat · Pull Request #68 · jump-dev/SumOfSquares.jl · GitHub](https://github.com/JuliaOpt/SumOfSquares.jl/pull/68)).  
However, we would like to recommend all non-“throw-away script” to do `import JuMP` instead of `using JuMP` (see [style point on using vs import by mlubin · Pull Request #1778 · jump-dev/JuMP.jl · GitHub](https://github.com/JuliaOpt/JuMP.jl/pull/1778)).  
Hence we would like to do `import JuMP` in JuMP extensions but also reexport all JuMP symbols (see [Decide what to export · Issue #1761 · jump-dev/JuMP.jl · GitHub](https://github.com/JuliaOpt/JuMP.jl/issues/1761#issuecomment-454301357)).

---

<div class="post-metadata">

**Author:** ![c42f](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c42f/32/52842_2.png) [@c42f](https://discourse.julialang.org/u/c42f)\
**Post date:** [January 16, 2019, 4:36am UTC](https://discourse.julialang.org/t/exporting-symbols-of-imported-module/19651/6 "2019-01-16T04:36:32Z")

</div>

Looking at the code, I think there’s no way to “export without import” because `using` brings in _bindings from the source module_ which have the `exportp` flag set:

> <https://github.com/JuliaLang/julia/blob/7004841d418ab42fadddbbd0b4a4b9a8ca8e7054/src/module.c#L429>

seems reasonable enough.
