Reputation: 14786
I'm writing a function to help with an optional dependency (similar to pytest.importorskip) and I'd like to type it, but unsure what type to use. Since I'm always returning a specific module or None, I think I can be more specific than "Any".
def try_import_pyarrow():
try:
import pyarrow
except ImportError:
pyarrow = None
return pyarrow
Upvotes: 2
Views: 991