I know about Base.names, however it ignores all the variables which are imported via using.
Is there a function which also includes these?
Or is there a way to tell whether a module was imported like using DataFrames? Then I could apply names once again to get the exported names of these imported packages and add them
EDIT: I just realized that when using using DataFrames, then :DataFrames itself is also not part of names.
(Note that names itself does not print anything — it returns an array of the symbols. When you evaluate this in the REPL, it calls display(...) on the return value, which prints the text output as above. You can also call display or print or some other I/O function yourself on the return value.)
julia> module A using Statistics end; # avoid Main because treated specially
julia> names(A; all=true,imported=true)
5-element Vector{Symbol}:
Symbol("#eval")
Symbol("#include")
:A
:eval
:include
julia> module A import Statistics end; # avoid Main because treated specially
WARNING: replacing module A.
julia> names(A; all=true,imported=true)
6-element Vector{Symbol}:
Symbol("#eval")
Symbol("#include")
:A
:Statistics
:eval
:include
julia> module A using Statistics: Statistics, mean; s = mean(1:5) + Statistics.var(1:3) end; # avoid Main because treated specially
WARNING: replacing module A.
julia> names(A; all=true, imported=true)
6-element Vector{Symbol}:
Symbol("#eval")
Symbol("#include")
:A
:eval
:include
:s
julia> module A import Statistics: Statistics, mean; s = mean(1:5) + Statistics.var(1:3) end; # avoid Main because treated specially
WARNING: replacing module A.
julia> names(A; all=true, imported=true)
8-element Vector{Symbol}:
Symbol("#eval")
Symbol("#include")
:A
:Statistics
:eval
:include
:mean
:s
Is there a good reason for this? I’m surprised that names imported by import and using are even delineated so strictly because colon-specified names and the module names in bare using/import statements can’t be shadowed like the export list names accessed by bare using statements. I’d consider the former to be essentially explicit imports, and like schlictsanders I think they should be reported by the imported=true option, especially the modules in bare using statements because I’d need to use names to check their export lists the most. I’d also prefer if the imported=true option reported any names from bare using statements after they were accessed and thus made unshadowable, but those imports don’t seem explicit in any sense.
I guess the basic issue here is that people mostly use names to obtain the API defined in a module, and it’s rare that they want to pull in 1000+ additional symbols defined in Base etcetera. But it would be nice to have that option.
That link doesn’t involve imports, but do you mean how function names from import statements don’t need module name qualification to add methods?
That’s true, I’d probably just want to check the already accessed, implicitly imported symbols at the most. Still, I’d think using Base itself should let Base show up, and using Base: +, ^ should let + and ^ show up, just like if I used the import keyword. Those don’t risk unintended bloat. Those 1000+ symbols can be checked with names(Base), so if names(A;imported=true) reported Base, that’ll be enough for me to know what to check further. Or perhaps bare using Base should be reported under another keyword option for that purpose, it’s not like I need to check names(+).