diff options
| author | userimack <mahendra.k12@gmail.com> | 2016-01-23 22:17:07 +0530 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-01-25 14:23:43 -0500 |
| commit | 60586dd7379b295b72d8af4e03423c286913b5e8 (patch) | |
| tree | 6f834957ea76305fbcda40e23e836077890d36b8 /django | |
| parent | abc0777b63057e2ff97eee2ff184356051e14c47 (diff) | |
Fixed #26125 -- Fixed E731 flake warnings.
Diffstat (limited to 'django')
25 files changed, 145 insertions, 56 deletions
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index 5128a28079..b540fbc5a3 100644 --- a/django/conf/global_settings.py +++ b/django/conf/global_settings.py @@ -1,12 +1,15 @@ # -*- coding: utf-8 -*- +""" +Default Django settings. Override these with settings in the module pointed to +by the DJANGO_SETTINGS_MODULE environment variable. +""" from __future__ import unicode_literals -# Default Django settings. Override these with settings in the module -# pointed-to by the DJANGO_SETTINGS_MODULE environment variable. # This is defined here as a do-nothing function because we can't import # django.utils.translation -- that module depends on the settings. -gettext_noop = lambda s: s +def gettext_noop(s): + return s #################### # CORE # diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index a45cf74bf5..a1fd3b5657 100644 --- a/django/contrib/admin/templatetags/admin_list.py +++ b/django/contrib/admin/templatetags/admin_list.py @@ -143,7 +143,9 @@ def result_headers(cl): o_list_primary = [] # URL for making this field the primary sort o_list_remove = [] # URL for removing this field from sort o_list_toggle = [] # URL for toggling order type for this field - make_qs_param = lambda t, n: ('-' if t == 'desc' else '') + str(n) + + def make_qs_param(t, n): + return ('-' if t == 'desc' else '') + str(n) for j, ot in ordering_field_columns.items(): if j == i: # Same column @@ -341,7 +343,8 @@ def date_hierarchy(cl): month_lookup = cl.params.get(month_field) day_lookup = cl.params.get(day_field) - link = lambda filters: cl.get_query_string(filters, [field_generic]) + def link(filters): + return cl.get_query_string(filters, [field_generic]) if not (year_lookup or month_lookup or day_lookup): # select appropriate start level diff --git a/django/contrib/postgres/validators.py b/django/contrib/postgres/validators.py index 3f576873f4..69ceeea8ba 100644 --- a/django/contrib/postgres/validators.py +++ b/django/contrib/postgres/validators.py @@ -69,10 +69,12 @@ class KeysValidator(object): class RangeMaxValueValidator(MaxValueValidator): - compare = lambda self, a, b: a.upper > b + def compare(self, a, b): + return a.upper > b message = _('Ensure that this range is completely less than or equal to %(limit_value)s.') class RangeMinValueValidator(MinValueValidator): - compare = lambda self, a, b: a.lower < b + def compare(self, a, b): + return a.lower < b message = _('Ensure that this range is completely greater than or equal to %(limit_value)s.') diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py index d6911c9fd7..58cb847f1f 100644 --- a/django/contrib/staticfiles/storage.py +++ b/django/contrib/staticfiles/storage.py @@ -217,11 +217,15 @@ class HashedFilesMixin(object): hashed_files = OrderedDict() # build a list of adjustable files - matches = lambda path: matches_patterns(path, self._patterns.keys()) - adjustable_paths = [path for path in paths if matches(path)] + adjustable_paths = [ + path for path in paths + if matches_patterns(path, self._patterns.keys()) + ] # then sort the files by the directory level - path_level = lambda name: len(name.split(os.sep)) + def path_level(name): + return len(name.split(os.sep)) + for name in sorted(paths.keys(), key=path_level, reverse=True): # use the original, local file, not the copied-but-unprocessed diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py index 40f13183d4..1573746329 100644 --- a/django/core/cache/backends/memcached.py +++ b/django/core/cache/backends/memcached.py @@ -146,8 +146,7 @@ class BaseMemcachedCache(BaseCache): self._cache.set_multi(safe_data, self.get_backend_timeout(timeout)) def delete_many(self, keys, version=None): - l = lambda x: self.make_key(x, version=version) - self._cache.delete_multi(map(l, keys)) + self._cache.delete_multi(self.make_key(key, version=version) for key in keys) def clear(self): self._cache.flush_all() diff --git a/django/core/management/color.py b/django/core/management/color.py index 3803ea3e3e..7a32370860 100644 --- a/django/core/management/color.py +++ b/django/core/management/color.py @@ -46,7 +46,8 @@ def make_style(config_string=''): format = color_settings.get(role, {}) style_func = termcolors.make_style(**format) else: - style_func = lambda x: x + def style_func(x): + return x setattr(style, role, style_func) # For backwards compatibility, diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py index 7c26abba92..3bb8e75924 100644 --- a/django/core/management/commands/inspectdb.py +++ b/django/core/management/commands/inspectdb.py @@ -32,8 +32,11 @@ class Command(BaseCommand): # 'table_name_filter' is a stealth option table_name_filter = options.get('table_name_filter') - table2model = lambda table_name: re.sub(r'[^a-zA-Z0-9]', '', table_name.title()) - strip_prefix = lambda s: s[1:] if s.startswith("u'") else s + def table2model(table_name): + return re.sub(r'[^a-zA-Z0-9]', '', table_name.title()) + + def strip_prefix(s): + return s[1:] if s.startswith("u'") else s with connection.cursor() as cursor: yield "# This is an auto-generated Django model module." diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py index 1fe17cad7f..ebec17ff01 100644 --- a/django/core/management/commands/makemessages.py +++ b/django/core/management/commands/makemessages.py @@ -365,8 +365,10 @@ class Command(BaseCommand): Check if the given path should be ignored or not. """ filename = os.path.basename(path) - ignore = lambda pattern: (fnmatch.fnmatchcase(filename, pattern) or - fnmatch.fnmatchcase(path, pattern)) + + def ignore(pattern): + return fnmatch.fnmatchcase(filename, pattern) or fnmatch.fnmatchcase(path, pattern) + return any(ignore(pattern) for pattern in ignore_patterns) ignore_patterns = [os.path.normcase(p) for p in self.ignore_patterns] diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py index 2153198751..80e4314b3c 100644 --- a/django/core/management/commands/makemigrations.py +++ b/django/core/management/commands/makemigrations.py @@ -224,7 +224,10 @@ class Command(BaseCommand): if mig[0] == migration.app_label ] merge_migrations.append(migration) - all_items_equal = lambda seq: all(item == seq[0] for item in seq[1:]) + + def all_items_equal(seq): + return all(item == seq[0] for item in seq[1:]) + merge_migrations_generations = zip(*[m.ancestry for m in merge_migrations]) common_ancestor_count = sum(1 for common_ancestor_generation in takewhile(all_items_equal, merge_migrations_generations)) diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py index 09a5438861..8a8a776d48 100644 --- a/django/core/serializers/python.py +++ b/django/core/serializers/python.py @@ -70,9 +70,11 @@ class Serializer(base.Serializer): def handle_m2m_field(self, obj, field): if field.remote_field.through._meta.auto_created: if self.use_natural_foreign_keys and hasattr(field.remote_field.model, 'natural_key'): - m2m_value = lambda value: value.natural_key() + def m2m_value(value): + return value.natural_key() else: - m2m_value = lambda value: force_text(value._get_pk_val(), strings_only=True) + def m2m_value(value): + return force_text(value._get_pk_val(), strings_only=True) self._current[field.name] = [m2m_value(related) for related in getattr(obj, field.name).iterator()] @@ -136,7 +138,8 @@ def Deserializer(object_list, **options): else: return force_text(model._meta.pk.to_python(value), strings_only=True) else: - m2m_convert = lambda v: force_text(model._meta.pk.to_python(v), strings_only=True) + def m2m_convert(v): + return force_text(model._meta.pk.to_python(v), strings_only=True) try: m2m_data[field.name] = [] diff --git a/django/core/serializers/xml_serializer.py b/django/core/serializers/xml_serializer.py index 44d745d55d..3d38217612 100644 --- a/django/core/serializers/xml_serializer.py +++ b/django/core/serializers/xml_serializer.py @@ -275,7 +275,8 @@ class Deserializer(base.Deserializer): obj_pk = model._meta.pk.to_python(n.getAttribute('pk')) return obj_pk else: - m2m_convert = lambda n: model._meta.pk.to_python(n.getAttribute('pk')) + def m2m_convert(n): + return model._meta.pk.to_python(n.getAttribute('pk')) return [m2m_convert(c) for c in node.getElementsByTagName("object")] def _get_model_from_node(self, node, attr): diff --git a/django/core/validators.py b/django/core/validators.py index 8c43644ed6..dd18aee3cb 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -295,8 +295,6 @@ validate_comma_separated_integer_list = int_list_validator( @deconstructible class BaseValidator(object): - compare = lambda self, a, b: a is not b - clean = lambda self, x: x message = _('Ensure this value is %(limit_value)s (it is %(show_value)s).') code = 'limit_value' @@ -319,42 +317,60 @@ class BaseValidator(object): and (self.code == other.code) ) + def compare(self, a, b): + return a is not b + + def clean(self, x): + return x + @deconstructible class MaxValueValidator(BaseValidator): - compare = lambda self, a, b: a > b message = _('Ensure this value is less than or equal to %(limit_value)s.') code = 'max_value' + def compare(self, a, b): + return a > b + @deconstructible class MinValueValidator(BaseValidator): - compare = lambda self, a, b: a < b message = _('Ensure this value is greater than or equal to %(limit_value)s.') code = 'min_value' + def compare(self, a, b): + return a < b + @deconstructible class MinLengthValidator(BaseValidator): - compare = lambda self, a, b: a < b - clean = lambda self, x: len(x) message = ungettext_lazy( 'Ensure this value has at least %(limit_value)d character (it has %(show_value)d).', 'Ensure this value has at least %(limit_value)d characters (it has %(show_value)d).', 'limit_value') code = 'min_length' + def compare(self, a, b): + return a < b + + def clean(self, x): + return len(x) + @deconstructible class MaxLengthValidator(BaseValidator): - compare = lambda self, a, b: a > b - clean = lambda self, x: len(x) message = ungettext_lazy( 'Ensure this value has at most %(limit_value)d character (it has %(show_value)d).', 'Ensure this value has at most %(limit_value)d characters (it has %(show_value)d).', 'limit_value') code = 'max_length' + def compare(self, a, b): + return a > b + + def clean(self, x): + return len(x) + @deconstructible class DecimalValidator(object): diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py index 6e5aff19cd..d68a5aa996 100644 --- a/django/db/backends/base/operations.py +++ b/django/db/backends/base/operations.py @@ -204,7 +204,8 @@ class BaseDatabaseOperations(object): according to their own quoting schemes. """ # Convert params to contain Unicode values. - to_unicode = lambda s: force_text(s, strings_only=True, errors='replace') + def to_unicode(s): + return force_text(s, strings_only=True, errors='replace') if isinstance(params, (list, tuple)): u_params = tuple(to_unicode(val) for val in params) elif params is None: diff --git a/django/db/backends/mysql/introspection.py b/django/db/backends/mysql/introspection.py index 3d0f6f3689..835276d7e1 100644 --- a/django/db/backends/mysql/introspection.py +++ b/django/db/backends/mysql/introspection.py @@ -71,7 +71,10 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): field_info = {line[0]: InfoLine(*line) for line in cursor.fetchall()} cursor.execute("SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name)) - to_int = lambda i: int(i) if i is not None else i + + def to_int(i): + return int(i) if i is not None else i + fields = [] for line in cursor.description: col_name = force_text(line[0]) diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 162a84793d..2071d5ff96 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -85,7 +85,10 @@ def add_lazy_relation(cls, field, relation, operation): "and related methods on the Apps class.", RemovedInDjango20Warning, stacklevel=2) # Rearrange args for new Apps.lazy_model_operation - function = lambda local, related, field: operation(field, related, local) + + def function(local, related, field): + return operation(field, related, local) + lazy_related_operation(function, cls, relation, field=field) diff --git a/django/db/models/fields/related_descriptors.py b/django/db/models/fields/related_descriptors.py index 050866efce..8f45a9231b 100644 --- a/django/db/models/fields/related_descriptors.py +++ b/django/db/models/fields/related_descriptors.py @@ -300,7 +300,10 @@ class ReverseOneToOneDescriptor(object): queryset._add_hints(instance=instances[0]) rel_obj_attr = attrgetter(self.related.field.attname) - instance_attr = lambda obj: obj._get_pk_val() + + def instance_attr(obj): + return obj._get_pk_val() + instances_dict = {instance_attr(inst): inst for inst in instances} query = {'%s__in' % self.related.field.name: instances} queryset = queryset.filter(**query) diff --git a/django/db/models/options.py b/django/db/models/options.py index 2f1f930ec5..4fdcc025f7 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -371,11 +371,17 @@ class Options(object): # use that property directly because related_model is a cached property, # and all the models may not have been loaded yet; we don't want to cache # the string reference to the related_model. - is_not_an_m2m_field = lambda f: not (f.is_relation and f.many_to_many) - is_not_a_generic_relation = lambda f: not (f.is_relation and f.one_to_many) - is_not_a_generic_foreign_key = lambda f: not ( - f.is_relation and f.many_to_one and not (hasattr(f.remote_field, 'model') and f.remote_field.model) - ) + def is_not_an_m2m_field(f): + return not (f.is_relation and f.many_to_many) + + def is_not_a_generic_relation(f): + return not (f.is_relation and f.one_to_many) + + def is_not_a_generic_foreign_key(f): + return not ( + f.is_relation and f.many_to_one and not (hasattr(f.remote_field, 'model') and f.remote_field.model) + ) + return make_immutable_fields_list( "fields", (f for f in self._get_fields(reverse=False) if diff --git a/django/http/request.py b/django/http/request.py index 22405d8306..d6ce49d755 100644 --- a/django/http/request.py +++ b/django/http/request.py @@ -481,9 +481,12 @@ class QueryDict(MultiValueDict): output = [] if safe: safe = force_bytes(safe, self.encoding) - encode = lambda k, v: '%s=%s' % ((quote(k, safe), quote(v, safe))) + + def encode(k, v): + return '%s=%s' % ((quote(k, safe), quote(v, safe))) else: - encode = lambda k, v: urlencode({k: v}) + def encode(k, v): + return urlencode({k: v}) for k, list_ in self.lists(): k = force_bytes(k, self.encoding) output.extend(encode(k, force_bytes(v, self.encoding)) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 71727208c3..631118f4b9 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -639,7 +639,8 @@ def unordered_list(value, autoescape=True): if autoescape: escaper = conditional_escape else: - escaper = lambda x: x + def escaper(x): + return x def walk_items(item_list): item_iterator = iter(item_list) @@ -850,7 +851,8 @@ def filesizeformat(bytes_): value = ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0} return avoid_wrapping(value) - filesize_number_format = lambda value: formats.number_format(round(value, 1), 1) + def filesize_number_format(value): + return formats.number_format(round(value, 1), 1) KB = 1 << 10 MB = 1 << 20 diff --git a/django/test/client.py b/django/test/client.py index 78a5df5c52..61c2136b09 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -160,10 +160,13 @@ def encode_multipart(boundary, data): as an application/octet-stream; otherwise, str(value) will be sent. """ lines = [] - to_bytes = lambda s: force_bytes(s, settings.DEFAULT_CHARSET) + + def to_bytes(s): + return force_bytes(s, settings.DEFAULT_CHARSET) # Not by any means perfect, but good enough for our purposes. - is_file = lambda thing: hasattr(thing, "read") and callable(thing.read) + def is_file(thing): + return hasattr(thing, "read") and callable(thing.read) # Each bit of the multipart form data could be either a form value or a # file, or a *list* of form values and/or files. Remember that HTTP field @@ -198,7 +201,8 @@ def encode_multipart(boundary, data): def encode_file(boundary, key, file): - to_bytes = lambda s: force_bytes(s, settings.DEFAULT_CHARSET) + def to_bytes(s): + return force_bytes(s, settings.DEFAULT_CHARSET) filename = os.path.basename(file.name) if hasattr(file, 'name') else '' if hasattr(file, 'content_type'): content_type = file.content_type diff --git a/django/utils/decorators.py b/django/utils/decorators.py index 87a702d3d8..7ba31a32e3 100644 --- a/django/utils/decorators.py +++ b/django/utils/decorators.py @@ -159,7 +159,8 @@ def make_middleware_decorator(middleware_class): # Defer running of process_response until after the template # has been rendered: if hasattr(middleware, 'process_response'): - callback = lambda response: middleware.process_response(request, response) + def callback(response): + return middleware.process_response(request, response) response.add_post_render_callback(callback) else: if hasattr(middleware, 'process_response'): diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py index 3fae71cdee..367245be22 100644 --- a/django/utils/feedgenerator.py +++ b/django/utils/feedgenerator.py @@ -91,7 +91,8 @@ class SyndicationFeed(object): def __init__(self, title, link, description, language=None, author_email=None, author_name=None, author_link=None, subtitle=None, categories=None, feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs): - to_unicode = lambda s: force_text(s, strings_only=True) + def to_unicode(s): + return force_text(s, strings_only=True) if categories: categories = [force_text(c) for c in categories] if ttl is not None: @@ -126,7 +127,8 @@ class SyndicationFeed(object): objects, and enclosures, which is an iterable of instances of the Enclosure class. """ - to_unicode = lambda s: force_text(s, strings_only=True) + def to_unicode(s): + return force_text(s, strings_only=True) if categories: categories = [to_unicode(c) for c in categories] if ttl is not None: diff --git a/django/utils/text.py b/django/utils/text.py index af80812a0d..46872372ac 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -19,7 +19,8 @@ if six.PY2: # Capitalizes the first letter of a string. -capfirst = lambda x: x and force_text(x)[0].upper() + force_text(x)[1:] +def capfirst(x): + return x and force_text(x)[0].upper() + force_text(x)[1:] capfirst = keep_lazy_text(capfirst) # Set up regular expressions diff --git a/django/utils/translation/trans_null.py b/django/utils/translation/trans_null.py index cb909c63f7..7d02fa5607 100644 --- a/django/utils/translation/trans_null.py +++ b/django/utils/translation/trans_null.py @@ -24,11 +24,28 @@ def pgettext(context, message): def npgettext(context, singular, plural, number): return ungettext(singular, plural, number) -activate = lambda x: None -deactivate = deactivate_all = lambda: None -get_language = lambda: settings.LANGUAGE_CODE -get_language_bidi = lambda: settings.LANGUAGE_CODE in settings.LANGUAGES_BIDI -check_for_language = lambda x: True + +def activate(x): + return None + + +def deactivate(): + return None + + +deactivate_all = deactivate + + +def get_language(): + return settings.LANGUAGE_CODE + + +def get_language_bidi(): + return settings.LANGUAGE_CODE in settings.LANGUAGES_BIDI + + +def check_for_language(x): + return True def gettext(message): diff --git a/django/views/i18n.py b/django/views/i18n.py index 37d38d9e74..974b63e194 100644 --- a/django/views/i18n.py +++ b/django/views/i18n.py @@ -186,7 +186,10 @@ js_catalog_template = r""" def render_javascript_catalog(catalog=None, plural=None): template = Engine().from_string(js_catalog_template) - indent = lambda s: s.replace('\n', '\n ') + + def indent(s): + return s.replace('\n', '\n ') + context = Context({ 'catalog_str': indent(json.dumps( catalog, sort_keys=True, indent=2)) if catalog else None, |
