From f0a31086d816d0a90fdcfaaa4ea58e122a6d99b3 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Fri, 3 Apr 2015 16:51:07 +0100 Subject: _parse_version_file tweak Swap nested ifs for and Also replace type() with isinstance() Also fix doc string Change-Id: I58177566f19b601bc734f7542c6a5dd52938063a --- morphlib/sourceresolver.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/morphlib/sourceresolver.py b/morphlib/sourceresolver.py index 7be104d2..771e81e3 100644 --- a/morphlib/sourceresolver.py +++ b/morphlib/sourceresolver.py @@ -367,21 +367,19 @@ class SourceResolver(object): and it's a dict and has the key 'version' and the type stored in the 'version' key is an int - and that int is not in the supported format otherwise returns None ''' - version = None yaml_obj = yaml.safe_load(version_file) - if yaml_obj is not None: - if type(yaml_obj) is dict: - if 'version' in yaml_obj.keys(): - if type(yaml_obj['version']) is int: - version = yaml_obj['version'] - return version + return (yaml_obj['version'] if yaml_obj is not None + and isinstance(yaml_obj, dict) + and 'version' in yaml_obj + and isinstance(yaml_obj['version'], int) + + else None) def _check_version_file(self, definitions_repo, definitions_absref): # pragma: no cover -- cgit v1.2.1