diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2014-12-06 13:00:09 -0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-12-08 07:58:23 -0500 |
| commit | 4468c08d70b5b722f3ebd4872909e56580ec7d68 (patch) | |
| tree | 3da12d757bc9b586df4ba39da20b8793abcae76e /django/utils | |
| parent | b327a614eb7d885441c6a2575e10b70ac1352aae (diff) | |
Fixed #23968 -- Replaced list comprehension with generators and dict comprehension
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/datastructures.py | 4 | ||||
| -rw-r--r-- | django/utils/dateparse.py | 6 | ||||
| -rw-r--r-- | django/utils/dictconfig.py | 4 | ||||
| -rw-r--r-- | django/utils/encoding.py | 8 | ||||
| -rw-r--r-- | django/utils/html.py | 2 | ||||
| -rw-r--r-- | django/utils/termcolors.py | 4 | ||||
| -rw-r--r-- | django/utils/tree.py | 8 |
7 files changed, 18 insertions, 18 deletions
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index 49fd9d9848..58108faa4b 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -346,7 +346,7 @@ class MultiValueDict(dict): def __getstate__(self): obj_dict = self.__dict__.copy() - obj_dict['_data'] = dict((k, self.getlist(k)) for k in self) + obj_dict['_data'] = {k: self.getlist(k) for k in self} return obj_dict def __setstate__(self, obj_dict): @@ -467,7 +467,7 @@ class MultiValueDict(dict): """ Returns current object as a dict with singular values. """ - return dict((key, self[key]) for key in self) + return {key: self[key] for key in self} class ImmutableList(tuple): diff --git a/django/utils/dateparse.py b/django/utils/dateparse.py index cb45a2760b..422f55b9c5 100644 --- a/django/utils/dateparse.py +++ b/django/utils/dateparse.py @@ -36,7 +36,7 @@ def parse_date(value): """ match = date_re.match(value) if match: - kw = dict((k, int(v)) for k, v in six.iteritems(match.groupdict())) + kw = {k: int(v) for k, v in six.iteritems(match.groupdict())} return datetime.date(**kw) @@ -54,7 +54,7 @@ def parse_time(value): kw = match.groupdict() if kw['microsecond']: kw['microsecond'] = kw['microsecond'].ljust(6, '0') - kw = dict((k, int(v)) for k, v in six.iteritems(kw) if v is not None) + kw = {k: int(v) for k, v in six.iteritems(kw) if v is not None} return datetime.time(**kw) @@ -81,6 +81,6 @@ def parse_datetime(value): if tzinfo[0] == '-': offset = -offset tzinfo = get_fixed_timezone(offset) - kw = dict((k, int(v)) for k, v in six.iteritems(kw) if v is not None) + kw = {k: int(v) for k, v in six.iteritems(kw) if v is not None} kw['tzinfo'] = tzinfo return datetime.datetime(**kw) diff --git a/django/utils/dictconfig.py b/django/utils/dictconfig.py index e2c7a43c44..1644627967 100644 --- a/django/utils/dictconfig.py +++ b/django/utils/dictconfig.py @@ -264,7 +264,7 @@ class BaseConfigurator(object): c = self.resolve(c) props = config.pop('.', None) # Check for valid identifiers - kwargs = dict((k, config[k]) for k in config if valid_ident(k)) + kwargs = {k: config[k] for k in config if valid_ident(k)} result = c(**kwargs) if props: for name, value in props.items(): @@ -502,7 +502,7 @@ class DictConfigurator(BaseConfigurator): 'address' in config: config['address'] = self.as_tuple(config['address']) factory = klass - kwargs = dict((k, config[k]) for k in config if valid_ident(k)) + kwargs = {k: config[k] for k in config if valid_ident(k)} try: result = factory(**kwargs) except TypeError as te: diff --git a/django/utils/encoding.py b/django/utils/encoding.py index 39d548a9ce..40096741a7 100644 --- a/django/utils/encoding.py +++ b/django/utils/encoding.py @@ -105,8 +105,8 @@ def force_text(s, encoding='utf-8', strings_only=False, errors='strict'): # working unicode method. Try to handle this without raising a # further exception by individually forcing the exception args # to unicode. - s = ' '.join([force_text(arg, encoding, strings_only, - errors) for arg in s]) + s = ' '.join(force_text(arg, encoding, strings_only, errors) + for arg in s) return s @@ -152,8 +152,8 @@ def force_bytes(s, encoding='utf-8', strings_only=False, errors='strict'): # An Exception subclass containing non-ASCII data that doesn't # know how to print itself properly. We shouldn't raise a # further exception. - return b' '.join([force_bytes(arg, encoding, strings_only, - errors) for arg in s]) + return b' '.join(force_bytes(arg, encoding, strings_only, errors) + for arg in s) return six.text_type(s).encode(encoding, errors) else: return s.encode(encoding, errors) diff --git a/django/utils/html.py b/django/utils/html.py index 1247849f31..3c03210c11 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -90,7 +90,7 @@ def format_html(format_string, *args, **kwargs): of str.format or % interpolation to build up small HTML fragments. """ args_safe = map(conditional_escape, args) - kwargs_safe = dict((k, conditional_escape(v)) for (k, v) in six.iteritems(kwargs)) + kwargs_safe = {k: conditional_escape(v) for (k, v) in six.iteritems(kwargs)} return mark_safe(format_string.format(*args_safe, **kwargs_safe)) diff --git a/django/utils/termcolors.py b/django/utils/termcolors.py index aa2cdc97c3..47bce5244c 100644 --- a/django/utils/termcolors.py +++ b/django/utils/termcolors.py @@ -5,8 +5,8 @@ termcolors.py from django.utils import six color_names = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white') -foreground = dict((color_names[x], '3%s' % x) for x in range(8)) -background = dict((color_names[x], '4%s' % x) for x in range(8)) +foreground = {color_names[x]: '3%s' % x for x in range(8)} +background = {color_names[x]: '4%s' % x for x in range(8)} RESET = '0' opt_dict = {'bold': '1', 'underscore': '4', 'blink': '5', 'reverse': '7', 'conceal': '8'} diff --git a/django/utils/tree.py b/django/utils/tree.py index eceaf20eba..a8d96893b0 100644 --- a/django/utils/tree.py +++ b/django/utils/tree.py @@ -43,10 +43,10 @@ class Node(object): def __str__(self): if self.negated: - return '(NOT (%s: %s))' % (self.connector, ', '.join([str(c) for c - in self.children])) - return '(%s: %s)' % (self.connector, ', '.join([str(c) for c in - self.children])) + return '(NOT (%s: %s))' % (self.connector, ', '.join(str(c) for c + in self.children)) + return '(%s: %s)' % (self.connector, ', '.join(str(c) for c in + self.children)) def __repr__(self): return "<%s: %s>" % (self.__class__.__name__, self) |
