-
-
Notifications
You must be signed in to change notification settings - Fork 11.9k
MAINT: Start applying pycodestyle error rules (E) #27308
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
Conversation
dbff374 to
793890f
Compare
82c7da1 to
23086e4
Compare
b177186 to
8d8ae15
Compare
|
Needs rebase. |
|
Might want tag ignore some of the long lines. |
557a08f to
b04b862
Compare
189eb97 to
4a09789
Compare
|
@DimitriPapadopoulos Are you intentionally keeping this a draft? |
|
I need to apply more |
doc/source/conf.py
Outdated
| ('user/index', 'numpy-user.tex', 'NumPy User Guide', | ||
| _stdauthor, 'manual'), | ||
| ('reference/index', 'numpy-ref.tex', 'NumPy Reference', | ||
| _stdauthor, 'manual'), |
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 the continuation have an extra space?
numpy/_core/_dtype.py
Outdated
| return "'%sU%d'" % (byteorder, dtype.itemsize / 4) | ||
|
|
||
| elif dtype.type == str: | ||
| elif dtype.type is str: |
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.
Hmm, this might change behavior. @seberg Thoughts?
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.
If this was dtype == then yes, as is. This is fine, although it is a bit funny to not use it above as well.
| # name: [string of chars for which it is defined, | ||
| # string of characters using func interface, | ||
| # tuple of strings giving funcs for data, | ||
| # (in, out), or (instr, outstr) giving the signature as character codes, |
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.
Might add an extra space here even if a comment.
| cast._resolve_descriptors((from_dt, to_dt))) | ||
| assert(type(from_res) == from_Dt) | ||
| assert(type(to_res) == to_Dt) | ||
| assert type(from_res) is from_Dt |
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.
Might want to check that this is correct.
numpy/_core/tests/test_datetime.py
Outdated
| np.datetime64('NaT', '[D]'), | ||
| np.timedelta64(3, '[D]'), | ||
| np.timedelta64(11, '[h]'), | ||
| np.timedelta64(3*24 - 11, '[h]'))]: |
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.
Hmm, I think here and below the contents are over indented. Might be a better way to write these, maybe put the opening [ on the preceding line and dispense with the line continuation?
numpy/_core/tests/test_numeric.py
Outdated
| kwargs = {'fill_value': ''} if likefunc == np.full_like else {} | ||
| result = likefunc(b, dtype=dtype, **kwargs) | ||
| if dtype == str: | ||
| if dtype is str: |
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.
Might be worth a check.
| [one], | ||
| [three], | ||
| [four] | ||
| ]), |
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.
This nesting here is difficult to understand, could use a reformatting.
numpy/_core/tests/test_simd.py
Outdated
| def test_tobits(self): | ||
| data2bits = lambda data: sum([int(x != 0) << i for i, x in enumerate(data, 0)]) | ||
| def data2bits(data): | ||
| return sum([int(x != 0) << i for i, x in enumerate(data, 0)]) |
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'm a bit surprised a blank line wasn't added here.
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.
These are automated fixes by ruff, and pycodestyle doesn't have anything to say about it at this point. I was thinking of handling this error in an upcoming PR that would handle the relevant E pycodestyle rule.
numpy/_core/tests/test_simd.py
Outdated
|
|
||
| data_sqrt = self.load([math.sqrt(x) for x in data]) # load to truncate precision | ||
| data_sqrt = self.load([math.sqrt(x) # load to truncate precision | ||
| for x in data]) |
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.
Would be nicer to move the trailing comment to the preceding line.
numpy/_typing/_array_like.py
Outdated
| class _SupportsArray(Protocol[_DType_co]): | ||
| def __array__(self) -> ndarray[Any, _DType_co]: ... | ||
| def __array__(self) -> ndarray[Any, _DType_co]: | ||
| ... |
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 all these typing fixes should be avoided. @jorenham Thoughts?
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.
See #27308 (comment)
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.
What can I say? I'm just enforcing pycodestyle rules, not my choice. Unlike ruff, pycodestyle appears to be very opinionated, in the sense that errors cannot be silenced with noqa.
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.
# fmt: skip maybe?
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.
ruff also includes pycodestyle btw: https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
|
|
||
| substr = list_re.sub(listrepl, substr) # convert all lists to named templates | ||
| substr = list_re.sub(listrepl, substr) # convert all lists to named templates | ||
| # newnames are constructed as needed |
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.
Might want to line this up. Maybe better, put the comments on the preceding line. I hate trailing comments :)
| return writestr | ||
|
|
||
|
|
||
| include_src_re = re.compile(r"(\n|\A)\s*include\s*['\"](?P<name>[\w\d./\\]+\.src)['\"]", re.I) |
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.
This line seems long ...
numpy/linalg/tests/test_linalg.py
Outdated
| for mat in self.rshft_all: | ||
| tz(mat.astype(dt)) | ||
| if dt != object: | ||
| if dt != object: # noqa: E721 |
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'm curious why dt is not object didn't work here.
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 am considering moving this commit to a PR of its own, for a separate discussion.
numpy/ma/core.py
Outdated
| mask = ( | ||
| f(getmaskarray(a), np.ones(np.shape(v), dtype=bool), mode=mode) | ||
| | f(np.ones(np.shape(a), dtype=bool), getmaskarray(v), mode=mode) | ||
| f(getmaskarray(a), np.ones(np.shape(v), dtype=bool), mode=mode) | |
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.
IIRC, Python changed the style to prefer putting the operator in front. Don't recall if that was for Python or C code.
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.
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'm happy with leaving the change here, just reminded of the preference change.
| class SubClass(npt.NDArray[np.float64]): ... | ||
| class SubClass(npt.NDArray[np.float64]): | ||
| ... | ||
|
|
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.
Again the typing.
|
That was no fun, it would be better to keep the PR size down, and maybe do fewer style changes together. Going through a bunch of lines that add spaces in comments or blank lines is pretty easy, but mixing them in with more complicated fixes slows things down. |
|
For the static typing-related changes I agree with @charris that current "inlined ellipsis style", i.e. |
|
@DimitriPapadopoulos What are your plans here? With a few cleanups we could put this in. |
4a09789 to
d6bfeb0
Compare
|
@DimitriPapadopoulos We will be branching 2.2 in six weeks or so. It would be good to get these cleanups in before that happens. |
|
@charris I am afraid I unintentionally deleted this branch 😳 That's not necessarily a big deal because I am not certain any more that fixing Pycodestyle issues in the whole codebase is the best strategy to move to the ruff linter. Perhaps we can continue the discussion about the best strategy in #24994. |
|
Superseded by #27300. |
In preparation for #24994.