diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index f82c08348a..d8fb0a5396 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -879,17 +879,15 @@ def pluralize(value, arg='s'): singular_suffix, plural_suffix = bits[:2] try: - if float(value) != 1: - return plural_suffix + return singular_suffix if float(value) == 1 else plural_suffix except ValueError: # Invalid string that's not a number. pass except TypeError: # Value isn't a string or a number; maybe it's a list? try: - if len(value) != 1: - return plural_suffix + return singular_suffix if len(value) == 1 else plural_suffix except TypeError: # len() of unsized object. pass - return singular_suffix + return '' @register.filter("phone2numeric", is_safe=True) diff --git a/tests/template_tests/filter_tests/test_pluralize.py b/tests/template_tests/filter_tests/test_pluralize.py index 96c5802296..313981c6a8 100644 --- a/tests/template_tests/filter_tests/test_pluralize.py +++ b/tests/template_tests/filter_tests/test_pluralize.py @@ -58,8 +58,9 @@ class FunctionTests(SimpleTestCase): self.assertEqual(pluralize(0, 'y,ies,error'), '') def test_no_len_type(self): - self.assertEqual(pluralize(object(), 'y,es'), 'y') + self.assertEqual(pluralize(object(), 'y,es'), '') self.assertEqual(pluralize(object(), 'es'), '') def test_value_error(self): - self.assertEqual(pluralize('', 'y,es'), 'y') + self.assertEqual(pluralize('', 'y,es'), '') + self.assertEqual(pluralize('', 'es'), '')