# Syntax for import from parent module

**URL:** <https://discourse.julialang.org/t/syntax-for-import-from-parent-module/434>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 19, 2016, 4:43pm UTC](https://discourse.julialang.org/t/syntax-for-import-from-parent-module/434 "2016-11-19T16:43:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 19, 2016, 4:43pm UTC](https://discourse.julialang.org/t/syntax-for-import-from-parent-module/434/1 "2016-11-19T16:43:29Z")

</div>

consider this MWE:

```julia
module Foo

macro id(expr)
    expr
end

module Bar

import Foo: @id # how to refer to parent here without naming it?

@id(1+1)

end

end

```

Is it possible to import a symbol from the parent module without referring to that module by name? Eg with some syntax that involves `..` or similar.

My use case: use the same function in submodules.

A workaround is putting these in a module, eg

```julia
module Foo

module Util

macro id(expr)
    expr
end

end

module Bar

import ..Util: @id # how to refer to parent here without naming it?

@id(1+1)

end

end

```

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihnorton/32/26_2.png) [@ihnorton](https://discourse.julialang.org/u/ihnorton)\
**Post date:** [November 19, 2016, 8:57pm UTC](https://discourse.julialang.org/t/syntax-for-import-from-parent-module/434/2 "2016-11-19T20:57:38Z")

</div>

> [@Tamas\_Papp](#):
>
> Is it possible to import a symbol from the parent module without referring to that module by name? Eg with some syntax that involves … or similar.

```julia
import ..@id

```

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [March 29, 2020, 1:34pm UTC](https://discourse.julialang.org/t/syntax-for-import-from-parent-module/434/3 "2020-03-29T13:34:34Z")

</div>

Sorry to revive an old topic.

Is there something one can do to import a function from the parent of the parent module? E.g.:

```julia
module A
  f(x) = 2
  module B
    module C
      # I want to call f here
    end # module C
  end # module B
end # module A

```

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [March 29, 2020, 2:15pm UTC](https://discourse.julialang.org/t/syntax-for-import-from-parent-module/434/4 "2020-03-29T14:15:33Z")

</div>

The following works:

```julia
module A
  f(x) = 2
  module B
    import ..f
    module C
      import ..f
      f(1)
    end # module C
  end # module B
end # module A

```

So I have to import `f` into `B` first, and then into `C`.

Is there a better way?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [March 29, 2020, 4:52pm UTC](https://discourse.julialang.org/t/syntax-for-import-from-parent-module/434/5 "2020-03-29T16:52:34Z")

</div>

MOAR DOTS

```julia
julia> module A
         f(x) = 2
         module B
           module C
             import ...f
             f(1)
           end # module C
         end # module B
       end # module A
Main.A

julia> A.B.C.f(1)
2

```

---

<div class="post-metadata">

**Author:** ![Xing\_Shi\_Cai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xing_shi_cai/32/14128_2.png) [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)\
**Post date:** [May 9, 2020, 9:26pm UTC](https://discourse.julialang.org/t/syntax-for-import-from-parent-module/434/6 "2020-05-09T21:26:31Z")

</div>

What about `using` instead of `import`? How can I refer to the parent module in `using`?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 10, 2020, 6:07am UTC](https://discourse.julialang.org/t/syntax-for-import-from-parent-module/434/7 "2020-05-10T06:07:55Z")

</div>

~~Same way as for `import`. Please do read the manual, all of this is documented.~~ EDIT: sorry, I misunderstood the question. AFAIK it is not supported at the moment.

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [May 10, 2020, 6:42am UTC](https://discourse.julialang.org/t/syntax-for-import-from-parent-module/434/8 "2020-05-10T06:42:38Z")

</div>

Is it?

```julia
julia> module A
         f(x) = 2
         module B
           module C
             using ...f
             f(1)
           end # module C
         end # module B
       end # module A
ERROR: invalid using path: "f" does not name a module

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 10, 2020, 7:24am UTC](https://discourse.julialang.org/t/syntax-for-import-from-parent-module/434/9 "2020-05-10T07:24:48Z")

</div>

I think that’s unfortunately

[https://github.com/JuliaLang/julia/issues/29131#issuecomment-420525223](https://github.com/JuliaLang/julia/issues/29131#issuecomment-420525223)
