summaryrefslogtreecommitdiff
path: root/django/forms/fields.py
diff options
context:
space:
mode:
authorMads Jensen <mje@inducks.org>2017-03-09 16:17:41 +0100
committerTim Graham <timograham@gmail.com>2017-06-28 14:07:55 -0400
commit550cb3a365dee4edfdd1563224d5304de2a57fda (patch)
treefb532f38774ff7619edd2a4532c3daae1ee0ac5a /django/forms/fields.py
parent43a4835edf32c57eb74c0eb207c276734a34abcf (diff)
Fixed #27818 -- Replaced try/except/pass with contextlib.suppress().
Diffstat (limited to 'django/forms/fields.py')
-rw-r--r--django/forms/fields.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 1bc6953561..3a0609b915 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -8,6 +8,7 @@ import itertools
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
@@ -1086,7 +1087,7 @@ class FilePathField(ChoiceField):
f = os.path.join(root, f)
self.choices.append((f, f.replace(path, "", 1)))
else:
- try:
+ with suppress(OSError):
for f in sorted(os.listdir(self.path)):
if f == '__pycache__':
continue
@@ -1095,8 +1096,6 @@ 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