[ConfigArgumentMerger] Improve ConfigArgumentMerger compatibility with external callers (#17051)

This commit is contained in:
YAMY
2026-01-16 15:32:42 +08:00
committed by GitHub
parent 968c4f55b1
commit daa4841e86
+29 -17
View File
@@ -16,25 +16,37 @@ logger = logging.getLogger(__name__)
class ConfigArgumentMerger: class ConfigArgumentMerger:
"""Handles merging of configuration file arguments with command-line arguments.""" """Handles merging of configuration file arguments with command-line arguments."""
def __init__(self, parser: argparse.ArgumentParser): def __init__(
self,
parser: argparse.ArgumentParser = None,
boolean_actions: List[str] = None,
):
"""Initialize with list of store_true action names.""" """Initialize with list of store_true action names."""
# NOTE: The current code does not support actions other than "store_true" and "store". # NOTE: The current code does not support actions other than "store_true" and "store".
self.parser = parser if parser is not None:
self.store_true_actions = [ self.parser = parser
action.dest self.store_true_actions = [
for action in parser._actions action.dest
if isinstance(action, argparse._StoreTrueAction) for action in parser._actions
] if isinstance(action, argparse._StoreTrueAction)
self.unsupported_actions = { ]
a.dest: a self.unsupported_actions = {
for a in parser._actions a.dest: a
if a.option_strings for a in parser._actions
and not isinstance(a, argparse._StoreTrueAction) if a.option_strings
and not isinstance(a, argparse._StoreAction) and not isinstance(a, argparse._StoreTrueAction)
and "--config" not in a.option_strings and not isinstance(a, argparse._StoreAction)
and "--help" not in a.option_strings and "--config" not in a.option_strings
and "-h" not in a.option_strings and "--help" not in a.option_strings
} and "-h" not in a.option_strings
}
elif boolean_actions is not None:
# Legacy interface for compatibility
self.store_true_actions = boolean_actions
self.unsupported_actions = {}
else:
self.store_true_actions = []
self.unsupported_actions = {}
def merge_config_with_args(self, cli_args: List[str]) -> List[str]: def merge_config_with_args(self, cli_args: List[str]) -> List[str]:
""" """