diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 02f9ed3a84..263d1f4a87 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -46,9 +46,12 @@ from django.views.decorators.csrf import csrf_protect
IS_POPUP_VAR = '_popup'
TO_FIELD_VAR = '_to_field'
+
HORIZONTAL, VERTICAL = 1, 2
-# returns the
class for a given radio_admin field
-get_ul_class = lambda x: 'radiolist%s' % (' inline' if x == HORIZONTAL else '')
+
+
+def get_ul_class(radio_style):
+ return 'radiolist' if radio_style == VERTICAL else 'radiolist inline'
class IncorrectLookupParameters(Exception):
diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py
index 0181f665ad..42ab18007e 100644
--- a/django/contrib/admin/templatetags/admin_list.py
+++ b/django/contrib/admin/templatetags/admin_list.py
@@ -333,7 +333,7 @@ def date_hierarchy(cl):
month_lookup = cl.params.get(month_field)
day_lookup = cl.params.get(day_field)
- link = lambda d: cl.get_query_string(d, [field_generic])
+ link = lambda filters: 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/auth/forms.py b/django/contrib/auth/forms.py
index e3c139a5fd..459a42febb 100644
--- a/django/contrib/auth/forms.py
+++ b/django/contrib/auth/forms.py
@@ -21,7 +21,11 @@ from django.contrib.sites.models import get_current_site
UNMASKED_DIGITS_TO_SHOW = 6
-mask_password = lambda p: "%s%s" % (p[:UNMASKED_DIGITS_TO_SHOW], "*" * max(len(p) - UNMASKED_DIGITS_TO_SHOW, 0))
+
+def mask_password(password):
+ shown = password[:UNMASKED_DIGITS_TO_SHOW]
+ masked = "*" * max(len(password) - UNMASKED_DIGITS_TO_SHOW, 0)
+ return shown + masked
class ReadOnlyPasswordHashWidget(forms.Widget):
diff --git a/django/contrib/messages/storage/__init__.py b/django/contrib/messages/storage/__init__.py
index 9a09aff007..591ae14d7c 100644
--- a/django/contrib/messages/storage/__init__.py
+++ b/django/contrib/messages/storage/__init__.py
@@ -1,8 +1,12 @@
from django.conf import settings
-from django.utils.module_loading import import_by_path as get_storage
+from django.utils.module_loading import import_by_path
-# Callable with the same interface as the storage classes i.e. accepts a
-# 'request' object. It is wrapped in a lambda to stop 'settings' being used at
-# the module level
-default_storage = lambda request: get_storage(settings.MESSAGE_STORAGE)(request)
+def default_storage(request):
+ """
+ Callable with the same interface as the storage classes.
+
+ This isn't just default_storage = import_by_path(settings.MESSAGE_STORAGE)
+ to avoid accessing the settings at the module level.
+ """
+ return import_by_path(settings.MESSAGE_STORAGE)(request)
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 1186d3b50a..4c5519441e 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -1,8 +1,7 @@
from __future__ import unicode_literals
-from collections import OrderedDict
-import re
from bisect import bisect
+from collections import OrderedDict
import warnings
from django.apps import apps
@@ -13,10 +12,9 @@ from django.db.models.fields.proxy import OrderWrt
from django.utils import six
from django.utils.functional import cached_property
from django.utils.encoding import force_text, smart_text, python_2_unicode_compatible
+from django.utils.text import camel_case_to_spaces
from django.utils.translation import activate, deactivate_all, get_language, string_concat
-# Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces".
-get_verbose_name = lambda class_name: re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', class_name).lower().strip()
DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering',
'unique_together', 'permissions', 'get_latest_by',
@@ -109,7 +107,7 @@ class Options(object):
# First, construct the default values for these options.
self.object_name = cls.__name__
self.model_name = self.object_name.lower()
- self.verbose_name = get_verbose_name(self.object_name)
+ self.verbose_name = camel_case_to_spaces(self.object_name)
# Store the original user-defined values for each option,
# for use when serializing the model definition
diff --git a/django/utils/text.py b/django/utils/text.py
index f44a364f5f..f52050cccc 100644
--- a/django/utils/text.py
+++ b/django/utils/text.py
@@ -17,6 +17,7 @@ if six.PY2:
# people rely on it being here.
from django.utils.encoding import force_unicode # NOQA
+
# Capitalizes the first letter of a string.
capfirst = lambda x: x and force_text(x)[0].upper() + force_text(x)[1:]
capfirst = allow_lazy(capfirst, six.text_type)
@@ -25,6 +26,7 @@ capfirst = allow_lazy(capfirst, six.text_type)
re_words = re.compile(r'<.*?>|((?:\w[-\w]*|&.*?;)+)', re.U | re.S)
re_tag = re.compile(r'<(/)?([^ ]+?)(?:(\s*/)| .*?)?>', re.S)
re_newlines = re.compile(r'\r\n|\r') # Used in normalize_newlines
+re_camel_case = re.compile(r'(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))')
def wrap(text, width):
@@ -420,3 +422,11 @@ def slugify(value):
value = re.sub('[^\w\s-]', '', value).strip().lower()
return mark_safe(re.sub('[-\s]+', '-', value))
slugify = allow_lazy(slugify, six.text_type)
+
+
+def camel_case_to_spaces(value):
+ """
+ Splits CamelCase and converts to lower case. Also strips leading and
+ trailing whitespace.
+ """
+ return re_camel_case.sub(r' \1', value).strip().lower()
diff --git a/tests/runtests.py b/tests/runtests.py
index 5f39eef400..3998a7bf92 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -154,12 +154,10 @@ def setup(verbosity, test_labels):
if not test_labels:
module_found_in_labels = True
else:
- match = lambda label: (
- module_label == label or # exact match
- module_label.startswith(label + '.') # ancestor match
- )
-
- module_found_in_labels = any(match(l) for l in test_labels_set)
+ module_found_in_labels = any(
+ # exact match or ancestor match
+ module_label == label or module_label.startswith(label + '.')
+ for label in test_labels_set)
if module_found_in_labels:
if verbosity >= 2: