diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py index 8bccf7297a9dc..029b4bb915b91 100644 --- a/django/contrib/auth/management/__init__.py +++ b/django/contrib/auth/management/__init__.py @@ -97,9 +97,9 @@ def create_permissions(app_config, verbosity=2, interactive=True, using=DEFAULT_ )) perms = [ - Permission(codename=codename, name=name, content_type=ctype) - for ctype, (codename, name) in searched_perms - if (ctype.pk, codename) not in all_perms + Permission(codename=codename, name=name, content_type=ct) + for ct, (codename, name) in searched_perms + if (ct.pk, codename) not in all_perms ] # Validate the permissions before bulk_creation to avoid cryptic # database error when the verbose_name is longer than 50 characters diff --git a/django/contrib/gis/views.py b/django/contrib/gis/views.py index cc6844ba4897a..5d05d3a057f86 100644 --- a/django/contrib/gis/views.py +++ b/django/contrib/gis/views.py @@ -9,11 +9,7 @@ def feed(request, url, feed_dict=None): if not feed_dict: raise Http404(_("No feeds are registered.")) - try: - slug, param = url.split('/', 1) - except ValueError: - slug, param = url, '' - + slug = url.partition('/')[0] try: f = feed_dict[slug] except KeyError: diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py index c9fef98371a06..0a1463426e3cf 100644 --- a/django/contrib/staticfiles/management/commands/collectstatic.py +++ b/django/contrib/staticfiles/management/commands/collectstatic.py @@ -9,7 +9,8 @@ from django.utils.encoding import smart_text from django.utils.six.moves import input -from django.contrib.staticfiles import finders, storage +from django.contrib.staticfiles.finders import get_finders +from django.contrib.staticfiles.storage import staticfiles_storage class Command(NoArgsCommand): @@ -52,7 +53,7 @@ def __init__(self, *args, **kwargs): self.symlinked_files = [] self.unmodified_files = [] self.post_processed_files = [] - self.storage = storage.staticfiles_storage + self.storage = staticfiles_storage try: self.storage.path('') except NotImplementedError: @@ -93,7 +94,7 @@ def collect(self): handler = self.copy_file found_files = OrderedDict() - for finder in finders.get_finders(): + for finder in get_finders(): for path, storage in finder.list(self.ignore_patterns): # Prefix the relative path if the source storage contains it if getattr(storage, 'prefix', None): diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index 8874a698efe23..a41e433f0af2b 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -239,9 +239,9 @@ def fixture_dirs(self): for app_config in apps.get_app_configs(): if self.app_label and app_config.label != self.app_label: continue - d = os.path.join(app_config.path, 'fixtures') - if os.path.isdir(d): - dirs.append(d) + app_dir = os.path.join(app_config.path, 'fixtures') + if os.path.isdir(app_dir): + dirs.append(app_dir) dirs.extend(list(settings.FIXTURE_DIRS)) dirs.append('') dirs = [upath(os.path.abspath(os.path.realpath(d))) for d in dirs] diff --git a/django/db/models/base.py b/django/db/models/base.py index ba89e6e037747..968174e78cb48 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -1105,7 +1105,7 @@ def _check_managers(cls, **kwargs): errors = [] managers = cls._meta.concrete_managers + cls._meta.abstract_managers - for (_, _, manager) in managers: + for __, __, manager in managers: errors.extend(manager.check(**kwargs)) return errors diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 38b656162db87..c23767d48601a 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -15,9 +15,9 @@ class ExpressionNode(tree.Node): MUL = '*' DIV = '/' POW = '^' - MOD = '%%' # This is a quoted % operator - it is quoted - # because it can be used in strings that also - # have parameter substitution. + # The following is a quoted % operator - it is quoted because it can be + # used in strings that also have parameter substitution. + MOD = '%%' # Bitwise operators - note that these are generated by .bitand() # and .bitor(), the '&' and '|' are reserved for boolean operator diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 964f71e69443c..7bac2c386941d 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -728,7 +728,7 @@ def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH): """Returns choices with a default blank choices included, for use as SelectField choices for this field.""" blank_defined = False - for choice, _ in self.choices: + for choice, __ in self.choices: if choice in ('', None): blank_defined = True break diff --git a/django/utils/ipv6.py b/django/utils/ipv6.py index c545b2461828e..675448f6f8bbb 100644 --- a/django/utils/ipv6.py +++ b/django/utils/ipv6.py @@ -239,7 +239,7 @@ def _explode_shorthand_ip_string(ip_str): sep = len(hextet[0].split(':')) + len(hextet[1].split(':')) new_ip = hextet[0].split(':') - for _ in xrange(fill_to - sep): + for __ in xrange(fill_to - sep): new_ip.append('0000') new_ip += hextet[1].split(':') diff --git a/setup.cfg b/setup.cfg index 1b2e4718a122b..1db26cea6d8e4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,7 +4,7 @@ install-script = scripts/rpm-install.sh [flake8] exclude=build,.git,./django/utils/dictconfig.py,./django/contrib/comments/*,./django/utils/unittest.py,./django/utils/lru_cache.py,./tests/comment_tests/*,./django/test/_doctest.py,./django/utils/six.py,./django/conf/app_template/*,./django/dispatch/weakref_backports.py -ignore=E128,E501,W601 +ignore=E123,E128,E265,E501,W601 [metadata] license-file = LICENSE diff --git a/tests/cache/tests.py b/tests/cache/tests.py index c08a489939117..601d5c2b2bd09 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -1095,8 +1095,8 @@ def test_invalid_keys(self): "cache with python-memcached library not available") def test_memcached_uses_highest_pickle_version(self): # Regression test for #19810 - for cache_key, cache in settings.CACHES.items(): - if cache['BACKEND'] == 'django.core.cache.backends.memcached.MemcachedCache': + for cache_key, cache_config in settings.CACHES.items(): + if cache_config['BACKEND'] == 'django.core.cache.backends.memcached.MemcachedCache': self.assertEqual(caches[cache_key]._cache.pickleProtocol, pickle.HIGHEST_PROTOCOL) diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index 4d552532d441d..6a85ba8ca3df7 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -160,7 +160,7 @@ def test_simple_migration(self): # In order to preserve compatibility with Python 3.2 unicode literals # prefix shouldn't be added to strings. tokens = tokenize.generate_tokens(six.StringIO(str(output)).readline) - for token_type, token_source, (srow, scol), _, line in tokens: + for token_type, token_source, (srow, scol), __, line in tokens: if token_type == tokenize.STRING: self.assertFalse( token_source.startswith('u'), diff --git a/tests/model_inheritance/tests.py b/tests/model_inheritance/tests.py index 50cdf31b87df8..15c94c60878d6 100644 --- a/tests/model_inheritance/tests.py +++ b/tests/model_inheritance/tests.py @@ -6,7 +6,7 @@ from django.core.management import call_command from django.db import connection from django.test import TestCase -from django.test.utils import CaptureQueriesContext, override_settings +from django.test.utils import CaptureQueriesContext from django.utils import six from .models import ( diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py index 4d2ba30c8c49a..9d49ab1927854 100644 --- a/tests/staticfiles_tests/tests.py +++ b/tests/staticfiles_tests/tests.py @@ -848,9 +848,10 @@ def setUp(self): self.find_all = ('media-file.txt', [test_file_path]) -@override_settings(STATICFILES_FINDERS= - ('django.contrib.staticfiles.finders.FileSystemFinder',), - STATICFILES_DIRS=[os.path.join(TEST_ROOT, 'project', 'documents')]) +@override_settings( + STATICFILES_FINDERS=('django.contrib.staticfiles.finders.FileSystemFinder',), + STATICFILES_DIRS=[os.path.join(TEST_ROOT, 'project', 'documents')], +) class TestMiscFinder(TestCase): """ A few misc finder tests.