Should failure to import be an error, not a warning?

I noticed today that importing a name that’s not found in
a module is a warning. Shouldn’t this be an error?

julia> import Base: start, next, done
WARNING: could not import Base.start into Main
WARNING: could not import into Main
WARNING: could not import Base.done into Main

Yes, this example has to do with the iteration change.
However, it made me wonder about import behavior.

1 Like

I suppose there may be cases where you would want to import a function to extend it if it exists, but if it doesn’t exist create it. Usually I come down in favor of throwing errors, but I’m not too sure about this one. The fact that metaprogramming exists in Julia means that you generally want to make it as easy as possible to drop blocks of code in and out of modules. Another question is if this is really an intended use case, why even throw the warning.

If you imported a function just to use it and not to extend it, indeed this will result in your code breaking. However, you’ll already get an error wherever you try to use the function you tried and failed to import, so I suppose the developers figured there was no point in preemptively throwing an error here.