Extending functions from implicit dependencies

It’s better to depend on the interface package directly, and import it as a normal package. Importing it “through” another package (like using KrylovKit.VectorInterface) is often actually using internal implementation details of the package (KrylovKit). Here, the assumption is that VectorInterface is in the namespace of the module KrylovKit - perhaps someday they could reorganize things so VectorInterface is only loaded in some submodule or package extension. In that case, your code would break if it assumes KrylovKit.VectorInterface exists.

Adding it as a direct dependency is also important so you can manage compatibility bounds. If VectorInterface has a breaking change, KrylovKit could update to accommodate the changes without itself making a breaking change. But your code might break. So it is better to set compatibility bounds with VectorInterface directly.

Lastly, there’s basically no cost to it. If the package would have to be loaded anyway (since KrylovKit needs it), you adding it as a direct dependency doesn’t add any load time etc.

Note: I don’t actually know anything about KrylovKit / VectorInterface specifically, I’m just using it as the example.

5 Likes