aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorWolfgang Müller2021-04-27 17:23:31 +0200
committerWolfgang Müller2021-04-28 20:15:53 +0200
commitf994851c472d097a4cd34da42abc16bea30dc4c6 (patch)
tree39d7e84ccc95ec7daf99145c78da8d2b717027aa
parent5abde2e5cac9700c42babaf90c35e2cc2be25477 (diff)
downloadquarg-f994851c472d097a4cd34da42abc16bea30dc4c6.tar.gz
main: Improve readability of collect_predicates
Instead of adding another indentation level, exit early if a value or a key can be ignored.
-rw-r--r--quarg/main.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/quarg/main.py b/quarg/main.py
index eeaf943..2973a2a 100644
--- a/quarg/main.py
+++ b/quarg/main.py
@@ -141,16 +141,25 @@ def collect_predicates(args):
}
for key, value in vars(args).items():
- # FIXME sadly the 'joined' namespace will contain a falsy value, so
- # check against None or []
- if key in funs and value not in [None, []]:
- fun = funs[key]
- if args.debug:
- print(f'{key}: {value}', file=sys.stderr)
- if isinstance(value, list):
- yield filters.any_filter(fun, value)
- else:
- yield fun(value)
+ # ignore unset or empty arguments
+ # Note: 'if not value' does not work here because 'joined' can be falsy
+ # but still needs to be passed to filters.joined
+ if value is None or value == []:
+ continue
+
+ # ignore arguments that do not map to predicates
+ if key not in funs:
+ continue
+
+ if args.debug:
+ print(f'{key}: {value}', file=sys.stderr)
+
+ fun = funs[key]
+
+ if isinstance(value, list):
+ yield filters.any_filter(fun, value)
+ else:
+ yield fun(value)
def run_query(session, predicates):
start = timer()