diff options
| author | Дилян Палаузов <Dilyan.Palauzov@db.com> | 2017-12-27 00:14:12 +0530 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-12-26 17:11:15 -0500 |
| commit | 4c599ece57fa009cf3615f09497f81bfa6a585a7 (patch) | |
| tree | 1f27a7e76024aaa5bc69356826061262d35d0be3 /django/utils | |
| parent | c21f158295d92e35caf96436bfdbbff554fc5569 (diff) | |
Fixed #28930 -- Simplified code with any() and all().
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/functional.py | 9 | ||||
| -rw-r--r-- | django/utils/translation/trans_real.py | 8 |
2 files changed, 7 insertions, 10 deletions
diff --git a/django/utils/functional.py b/django/utils/functional.py index 0da1fffa2b..146a2e8dc2 100644 --- a/django/utils/functional.py +++ b/django/utils/functional.py @@ -190,12 +190,9 @@ def keep_lazy(*resultclasses): @wraps(func) def wrapper(*args, **kwargs): - for arg in itertools.chain(args, kwargs.values()): - if isinstance(arg, Promise): - break - else: - return func(*args, **kwargs) - return lazy_func(*args, **kwargs) + if any(isinstance(arg, Promise) for arg in itertools.chain(args, kwargs.values())): + return lazy_func(*args, **kwargs) + return func(*args, **kwargs) return wrapper return decorator diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index cb8e79287d..74c21d97e9 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -394,10 +394,10 @@ def check_for_language(lang_code): # First, a quick check to make sure lang_code is well-formed (#21458) if lang_code is None or not language_code_re.search(lang_code): return False - for path in all_locale_paths(): - if gettext_module.find('django', path, [to_locale(lang_code)]) is not None: - return True - return False + return any( + gettext_module.find('django', path, [to_locale(lang_code)]) is not None + for path in all_locale_paths() + ) @functools.lru_cache() |
