From 809cf435fb31923b1cb0a8eaed5dfcda67d7f8b5 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 26 Apr 2022 18:00:44 +0200 Subject: [PATCH] :test_tube: Catch TypeError in the config --- cfig/tests/test_config.py | 4 ++-- docs/quickstart.rst | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cfig/tests/test_config.py b/cfig/tests/test_config.py index 60af0e3..5e990a8 100644 --- a/cfig/tests/test_config.py +++ b/cfig/tests/test_config.py @@ -58,7 +58,7 @@ class TestConfig: """The first number to sum.""" try: return int(val) - except ValueError: + except (ValueError, TypeError): raise cfig.InvalidValueError("Not an int.") @basic_config.optional() @@ -66,7 +66,7 @@ class TestConfig: """The second number to sum.""" try: return int(val) - except ValueError: + except (ValueError, TypeError): raise cfig.InvalidValueError("Not an int.") yield basic_config diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 7895deb..26bc70b 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -125,7 +125,7 @@ This allows us to perform some expensive operations inside, such as connecting t """The maximum number of users that will be able to login to this application.""" try: return int(val) - except ValueError: + except (ValueError, TypeError): raise cfig.InvalidValueError("Not an int.") We can see that the new ``MAX_USERS`` configurable value processes the input string by trying to cast it into an :class:`int`, and raises a :exc:`~cfig.errors.InvalidValueError` containing the error message to display to the user if the cast fails. @@ -168,7 +168,7 @@ To facilitate configuration on the users' part, :mod:`cfig` provides an integrat """The maximum number of users that will be able to login to this application.""" try: return int(val) - except ValueError: + except (ValueError, TypeError): raise cfig.InvalidValueError("Not an int.") if __name__ == "__main__":