How to format Django setting file for flake8

If you are obsessed with not getting this warning more than the actual looks of your code, then you can break a line of python code (without breaking it's continuity) by adding a \ character at the breaking point:

Examples:

# 1
from some_module import some_method, some_other_method, \
                        a_third_method

# 2
s = "A really very long string, which exist to mesh with your pep8" \
    " warning free obsession. Well, not anymore!!!"    

Attention: The \ character raises an error when the line you are going to split is inside {}, [] or (), so you may simply do:

AUTH_PASSWORD_VALIDATORS = [{
    'NAME': 'django.contrib.auth.password_validation.'
            'UserAttributeSimilarityValidator'
    }, ...

which is not that ugly considering...


If you don't want the warning and you like your code as is, then you can add:

# nopep8 

at the end of every line that you want to exempt from pep8 analysis.


As an alternative (the following rewrite passes PEP8):

[{"NAME": f"django.contrib.auth.password_validation.{name}"}
 for name in [
    "UserAttributeSimilarityValidator",
    "MinimumLengthValidator",
    "CommonPasswordValidator",
    "NumericPasswordValidator"]]

In python 2 you can use {}".format(name) rather than f"".


Was looking at Coding style | Django docs and found this:

An exception to PEP 8 is our rules on line lengths. Don’t limit lines of code to 79 characters if it means the code looks significantly uglier or is harder to read. We allow up to 119 characters as this is the width of GitHub code review.

Even people at Django avoid it (they also prefer flake8 for PEP8 checking). So, it'll be better if you make a .flake8 or setup.cfg file and type:

[flake8]
max-line-length = 119