-
Notifications
You must be signed in to change notification settings - Fork 756
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
Ability to change PEP8 flags on the fly in source file via inline comments #27
Conversation
Example: #:PEP8 -E221 a = 3 bc = 4 #:PEP8 +E221
This one would be exactly what I need right now. One request, though: could you rewrite the code a bit? A map and two lambda functions is all cool, but I cannot read it. I have to "decompile" it first into regular python. So make it a bit more readable. jcrocholl: OK with merging this in principle? |
+1 |
This patch needs further cleanup: it actually silences these errors, but they still appear in stats. I can do the change and will come up with cleaner version. |
+1 |
I feel this feature would be ripe for abuse by people who will adamantly insist that their coding style violating PEP8 is justified. I look at the example in the commit message and think, that is not more readable than the version which honors PEP8. It's ended up just being a bunch of cryptic tokens, just to let someone line up equals signs between lines. Those kinds of indentation styles are annoying when it comes to history analysis (as changing a token on one logical line affects those of the lines around it), and as useful as comments in interpretive dance. That said, a per–file setting, something along the lines of:
This might be a good idea for a particular project; maintainers can run the pep8.py script in a way that it honors these notices, and people reading the file get a warning at the beginning of what to expect. |
Since now we have per project configuration, is there a need for inline comments? |
I have an issue where I have to just import a module to include a number of decorated functions. To get rid of the warning I even tried putting them in an init function just so the import wouldn't be unused. That resulted in some errors which I found was because of lazy initialization. The only option I can see to not have this warning is put a noop function in the module and call it. I think that makes the code much worse than a comment to say this is bad but I can't think of a better option. I definitely don't want to suppress the warning for unused imports for the whole project because that's super useful. If I'm missing something and you have a better option for my situation I'd love to hear it. |
@wkral, this report is interesting, but it does not apply to |
@florentx My mistake I didn't realize that flake8 was adding on that feature I thought that it just was a wrapper that called multiple linters. Turns out that ability to suppress warnings is built in to that project. Thanks. |
* upstream/master: (169 commits) Fix false positive E401; issue PyCQA#104. Add tests for issue PyCQA#100. Fix false positive for continuation line indentation when line contains comments. Closes PyCQA#100 Fix issue with bpython. Closes PyCQA#101 Back to development. Fix crash, and release 1.3.3; issue PyCQA#98. Release version 1.3.2. Add E902 errors for IOErrors; issue PyCQA#87. Update README. A little bit of rewording. Revert to the pre-1.2 behavior: --show-pep8 does not imply --first; issue PyCQA#89. Fix errors on E121 and E124; issue PyCQA#92. Add changelog entries for issue PyCQA#86 and issue PyCQA#91. Fix the default configuration path on Windows. Issue PyCQA#95. Back to development. Allow 'verbose' to be specified in the config file Clarify .pep can be located in any parent folder Show maximum length in "E501 line too long" error message Release version 1.3.1. Do not read the configuration when used as a module. ... Conflicts: pep8.py
Per project doen't solve the issue of you wanting to turn off pep8 for a single line because it's too long, but breaking it would hinder the style. E.g. a URL that's broken up can look very ugly and hard to maintain. |
+1 |
+1 My specific use case it also to allow long lines that contain URLs (in my case in comments). |
@smira why not use the same syntax as pylint? e.g: "# pep8: disable=E111". In particular I think the tag should be lower case to match the name of the tool it is addressing. |
I just started working with @tarekziade on flake8. Our long term goal is to make pep8 a dependency rather than something that's vendorized. I'd be willing to work with someone on @samclegg's suggested syntax for this. We have On the other hand, @samclegg , I feel obligated to point out that the solution to your problem is the fact that Python (like C) will concatenate adjacent strings, so if you want to do something like: url = 'https://api.github.com/repos/sigmavirus24/Todo.txt-python/branches/master?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxx&?client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' You could avoid the PEP8 error by doing url = ('https://api.github.com/repos/sigmavirus24/Todo.txt-python/branches/master'
'?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxx&'
'client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') It's also, IMO, easier to read. That aside, I'm sure there are some much better use cases that deem this necessary. |
This will disable pep8 for that line. It's simplistic but it works and it is an elegant (and commonplace solution) to PyCQA#27.
I agree, but in my case the URL is in a comment which makes breaking it up less easy. Ideally |
Well check out #136 and see if that's worthwhile to you. |
+ 1 |
+1 |
I will merge the patch #136 which seems just enough. Personally, I don't feel comfortable with this noise in source file, which has no added value for the reader. Of course there's some use cases where you want a blank report. (example: http://pypi.python.org/pypi/pep8nazi) |
This was a poor decision IMHO. The way pylint handles disables is more flexible and powerful. The current suggestion to use # noqa looks hacky, and is a workaround at best; it disables all violations when I might only want to disable a specific one. And the main reason (noise in source file) is not justified when I've seen more noise in several projects with multiple # noqa littering the source when a module-level disable of a specific code would have been appropriate. For E501, changing max_line_length for the whole project is not sufficient, it maybe the case where there is a coding standard for say 120 but there is a particular module/file in which it is more sensible to have this unlimited. |
Thanks for the feedback @wimglenn If you feel so inclined to implement what you described, feel free to send a pull request. It's unlikely to be merged, but it would be enlightening to see how you would do so. Further, if you write it, you can use it yourself (as can others who want that feature). |
I do not suggest to use The aim of Specifically, I'm surprised you take the example of |
On July 7, 2014 1:36:03 PM GMT+01:00, wim glenn notifications@github.com wrote:
Here's how I solved pep8's inability/unwillingness to be inline configurable... https://github.com/saltstack/salt-testing/blob/develop/salttesting/pylintplugins/pep8.py Its not a failure proof pylint plugin, but it helps... Hope it helps you... |
As in something that happens once in a file and tells flake8 what to ignore in that file? No. We've furiously avoided that as best as we can. That introduces a level of complexity that no one really wants to maintain.
Actually only Flake8 allows you to register plugins. Flake8 does quite a bit of work with pep8 to get it to accept our plugins.
I have no clue what you're asking about a project going into pip. Regardless, to implement per-file supressions would require per-file StyleGuides which would then flip the way pep8 works on its head. Hence the need for a fork. I'm sorry, but the way pep8 has been architected does not allow for this since it applies a style guide to the entirety of a run rather than a style guide per file. (Typically projects have a single style guide, not N where N is the number of files in a project.) |
One's preferences or whatever they feel comfortable should be irrelevant in any software tool (library/framework/linter and so on). You cannot easily make assumptions on your client's use cases and imposing personal preferences as opposed to providing flexibility is certainly an anti-pattern. Plus the argument of "noise in source file" contradicts with the decision being made. There can be very justifiable cases (as in the first message) where the amount of noise could be a single line at the top. But now there is no way of doing that and each line that needs ignoring will have noise. Which is obviously more noise at the end. Disappointing decisions. |
@emreay- trying to revive a conversation last commented on in 2016 is not productive nor is trying to shame a developer who is no longer part of the project. Further behaviour like this will not be tolerated |
Sometimes we need to violate PEP8 rules to improve readability of source file, at the same time we would like file to be still checked by PEP8.
I've added simple change that allows to influence pep8 'expected' codes:
:PEP8 -E221 -W603
a = 3
long = 4
:PEP8 +E221
Prepending minus sign disables the code, while prepending plus enables it back.
Please let me know if that makes sense for inclusion, I may need to add tests...