From bb45af0f98ed1d4331508e7731fb95c36d4ddec4 Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Tue, 22 Jan 2019 09:26:46 -0500 Subject: [PATCH] Use an if/else for returning the client in get_client Attempting to do something more fancy lead the method to instanciate both clients, let's not do that. Change-Id: I0c8abc48ce146fe7dec592779b4cd07dedcc3bd8 --- ara/clients/utils.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/ara/clients/utils.py b/ara/clients/utils.py index 819a033..9b060c0 100644 --- a/ara/clients/utils.py +++ b/ara/clients/utils.py @@ -23,12 +23,9 @@ def get_client(client="offline", endpoint="http://127.0.0.1:8000", timeout=30): """ Returns a specified client configuration or one with sane defaults. """ - try: - # fmt: off - return { - "offline": AraOfflineClient(), - "http": AraHttpClient(endpoint=endpoint, timeout=timeout) - }[client] - # fmt: on - except KeyError: + if client == "offline": + return AraOfflineClient() + elif client == "http": + return AraHttpClient(endpoint=endpoint, timeout=timeout) + else: raise ValueError(f"Unsupported API client: {client} (use 'http' or 'offline')")