summaryrefslogtreecommitdiff
path: root/django/forms/fields.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/forms/fields.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/forms/fields.py')
-rw-r--r--django/forms/fields.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 805018786a..9246676527 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -9,7 +9,6 @@ import math
import os
import re
import uuid
-from contextlib import suppress
from decimal import Decimal, DecimalException
from io import BytesIO
from urllib.parse import urlsplit, urlunsplit
@@ -1093,7 +1092,7 @@ class FilePathField(ChoiceField):
f = os.path.join(root, f)
self.choices.append((f, f.replace(path, "", 1)))
else:
- with suppress(OSError):
+ try:
for f in sorted(os.listdir(self.path)):
if f == '__pycache__':
continue
@@ -1102,6 +1101,8 @@ class FilePathField(ChoiceField):
(self.allow_folders and os.path.isdir(full_file))) and
(self.match is None or self.match_re.search(f))):
self.choices.append((full_file, f))
+ except OSError:
+ pass
self.widget.choices = self.choices