diff options
Diffstat (limited to 'django/forms/fields.py')
| -rw-r--r-- | django/forms/fields.py | 5 |
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 |
