Error with base/generic function calls

I’m having trouble with functions seemingly disappearing as I get an UndefVarError.

Specifically, in my case, the subtypes() function, although I think I encountered the same issue with DataFrames.valuecols().

I have no idea what’s going on.

If I run the below in the REPL, it works fine as expected:

using DataFrames

@info subtypes(DataFrame)
# [ Info: Type[]

function get_subtypes()
    return subtypes(DataFrame)
end

@info get_subtypes()
# [ Info: Type[]

If I put it into a file and include it, both calls works as expected

julia> include("src/subtypes.jl")
[ Info: Type[]
[ Info: Type[]

But running the file directly doesn’t work:

$ julia --project=. src/subtypes.jl
┌ Error: Exception while generating log record in module Main at c:\programs\ownCloud\projects\example_error\src\subtypes.jl:3
│   exception =
│    UndefVarError: subtypes not defined
│    Stacktrace:
│     [1] top-level scope at logging.jl:331
│     [2] include(::Function, ::Module, ::String) at .\Base.jl:380
│     [3] include(::Module, ::String) at .\Base.jl:368
│     [4] exec_options(::Base.JLOptions) at .\client.jl:296
│     [5] _start() at .\client.jl:506

And in running the actual piece of code I am working on, a call to subtypes() at the top level works, but the second call within a function errors out with no message:

[ Info: Type[]
ERROR:

This is happening on Windows 10, for both v1.5.0 and v1.4.0

EDIT: Experiencing same issue on Linux, Julia 1.5.0

Does anyone know what’s happening here?
I swear this was working a few weeks ago (I’m working with Julia on and off)

Add a
using InteractiveUtils
to your subtypes.jl
It seems this stdlib package is auto-imported in the REPL but not in general. I didn’t found anything described in the docs, but it seems to be self explaining as the name of the package is “Interactive Utilities”.

I think it is worth a PR or a issue in Issues · JuliaLang/julia · GitHub but I don’t know how often this happens and if it is really worth it. As far as I follow discussions here people do not stumble very often over this.

@oheil thanks for your response

Now that you’ve explained where it was moved, I found this post which made me think about what might be the Julian way of doing what I wanted.

In my case it was simple enough to re-conceptualize so that the following was suitable:

a isa CustomType
# true

# the above also works for subtypes of CustomType

So my direct issue is solved but I’m kind of annoyed that the documentation, with example, didn’t explicitly mention this (Reflection and introspection · The Julia Language). I feel the info is buried.

But anyway, thanks again.

Feel free to edit the documentation (link to edit is at the top of the page in the right upper corner) and create a PR (it’s straight forward and the option for a PR is presented automatically if I remember correctly). Of course it is not guaranteed that the PR is accepted. Link to this discussion for the motivation of the PR.

2 Likes

Thanks again @oheil, I’ve started a PR here:

https://github.com/JuliaLang/julia/pull/36971

1 Like