From 37c8c01cf7f60e950acbdc244f5a111d56378fa9 Mon Sep 17 00:00:00 2001 From: Andrew Dennison Date: Fri, 6 Oct 2023 14:34:53 +1100 Subject: [PATCH] build/parser: detect invalid defaults --- litex/build/parser.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/litex/build/parser.py b/litex/build/parser.py index 74359e2a90..ee2b4fb27d 100644 --- a/litex/build/parser.py +++ b/litex/build/parser.py @@ -225,6 +225,13 @@ def parse_args(self, args=None, namespace=None): # Injects arguments default values if len(self._args_default): argparse.ArgumentParser.set_defaults(self, **self._args_default) + # Catch defaults which do not match any arguments - typos? + remaining = list(self._args_default.keys()) + for action in self._actions: + if action.dest in remaining: + remaining.remove(action.dest) + if len(remaining) > 0: + raise ValueError(f"set_default() for invalid argument(s): {remaining}") # Parse args. self._args = argparse.ArgumentParser.parse_args(self, args, namespace)