How to let pyflakes ignore some errors?

I am using SublimePythonIDE which uses pyflakes. There are some errors that I would like to ignore, for example:

(E501) line too long 
 (E101) indentation contains mixed spaces and tabs 

What is the easiest way to do this?

+5
source share
2 answers

Setting up a plugin in Sublime almost always uses the same procedure: click Preferences -> Package Settings -> Plugin Name -> Settings-Default to open (unexpected surprise) the default settings. This file usually contains all the possible settings for the plugin, usually together with comments explaining what everyone does. This file cannot be changed, therefore, to configure any parameters that you open, Preferences -> Package Settings -> Plugin Name -> Settings-User . Usually I copy the entire contents of the default settings to the user file, then configure as desired, then save and close.

In the case of this particular plugin, while it uses pyflakes (as stated), it also uses pep8 , a style checker that uses the same PEP-8 official Python style guide that I mentioned in the comments. This knowledge is useful because pyflakes does not use specific error codes, but pep8 does.

So, having examined the plugin settings file, we will find the option "pep8_ignore" , as well as "pyflakes_ignore" . Since error codes come from pep8 , we will use this parameter:

 "pep8_ignore": [ "E501", // line too long "E303", // too many blank lines (3) "E402" // module level import not at top of file ] 

Please note that codes E121, E123, E126, E133, E226, E241, E242 and E704 are ignored by default because they are not unanimously accepted and PEP 8 does not apply them.


Relatively long lines:

Sometimes long lines are inevitable. The PEP-8 recommendation of 79-character lines is based in ancient history when terminal monitors had only 80 wide-screen screens, but it continues to this day for several reasons: it is backward compatible with the old code, some equipment is still used with these restrictions, it looks good, it makes it easier to work on wider displays so that multiple files open side by side, and it is readable (something you should always keep in mind when coding). If you prefer a limit of 90 or 100 characters, that’s fine (if your team / project agrees with it), but use it consistently and remember that others can use different values. If you want to set pep8 to a larger value than its default value of 80, just change the setting of "pep8_max_line_length" .

There are many ways to reduce the number of characters in liters, to stay within the limit, or to divide long lines into several shorter ones. In the case of your example in the comments:

 flag, message = FacebookUserController.AddFBUserToDB(iOSUserId, fburl, fbsecret, code) 

you can do a couple of things:

 # shorten the module/class name fbuc = FacebookUserController # or import FacebookUserController as fbuc flag, message = fbuc.AddFBUserToDB(iOSUserId, fburl, fbsecret, code) 
 # or eliminate it all together from FacebookUserController import AddFBUserToDB flag, message = AddFBUserToDB(iOSUserId, fburl, fbsecret, code) 
 # split the function arguments onto separate lines flag, message = FacebookUserController.AddFBUserToDB(iOSUserId, fburl, fbsecret, code) # There are multiple ways of doing this, just make sure the subsequent # line(s) are indented. You don't need to escape newlines inside of # braces, brackets, and parentheses, but you do need to outside of them. 
+7
source

Like others, perhaps heed the warnings. But in these cases, you cannot add # NOQA to the end of the violation line. Note the two spaces before # , as this is also a style thing to be complained about.

And if pyflakes are wrapped in flake8, which allows you to ignore certain errors.

For example, in a file in a project, put or add in tox.ini :

 [flake8] exclude = .tox,./build filename = *.py ignore = E501,E101 

Perhaps this is a duplicate of How to make Pyflakes ignore the instruction?

+1
source

All Articles