"Importing" all "exported" functionality

I would like to import a package without:

  • having the package’s symbols enter the global namespace
  • using any unexporrted functionality of the package

In other words, I would like to import package A and then use its functions as A.func() etc., but this should only work if func is exported by A. Currently, I can get all the exported symbols into the global namespace via using, I can get absolutely everything from A if I use import (which seems like too much, e.g. if A does using B internally I even get all of B’s exported functions here), or I can get a specific set of things from A using import A: func, etc. which means I have to manually specify what I want and can’t just use A’s exported symbols. Is there any way of doing what I want?

1 Like

Have you tried include?

You can wrap using inside a new module and it seems you can even use the same name. Example:

julia> module Inflate
           using Inflate
       end
Main.Inflate

julia> Inflate.InflateGzipStream
Inflate.InflateGzipStream

julia> Inflate.InflateData
ERROR: UndefVarError: InflateData not defined
Stacktrace:
 [1] getproperty(x::Module, f::Symbol)
   @ Base ./Base.jl:26
 [2] top-level scope
   @ REPL[3]:1

to be compared to

julia> import Inflate

julia> Inflate.InflateGzipStream
Inflate.InflateGzipStream

julia> Inflate.InflateData
Inflate.InflateData
10 Likes