From 4c599ece57fa009cf3615f09497f81bfa6a585a7 Mon Sep 17 00:00:00 2001 From: Дилян Палаузов Date: Wed, 27 Dec 2017 00:14:12 +0530 Subject: Fixed #28930 -- Simplified code with any() and all(). --- django/utils/functional.py | 9 +++------ django/utils/translation/trans_real.py | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'django/utils') 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() -- cgit v1.3