Commit Graph

39 Commits

Author SHA1 Message Date
Benoit Pierre 7659c6c236 pylint: disable `too-many-positional-arguments`
Added in 3.3.0, split from `too-many-arguments`, which is disabled.
2024-09-20 15:43:26 -07:00
Eli Schwartz e343590e7d
pylint: ignore possibly/used-before-assignment as it is prone to FP
It does no control flow analysis, and upgrading to pylint 3.2.0 produced
many incorrect warnings.

Also ignore contextmanager-generator-missing-cleanup for now. It has FP
when there is no code after a yield (and thus no cleanup needs to be
handled), which is what we do. Currently under discussion upstream:
https://github.com/pylint-dev/pylint/issues/9625
2024-05-19 15:49:12 -04:00
Dylan Baker 2d349eae8c
pylint: enable the set_membership plugin
Which adds the `use-set-for-membership` check. It's generally faster in
python to use a set with the `in` keyword, because it's a hash check
instead of a linear walk, this is especially true with strings, where
it's actually O(n^2), one loop over the container, and an inner loop of
the strings (as string comparison works by checking that `a[n] == b[n]`,
in a loop).

Also, I'm tired of complaining about this in reviews, let the tools do
it for me :)
2022-11-30 16:23:29 -05:00
Dylan Baker 67da2ad0fb
pylint: enable simplifiable-if-statement 2022-11-30 07:01:22 -05:00
Dylan Baker 1502431fe9
pylint: enable use-implicit-booleaness-not-comparison 2022-11-30 07:01:22 -05:00
Dylan Baker d5e899c768
pylint: enable the bad_builtin checker
This finds uses of deny-listed functions, which defaults to map and
filter. These functions should be replaced by comprehensions in
idiomatic python because:
    1. comprehensions are more heavily optimized and are often faster
    2. They avoid the need for lambdas in some cases, which make them
       faster
    3. you can do the equivalent in one statement rather than two, which
       is faster
    4. They're easier to read
    5. if you need a concrete instance (ie, a list) then you don't have
       to convert the iterator to a list afterwards
2022-11-29 23:26:05 -05:00
Dylan Baker a5d547e0d9
pylint: enable useless-return 2022-11-29 23:26:05 -05:00
Dylan Baker 5794805f8e
pylint: enable used-before-assignment
The one case of this was a false-positive, but what we were doing
(checking locals()) is not idiomatic. I've replaced the call to
`locals()` with the obvious `var: T.Optional[str] = None` with check
instead.
2022-11-29 23:26:05 -05:00
Dylan Baker e8727fc857
pylint: enable implicit-str-concat
Which catches a very real bug. The zlib system dependency failed to work
on MSVC since initial implementation in commit
c1a3b37ab7 -- it looked for the wrong
name.
2022-11-29 22:00:12 -05:00
Dylan Baker df1b95cf2b
pylint: enable consider-merging-isinstance 2022-10-04 00:33:14 -04:00
Dylan Baker a72840cd2e
pylint: enable use-a-generator
This catches some optimization problems, mostly in the use of `all()`
and `any()`. Basically writing `any([x == 5 for x in f])` vs `any(x == 5
for x in f)` reduces the performance because the entire concrete list
must first be created, then iterated over, while in the second f is
iterated and checked element by element.
2022-10-04 00:33:04 -04:00
Dylan Baker f11ebf20ff
pylint: enable unnecessary-lambda 2022-10-03 00:16:09 -04:00
Dylan Baker 20d76b8353
pylint: enable unnecessary-comprehension 2022-10-03 00:14:43 -04:00
Dylan Baker 676e66f853
pylint: enable consider-using-(min|max)-builtin
There's only one case of each, in the same function, so I've handled
both in the same commit.
2022-10-03 00:02:20 -04:00
Dylan Baker 8c819ab805
pylint: enable unspecified-encoding 2022-10-03 00:02:02 -04:00
Dylan Baker 988a50b19c
pylint: enable unnecessary-dunder-call 2022-10-03 00:00:26 -04:00
Dylan Baker f5283dd63f pylint: enable global-statement
This does force a number of uses of `# pylint: disable` comments, but it
also finds a couple of useless global uses and one place (in the
previous commit) that an easy refactor removes the use of global. Global
is a code smell, so forcing adding a comment to disable helps force
developers to really consider if what they're doing is a good idea.
2022-09-22 18:17:43 -04:00
Dylan Baker 3ef332e89a pylint: enable global-variable-not-assigned
The `global` statement is only needed to assign to global variables, not
read or mutate them. So calling `global.mutate()` is fine, but not
`var = foo`, which would otherwise shadow `var`.
2022-09-22 18:17:43 -04:00
Dylan Baker b8e53ed5ea pylint: enable use-dict-literal 2022-09-19 20:57:52 -04:00
Dylan Baker 798b6c5624 pylint: enable use-list-literal 2022-09-19 20:57:52 -04:00
Dylan Baker 4da14918cd pylint: enable consider-using-in 2022-09-19 20:57:52 -04:00
Dylan Baker 6f7ea0cc28 pylint: enable use-sequence-for-iteration
This found a couple of places where we *don't* want to use set(), and
want to use list() instead.
2022-09-19 20:57:52 -04:00
Dylan Baker 188c552dcf pylint: enable use-maxsplit-arg
This finds a bunch of places where we can do more efficient string
splitting.
2022-09-19 20:57:52 -04:00
Dylan Baker b11cf2f371 pylint: enable consider-using-dict-items
Which found a couple of places where we could write better code.
2022-09-19 20:57:52 -04:00
Dylan Baker 6d12d7623f pylint: move from allow-list to deny-list
This makes it much easier to see what we're ignoring, as well as
allowing pylint to enforce any lints that currently pass but aren't in
the allow list automatically.
2022-09-19 20:57:52 -04:00
Dylan Baker bca6c670c3 pylintrc: add function-redefined 2021-09-24 18:48:48 -07:00
Dylan Baker 9795323b86 pylint: check for duplicate imports
I ran into one of these from LGTM, and it would be nice if pylint could
warn me as part of my local development process instead of waiting for
the CI to tell me.
2021-09-24 10:36:05 -07:00
Dylan Baker b60bd0e299 pyllint: enable consider-user-enumerate
This caught a couple of cases of us doing:
```python
for i in range(len(x)):
   v = x[i]
```
which are places to use enumerate instead.

