← Back to context

Comment by zbentley

3 days ago

...crash?

Seriously: crash if your dependencies aren't available. There are better ways to do optional dependencies. ImportError ain't it.

What is the right way to handle an optional dependency?

  • I think this import flow tends to be the canonical one.

    I might recommend doing something like importing from something like `numpy.version` (or some other "random" very small utils package) so that the work done on file load is still fairly small.

    • Common? Yes. Canonical/ideal? No. Optional dependency specifiers in your package metadata is a much better way to go. You can use those even if you don't publish your package as an artifact; `pip install -e .[optional-thing]` should work, or can be made to, easily.

      1 reply →

    • It's not clear such a thing even exists in general though. It's certainly not guaranteed by packages.

      What would that be for numba?

      1 reply →