From 6e4c6281dbb7ee12bcdc22620894edb4e9cf623f Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 7 Sep 2017 08:16:21 -0400 Subject: Reverted "Fixed #27818 -- Replaced try/except/pass with contextlib.suppress()." This reverts commit 550cb3a365dee4edfdd1563224d5304de2a57fda because try/except performs better. --- django/utils/dateformat.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'django/utils/dateformat.py') diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py index d811e83965..d3f586aacf 100644 --- a/django/utils/dateformat.py +++ b/django/utils/dateformat.py @@ -14,7 +14,6 @@ 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, @@ -82,9 +81,11 @@ class TimeFormat(Formatter): if not self.timezone: return "" - with suppress(NotImplementedError): + try: if hasattr(self.data, 'tzinfo') and self.data.tzinfo: return self.data.tzname() or '' + except NotImplementedError: + pass return "" def f(self): @@ -165,11 +166,13 @@ class TimeFormat(Formatter): return "" name = None - with suppress(Exception): + try: + name = self.timezone.tzname(self.data) + except 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(). - name = self.timezone.tzname(self.data) + pass if name is None: name = self.format('O') return str(name) -- cgit v1.3