-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raise ModuleNotFoundError when unavailable #290
Raise ModuleNotFoundError when unavailable #290
Conversation
Hello @akihironitta! Thanks for updating this PR. There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-10-22 16:14:00 UTC |
Codecov Report
@@ Coverage Diff @@
## master #290 +/- ##
==========================================
- Coverage 82.06% 81.94% -0.12%
==========================================
Files 97 98 +1
Lines 5441 5501 +60
==========================================
+ Hits 4465 4508 +43
- Misses 976 993 +17
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@akihironitta could you please explore @awaelchli recommendation about importing without try/catch |
@Borda Thanks for reviewing as always! if importlib.util.find_spec("some_package") is not None:
from some_package import my_function and after that, Lightning-AI/pytorch-lightning#2877 tried implementing Is there a preferred way of importing optional packages without try/catch? Should I wait for Lightning-AI/pytorch-lightning#2877 to get merged or directly use Lightning-AI/pytorch-lightning#2266 (comment)? |
@akihironitta SKLEARN_AVAILABLE = importlib.util.find_spec("some_package") is not None and then wherever you need it: if SKLEARN_AVAILABLE:
# import something, warn or raise This is my recommendation when you need a variable telling you if the package is available without the need to actually import it. Hope this helps. |
@awaelchli Thank you for the suggestion! I'll start using |
Before submitting
What does this PR do?
Fixes #265.
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.
Did you have fun?
Make sure you had fun coding 🙃