-
-
Notifications
You must be signed in to change notification settings - Fork 309
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
ENH: Allow flexible spacing for numerical list-of-list (array-like) #758
Comments
In GitLab by @asottile on Jul 8, 2020, 18:19 closed |
In GitLab by @larsoner on Jul 8, 2020, 18:51
I would call this a work around rather than solution. Then people need to know what these A errors are about and how they relate to the E ones. It certainly seems suboptimal to me at least.
That one appears to be about ignoring entire files / adding to the file ignore list. The proposal here is really about (ideally) filtering errors based on logical-line (and/or physical line) criteria after they have been detected by the given global rules. In other words, adding this new hook would allow general algorithmic subselection of errors based on content. For example, maybe you want to:
I know the third would be useful in NumPy and scipy, and the second would be useful in many projects I maintain. But maybe I'm underestimating the complexity of the implementation / API contract Flake8 would have to absorb for this functionality. |
In GitLab by @larsoner on Jul 8, 2020, 18:58 TL;DR: I guess what I'm saying would be awesome would be a hook that allowed you to algorithmically effectively do the equivalent of inserting |
In GitLab by @sigmavirus24 on Jul 9, 2020, 06:25 So I'll say that the more complex we make Flake8 the less we can add in the future and this genuinely isn't something that has a benefit that would outweigh the sheer complexity of what you're actually asking for. On the other hand, Flake8 could be used as part of a pipeline and produce machine-readable output that is parsed/handled/etc by some other tool. flake8-json exists. You could build something that reads that, analyses the line it's referring to and does the algorithmic decision making you're concerned with. That's something you can do today (could have done months ago really) and will continue to work as the output isn't likely to change. It keeps Flake8 maintainable. It doesn't introduce the nightmare of "2 hooks have differing opinions on the same violation on the same line, what do?" it means you control all of this (which it sounds like is what you want) and you don't need to block on us. |
In GitLab by @larsoner on Jul 9, 2020, 06:59
Fair enough, I had wrongly assumed this wouldn't require too many additional lines or extensive modifications to flake8.
Indeed I could even pretty easily write a custom reporter and filter directly, which seems easy enough to do. However, I wouldn't have access to the logical line at that point so still wouldn't be as straightforward, unless there is some way to (at the reporter stage level) get the logical line that a physical line error corresponds to. (I also don't know if I'm using these terms correctly since I'm relatively new.) But I think what I'll really do instead is just make this |
In GitLab by @larsoner on Jul 8, 2020, 17:21
For numerical libraries there is a need for flexible spacing of list(-of-list) of numerical values. The related issues raised initially for PyCodestyle basically boiled down to (use
flake8
and then):# noqa: E221,...
on the lines that need it, or--ignore
the problematic E2XX's, then write a plugin to restore the checks everywhere but in arrays (or so)refs:
# noqa
ignored? pycodestyle#924(1) is a pain because there are a lot of these cases for example in SciPy. I started working toward (2) with the following to be able to deal with
E201/202/203/221/222/241
by recasting them asA2XX
:setup.py
flake8_array_spacing/__init__.py
You can see the TODO bit still needs to be done (i.e., don't emit cases that are within the acceptable array-like-of-numerical ranges of the logical lines), but I think some suitable regex could do it. However, this is already pretty clearly a sub-optimal solution because now any existing
# noqa: E2XX
's in the codebase would need to be renamed# noqa: A2XX
, and also any checks that are reallyE2XX
are now called by this other annoyingA2XX
name.My sense is that some deeper restructuring of flake8 might be required to support this sort of use case properly. Maybe adding a hook into ``Manager._handle_results
,
Manager.report`, `StyleGuide`, or somewhere else, allowing post-hoc filtering of results by a plugin like:If there were such a hook, the class above could make a filename->logical line->ranges to ignore or so. Of course this could have some memory problems, so maybe there is a better way to do it.
The text was updated successfully, but these errors were encountered: