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
Bug pylint 4326 #1183
Bug pylint 4326 #1183
Conversation
astroid/brain/brain_numpy_utils.py
Outdated
|
||
return tuple(numpy.version.version.split(".")) | ||
except ImportError: | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we return (0, 0, 0)
? We'd get TypeError: '>' not supported between instances of 'NoneType' and 'tuple'
line 25 if we can't import numpy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely right!
@@ -341,6 +345,59 @@ def test_datetime_astype_return(self): | |||
), | |||
) | |||
|
|||
@unittest.skipUnless( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can add a small test to check that we're not crashing if numpy is'nt installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Pierre-Sassoulas i'm sorry but i don't see the point here. Can you explain a bit what you want to prevent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would have detected the problem of the other remark (TypeError: '>' not supported between instances of 'NoneType' and 'tuple'
), by having automated tests for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Pierre-Sassoulas i was thinking to add something alone the following lines:
@unittest.skipIf(HAS_NUMPY)
class NumpyBrainUtilsTest(unittest.TestCase):
def test_get_numpy_version_do_not_crash(self):
"""
Test that the function _get_numpy_version doesn't crash even if numpy is not installed
"""
self.assertEqual(_get_numpy_version(), ('0', '0', '0'))
Is it what you were thinking of? Or do you had in mind something more generic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but we could even check what we get when parsing the code without numpy (that would execute the _get_numpy_version
too, but also much more code).
7ecd80f
to
61fb19f
Compare
Steps
Description
This PR adds type hints support inside
numpy
's brains. This way subscripting of classes that inherit fromgeneric
orndarray
is possible.Type of Changes
Related Issue
Closes pylint-dev/pylint#4326