-
Notifications
You must be signed in to change notification settings - Fork 183
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
Python3 linter #3194
Comments
I think the following rules should always be enforced:
The following rules should be run manually and periodically by maintainers to detect candidates for cleanup or refactoring:
To enable all rules except those failing on Cython or making too much noise: Other rules could pick up on PEP8 issues that are not properly handled by
|
Rule |
|
3203: Code cleanup with pylint r=KaiSzuttor a=jngrad Follow-up to #3194 Description of changes: - remove unused imports - rewrite wildcard imports as explicit imports - replace mutable optional parameters by immutable equivalents - fix LB thermostat checkpointing mechanism - cleanup and simplify conditional statements - refactor code with numpy and new espresso methods - remove unused variables/arguments - rename unused loop variables from `i` to `_` - fix broken numpy commands in parts of the testsuite that aren't executed - remove trailling whitespaces Co-authored-by: Jean-Noël Grad <[email protected]> Co-authored-by: Kai Szuttor <[email protected]>
With espresso/testsuite/python/h5md.py Lines 28 to 30 in 8e549ad
becomes: import espressomd # isort:skip; pylint: disable=import-error, wrong-import-order
import h5py # isort:skip; pylint: disable=wrong-import-order; h5py has to be imported *after* espressomd (MPI)
from espressomd.interactions import Virtual # isort:skip; pylint: disable=wrong-import-order,ungrouped-imports |
i fully agree with this list, plus I would add:
@RudolfWeeber please comment on this aswell. |
I think there are quite a few trivial style checks in that list.
I'm fine with the ones actually preventing dangerous stuff.
> I think the following rules should always be enforced:
* `W1505`: deprecated `assertRaisesRegexp()`
This is quite common in the test suite.
* `R1701`: merge type checks: `isinstance(x, y) or isinstance(x, z)` to `isinstance(x, (y, z))`
Not dangerous.
* `R1714`: merge value checks: `if x == 1 or x == 2:` to `if x in (1, 2):`
Not dangerous
* `C0201`: iterate dict keys directly
Not dangerous.
* `C0202`: use `cls` instead of `self` in class methods
Not dangerous
* `C0325`: superfluous parentheses: `if(a == 2):` to `if a == 2:`
Dangerous
i fully agree with this list, plus I would add:
* `W0612`: unused variable
* `W0613`: unused arguments
I agree with those, since authors might expect changed behavior when changing a variable's value.
* `C1801`: simplify empty list checks: `if len(seq) > 0:` to `if seq:`
Not dangerous. In fact I find the 'if seq' more dangerous, because it will do something else if seq is not a sequence.
The others are fine with me.
|
so to summarize, we agree on the following rules:
|
Maybe one more: Maybe one less: The corresponding pylint command would be: @RudolfWeeber have you accidentally exchanged two items in your reply above? Specifically:
I don't immediately see how class A():
property = "before"
@classmethod
def foo(self, new_value):
self.property = new_value # this is not actually self!!
a = A()
b = A()
print(a.property) # "before"
print(b.property) # "before"
a.foo("after")
print(a.property) # "after"
print(b.property) # "after" |
@jngrad, the "not" in "not dangerous" went missing for |
This issue needs merging #3267 first. |
removing
|
versions of pylint found in the Ubuntu repositories have an outdated command line interface |
3279: Replaced some manual memory allocations r=jngrad a=reinaual Partially adresses #2900 3293: Re-enable pylint in CI r=fweik a=jngrad Fixes #3194 Rules: `W0102,W0401,W0611,W0612,W0613,W0614,W1505,R0401,R1707,C0202,E0602` * `W0102`: dangerous-default-value * `W0401`: wildcard-import * `W0611`: unused-import * `W0612`: unused-variable * `W0613`: unused-argument * `W0614`: unused-wildcard-import * `W1505`: deprecated-method * `R0401`: cyclic-import * `R1707`: trailing-comma-tuple * `C0202`: bad-classmethod-argument * `E0602`: undefined-variable Co-authored-by: Alexander Reinauer <[email protected]> Co-authored-by: Jean-Noël Grad <[email protected]>
3293: Re-enable pylint in CI r=fweik a=jngrad Fixes #3194 Rules: `W0102,W0401,W0611,W0612,W0613,W0614,W1505,R0401,R1707,C0202,E0602` * `W0102`: dangerous-default-value * `W0401`: wildcard-import * `W0611`: unused-import * `W0612`: unused-variable * `W0613`: unused-argument * `W0614`: unused-wildcard-import * `W1505`: deprecated-method * `R0401`: cyclic-import * `R1707`: trailing-comma-tuple * `C0202`: bad-classmethod-argument * `E0602`: undefined-variable Co-authored-by: Jean-Noël Grad <[email protected]>
pylint
was recently removed (b720b5c) because it only checked for one warning that had become a false positive in Python3. We can re-enable it (and move it to the style check job) if there is a need for rules that cannot be enforced byautopep8
. A few candidates:class-naming-style
,const-naming-style
. Feel free to propose more rules here. The full list can be found in Pylint features.The text was updated successfully, but these errors were encountered: