diff options
Diffstat (limited to 'django/utils/dateformat.py')
| -rw-r--r-- | django/utils/dateformat.py | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py index d3f586aacf..d811e83965 100644 --- a/django/utils/dateformat.py +++ b/django/utils/dateformat.py @@ -14,6 +14,7 @@ import calendar import datetime import re import time +from contextlib import suppress from django.utils.dates import ( MONTHS, MONTHS_3, MONTHS_ALT, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR, @@ -81,11 +82,9 @@ class TimeFormat(Formatter): if not self.timezone: return "" - try: + with suppress(NotImplementedError): if hasattr(self.data, 'tzinfo') and self.data.tzinfo: return self.data.tzname() or '' - except NotImplementedError: - pass return "" def f(self): @@ -166,13 +165,11 @@ class TimeFormat(Formatter): return "" name = None - try: - name = self.timezone.tzname(self.data) - except Exception: + with suppress(Exception): # pytz raises AmbiguousTimeError during the autumn DST change. # This happens mainly when __init__ receives a naive datetime # and sets self.timezone = get_default_timezone(). - pass + name = self.timezone.tzname(self.data) if name is None: name = self.format('O') return str(name) |
