diff --git a/gluon/storage.py b/gluon/storage.py index 3b0780fd..4a1e46a7 100644 --- a/gluon/storage.py +++ b/gluon/storage.py @@ -275,7 +275,7 @@ class List(list): instead of `IndexOutOfBounds`. """ - def __call__(self, i, default=None, cast=None, otherwise=None): + def __call__(self, i, default=DEFAULT, cast=None, otherwise=None): """Allows to use a special syntax for fast-check of `request.args()` validity Args: @@ -291,7 +291,9 @@ class List(list): request.args(0,default=0,cast=int,otherwise='http://error_url') request.args(0,default=0,cast=int,otherwise=lambda:...) """ - value = self[i] or default + value = self[i] + if not value and default is not DEFAULT: + value, cast, otherwise = default, False, False try: if cast: value = cast(value) diff --git a/gluon/tests/test_storage.py b/gluon/tests/test_storage.py index 804a3fb8..e518e4d2 100644 --- a/gluon/tests/test_storage.py +++ b/gluon/tests/test_storage.py @@ -138,6 +138,9 @@ class TestList(unittest.TestCase): self.assertEqual(a(3, cast=int), 1234) a.append('x') self.assertRaises(HTTP, a, 4, cast=int) + b = List() + self.assertEqual(b(0, cast=int, default=None), None) + self.assertEqual(b(0, cast=int, default=None, otherwise='something'), None) if __name__ == '__main__':