Skip to content

Instantly share code, notes, and snippets.

@loic
Created December 18, 2013 01:40
Show Gist options
  • Save loic/8015995 to your computer and use it in GitHub Desktop.
Save loic/8015995 to your computer and use it in GitHub Desktop.
diff --git a/django/forms/utils.py b/django/forms/utils.py
index 3582384..4d44d28 100644
--- a/django/forms/utils.py
+++ b/django/forms/utils.py
@@ -127,6 +127,10 @@ class ErrorList(UserList):
return list(error)[0]
return force_text(error)
+ @classmethod
+ def __instancecheck__(cls, instance):
+ return isinstance(instance, (list, UserList))
+
# Utilities for time zone support in DateTimeField et al.
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index 675565b..6197568 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -5,6 +5,7 @@ import copy
import datetime
import json
import warnings
+from django.forms.util import ErrorList
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.validators import RegexValidator
@@ -2069,3 +2070,11 @@ class FormsTestCase(TestCase):
'__all__': [{'code': 'secret', 'message': 'Non-field error.'}]
}
self.assertEqual(errors, control)
+
+ def test_error_list(self):
+ e = ErrorList()
+ self.assertTrue(isinstance(e, list))
+
+ e.append('Foo')
+ self.assertIn('Foo', e)
+ self.assertIn('Foo', forms.ValidationError(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment