diff options
| author | Tim Graham <timograham@gmail.com> | 2017-09-07 08:16:21 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-07 08:16:21 -0400 |
| commit | 6e4c6281dbb7ee12bcdc22620894edb4e9cf623f (patch) | |
| tree | 1c21218d4b6f00c499f18943d5190ebe7b5248c9 /django/utils/formats.py | |
| parent | 8b2515a450ef376b9205029090af0a79c8341bd7 (diff) | |
Reverted "Fixed #27818 -- Replaced try/except/pass with contextlib.suppress()."
This reverts commit 550cb3a365dee4edfdd1563224d5304de2a57fda
because try/except performs better.
Diffstat (limited to 'django/utils/formats.py')
| -rw-r--r-- | django/utils/formats.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/django/utils/formats.py b/django/utils/formats.py index 33865d93a8..f19449ec1e 100644 --- a/django/utils/formats.py +++ b/django/utils/formats.py @@ -1,7 +1,6 @@ import datetime import decimal import unicodedata -from contextlib import suppress from importlib import import_module from django.conf import settings @@ -80,8 +79,10 @@ def iter_format_modules(lang, format_module_path=None): locales.append(locale.split('_')[0]) for location in format_locations: for loc in locales: - with suppress(ImportError): + try: yield import_module('%s.formats' % (location % loc)) + except ImportError: + pass def get_format_modules(lang=None, reverse=False): @@ -109,8 +110,10 @@ def get_format(format_type, lang=None, use_l10n=None): if use_l10n and lang is None: lang = get_language() cache_key = (format_type, lang) - with suppress(KeyError): + try: return _format_cache[cache_key] + except KeyError: + pass # The requested format_type has not been cached yet. Try to find it in any # of the format_modules for the given lang if l10n is enabled. If it's not |
