summaryrefslogtreecommitdiff
path: root/django/utils/dateformat.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-09-07 08:16:21 -0400
committerGitHub <noreply@github.com>2017-09-07 08:16:21 -0400
commit6e4c6281dbb7ee12bcdc22620894edb4e9cf623f (patch)
tree1c21218d4b6f00c499f18943d5190ebe7b5248c9 /django/utils/dateformat.py
parent8b2515a450ef376b9205029090af0a79c8341bd7 (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/dateformat.py')
-rw-r--r--django/utils/dateformat.py11
1 files changed, 7 insertions, 4 deletions
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)