It also caught a couple of cases of:
```python
assert len(x) == len(y)
for i in range(len(x)):
    xv = x[i]
    yv = y[i]
```
Which should instead be using zip()
```python
for xv, yv in zip(x, y):
    ...
```
2021-08-31 16:28:54 -04:00
Dylan Baker 06fdb29daa pylint: turn on superfluous parens warning
Which is really useful for catching parens used with keywords like
assert. Don't use parens with assert, it's bad.
2021-08-31 16:28:54 -04:00
Dylan Baker 278942a447 pylint: enable consider-iterating-dictionary
This didn't actually catch what it's supposed to, which is cases of:
```python
for x in dict.keys():
    y = dict[x]
```
But it did catch one unnecessary use of keys(), and one case where we
were doing something in an inefficient way. I've rewritten:
```python
if name.value in [x.value for x in self.kwargs.keys() if isinstance(x, IdNode)]:
```
as
``python
if any((isinstance(x, IdNode) and name.value == x.value) for x in self.kwargs):
```
Which avoids doing two iterations, one to build the list, and a
second to do a search for name.value in said list, which does a single
short circuiting walk, as any returns as soon as one check returns True.
2021-08-31 16:28:54 -04:00
Dylan Baker 1fc3d8608d pylint: enable unnecessary-not check
This finds things like
```python
if not x == 1:
```
which should be
```python
if x != 1:
```
2021-08-31 16:28:54 -04:00
Luke Drummond 63814543de Bare exceptions are no longer allowed [NFC]
The last instances of

    try:
        ...
    except:
        ...

were removed in bf98ffca. The sideci.yml file was updated, but the
flake8 config still allows this. Ensure that flake8 tests fail if this
questionable construct appears again.
2020-11-04 12:24:48 +02:00
Dylan Baker 8fa0548e08 pylint: turn on a few more errors 2020-09-22 17:57:03 -07:00
Dylan Baker f342efd080 pylint: turn on bad-indentation error
and fix all of the bad indentation
2020-09-22 17:57:03 -07:00
Dylan Baker 3b292a04b8 pylint: turn on warnings for abstract classes
We're using these now, so having some error checking to make sure we
don't have paths were we're trying to instantiate an abstract class
would be good.
2020-09-22 17:57:03 -07:00
Dylan Baker b034f8cf61 pylint: Turn on warnings for incorrect number of args
This catches some very real errors.

The one in scalapack is pretty silly actually, it's failing to figure
out that the exploded list is at least two arguments. However, the code
is actually clearer by not using a list and exploding it, so I've done
that and pylint is happy too.
2020-09-22 17:57:03 -07:00
Dylan Baker 007ece4659 pylint: Turn on a few more good warnings 2020-09-18 14:49:58 -07:00
Dylan Baker cb0265a6b2 pylint: Catch cases of `if len(container)` which should be replaced by `if container`
Unfortunately this doesn't catch other abuses of len(continauer) like,
`len(container) <comparator> 0`, see: https://github.com/PyCQA/pylint/issues/3751
2020-09-18 14:49:58 -07:00
Michael Hirsch, Ph.D fa38aa378e add pylint config file. update Sider CI name 2019-08-02 14:31:22 +03:00