-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
len-as-sequence with numpy.arrays #1879
Comments
Another issue with I'm thinking pylint should only apply this check for builtin containers such as dictionaries and lists and sets |
Feel free to disable the rule locally for such constructs. If a rule works most of the time but there are libraries such as numpy that decided to have a different behaviour, then this is not an argument against the rule, but against outliers in behaviour such as these libraries. |
That's what I meant: Numpy isn't just "a library" -- it's so immensely popular that I have problems naming a Python software that doesn't use it. One can disable the rule alright if you know about the behavior, but I'd argue that most people don't. Suggesting to replace |
To be fair, pylint doesn't recommend itself as being one size fits it all. If something does not work for a particular library, it's okay to just disable the check in that area of the code of across the entire project. Supporting numpy's idiosyncrasies might be worth it, but this can get easily out of hand if we're talking about adapting every rule for every popular library out there. Also adapting a check is a completely different topic than completely removing it, as your initial comment suggested, I wouldn't go as far as removing checks just for satisfying irregularities of other software. |
Sorry to revive an old discussion, but I guess this is better than opening a new issue. This was the MWE I intended to post:
On additional argument (to the ones pointed out above) would be that PEP 8 says
So while Another solution would be for |
Hello, thank you for bringing new arguments to the table @bersbersbers. I'm reopening for three reasons:
This might require change in astroid for libs that use system libraries like numpy. |
For
pylint suggests
However, there is a difference between those two conditions above; that's because
numpy.array([0])
evaluates toFalse
. (As opposed tonumpy.array([1.121])
, for example.)Now, pylint cannot know everything about all Python modules, but numpy is so popular and the above behavior so devious that I'm wondering if
len-as-condition
should be removed entirely. In any case, the warning message should explicitly except numpy arrays.The text was updated successfully, but these errors were encountered: