Skip to content
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

Merged
merged 8 commits into from Oct 5, 2021
Merged

Bug pylint 4326 #1183

merged 8 commits into from Oct 5, 2021

Conversation

hippo91
Copy link
Contributor

@hippo91 hippo91 commented Sep 18, 2021

Steps

  • For new features or bug fixes, add a ChangeLog entry describing what your PR does.
  • Write a good description on what the PR does.

Description

This PR adds type hints support inside numpy's brains. This way subscripting of classes that inherit from generic or ndarray is possible.

Type of Changes

Type
🐛 Bug fix

Related Issue

Closes pylint-dev/pylint#4326


return tuple(numpy.version.version.split("."))
except ImportError:
return None
Copy link
Member

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.

Copy link
Contributor Author

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(
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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).

@Pierre-Sassoulas Pierre-Sassoulas added the Brain 🧠 Needs a brain tip label Sep 19, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.8.1 milestone Sep 19, 2021
@cdce8p cdce8p added the pylint-tested PRs that don't cause major regressions with pylint label Sep 19, 2021
@cdce8p cdce8p removed their request for review September 19, 2021 21:59
@Pierre-Sassoulas Pierre-Sassoulas merged commit 1419ac5 into pylint-dev:main Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Brain 🧠 Needs a brain tip pylint-tested PRs that don't cause major regressions with pylint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Minor bug: np.number is not subscriptable
3 participants