-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
optional import of subpackages #4361
Comments
In the second form, you define two different symbols: I would suggest doing something like this: try:
import scipy.ndimage as scipy_ndimage
except ImportError:
scipy_ndimage = None
def foo():
if scipy_ndimage:
return scipy_ndimage.frobulate()
return 2 # good approximation of the frobulation algorithm without scipy Alternatively: try:
import scipy
import scipy.ndimage
except ImportError:
scipy = None
def foo():
if scipy:
return scipy.ndimage.frobulate()
return 2 # good approximation of the frobulation algorithm without scipy (It's untested and I hope it's not too far from something that would work!) |
@svenkreiss thanks for you report. |
@dbaty I didn't follow your two different symbols argument. When I import I'd argue that my original code is valid and should not fail pylint. |
I don't understand this issue, what would you want pylint to do exactly ? Not raise a |
Yes, I don't want pylint to raise this C0103. I have updated the report with the relevant part from the issue template (apologies @Pierre-Sassoulas ). |
Thank you for the clarification @svenkreiss, I'm going to close as duplicate of #3585 . |
Steps to reproduce
Pylint is happy but
scipy.ndimage
is not imported:Need the import below to make
scipy.ndimage
available, but pylint complains:Pylint:
C0103: Constant name "scipy" doesn't conform to UPPER_CASE naming style (invalid-name)
Expected behavior (updated)
When I run pylint, I want the output to be:
Context
I am making scipy an optional dependency in OpenPifPaf: openpifpaf/openpifpaf#390
The text was updated successfully, but these errors were encountered: