From 5d0e89c1c08149c9e660897877bddada91f991e4 Mon Sep 17 00:00:00 2001 From: Sourcery AI Date: Thu, 4 Jun 2020 12:45:11 +0000 Subject: [PATCH] Refactored by Sourcery --- ldndc2nc/cli.py | 25 +++++++++++-------------- ldndc2nc/extra.py | 3 +-- ldndc2nc/ldndc2nc.py | 6 +++--- ldndc2nc/variable.py | 8 +++----- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/ldndc2nc/cli.py b/ldndc2nc/cli.py index 4d2b988..c647d66 100644 --- a/ldndc2nc/cli.py +++ b/ldndc2nc/cli.py @@ -52,9 +52,7 @@ def is_valid_year_range(s): _ = int(e) except ValueError: return False - if int(s[1]) < int(s[0]): - return False - return True + return int(s[1]) >= int(s[0]) if is_valid_year_range(s): setattr(namespace, self.dest, range(int(s[0]), int(s[-1]) + 1)) @@ -82,17 +80,16 @@ class CustomFormatter( ): def _get_help_string(self, action): help = action.help - if "%(default)" not in action.help: - if action.default is not argparse.SUPPRESS: - defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE] - if action.option_strings or action.nargs in defaulting_nargs: - if type(action.default) == list: - help += " (default: %d-%d)" % ( - action.default[0], - action.default[-1], - ) - else: - help += " (default: %(default)s)" + if "%(default)" not in help and action.default is not argparse.SUPPRESS: + defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE] + if action.option_strings or action.nargs in defaulting_nargs: + if type(action.default) == list: + help += " (default: %d-%d)" % ( + action.default[0], + action.default[-1], + ) + else: + help += " (default: %(default)s)" return help diff --git a/ldndc2nc/extra.py b/ldndc2nc/extra.py index 8e7fcec..45608b7 100644 --- a/ldndc2nc/extra.py +++ b/ldndc2nc/extra.py @@ -30,7 +30,6 @@ def _copy_default_config(): def _find_config() -> Path: """ look for cfgFile in the default locations """ - cfgFile = None env_var = os.environ.get("LDNDC2NC_CONF", "__NOTSET__") locations = [ @@ -42,7 +41,7 @@ def _find_config() -> Path: if loc.is_file(): return loc - return cfgFile + return None def _parse_config(cfgFile): diff --git a/ldndc2nc/ldndc2nc.py b/ldndc2nc/ldndc2nc.py index 20bed68..57d7da6 100644 --- a/ldndc2nc/ldndc2nc.py +++ b/ldndc2nc/ldndc2nc.py @@ -147,7 +147,7 @@ def _select_files(inpath, ldndc_file_type, limiter=""): infiles.sort() - if len(infiles) == 0: + if not infiles: msg = "No LandscapeDNDC input files of type <%s>\n" % ldndc_file_type msg += "Input dir: %s\n" % inpath if limiter != "": @@ -234,8 +234,8 @@ def read_ldndc_txt(inpath, varData, years, limiter=""): dfs.append(df) # we don't have any dataframes, return - # TODO: the control flow here should be more obvious - if len(dfs) == 0: + # TODO: the control flow here should be more obvious + if not dfs: log.warn("No data.frame filetype %s!" % ldndc_file_type) continue diff --git a/ldndc2nc/variable.py b/ldndc2nc/variable.py index 465401c..afeb220 100644 --- a/ldndc2nc/variable.py +++ b/ldndc2nc/variable.py @@ -8,7 +8,7 @@ def identical(elements: List) -> bool: - return all([e == elements[0] for e in elements]) + return all(e == elements[0] for e in elements) def valid_brackets(s: str) -> bool: @@ -19,15 +19,13 @@ def valid_brackets(s: str) -> bool: cnt += 1 if cnt > 1: return False - if l == "]": + elif l == "]": cnt -= 1 if cnt == 0: cnt_closed += 1 elif cnt < 0: return False - if cnt_closed > 1: - return False - return True + return cnt_closed <= 1 def variables_compatible(s: str, src: List[str]) -> bool: