How to format Django settings file for flake8

I'm a little obsessed with creating python code using flake8. However, I cannot find a good way to solve the E501 (the string is too long x> 79 characters) in the Django settings file.

At first it was like this (4xE501):

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

and then I came up with the following:

AUTH_PASSWORD_VALIDATORS = [{
    'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    }, {
    'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    }, {
    'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    }, {
    'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

But still 'NAME':django.contrib.auth.password_validation.UserAttributeSimilarityValidator',too long. Is there a way to format this or should I ignore this?

+4
source share
3 answers

If you are obsessed with not getting this warning more than the actual appearance of your code, you can break the python code line (without breaking its continuity) by adding a character \at the time of interruption:

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!!!"    

: \ , , , {}, [] or (), :

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

, ...


, , :

# nopep8 

, pep8.


:)

+1

( PEP8):

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

python 2 {}".format(name), f"".

+1

| Django docs :

PEP 8 . 79 , , . 119 , GitHub.

Django ( flake8 PEP8). , , .flake8 setup.cfg :

[flake8]
max-line-length = 119
+1
source

Source: https://habr.com/ru/post/1675595/


All Articles