{"record":{"id":"2d24b8322695c82d","repo":"python/cpython","slug":"ignored-explicit-argument-r","errorCode":null,"errorMessage":"ignored explicit argument %r","messagePattern":"ignored explicit argument %r","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"Lib/argparse.py","lineNumber":2311,"sourceCode":"                    return start_index + 1\n\n                # if there is an explicit argument, try to match the\n                # optional's string arguments to only this\n                if explicit_arg is not None:\n                    arg_count = match_argument(action, 'A')\n\n                    # if the action is a single-dash option and takes no\n                    # arguments, try to parse more single-dash options out\n                    # of the tail of the option string\n                    chars = self.prefix_chars\n                    if (\n                        arg_count == 0\n                        and option_string[1] not in chars\n                        and explicit_arg != ''\n                    ):\n                        if sep or explicit_arg[0] in chars:\n                            msg = _('ignored explicit argument %r')\n                            raise ArgumentError(action, msg % explicit_arg)\n                        action_tuples.append((action, [], option_string))\n                        char = option_string[0]\n                        option_string = char + explicit_arg[0]\n                        optionals_map = self._option_string_actions\n                        if option_string in optionals_map:\n                            action = optionals_map[option_string]\n                            explicit_arg = explicit_arg[1:]\n                            if not explicit_arg:\n                                sep = explicit_arg = None\n                            elif explicit_arg[0] == '=':\n                                sep = '='\n                                explicit_arg = explicit_arg[1:]\n                            else:\n                                sep = ''\n                        else:\n                            extras.append(char + explicit_arg)\n                            extras_pattern.append('O')\n                            stop = start_index + 1","sourceCodeStart":2293,"sourceCodeEnd":2329,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/argparse.py#L2293-L2329","documentation":"When argparse splits a bundled single-dash option string (e.g. -xy where -x takes no arguments), it refuses an explicit argument attached to the zero-arg option: if an '=' separator was used (-x=3) or the remainder starts with another prefix character (-x-y), it raises ArgumentError with the ignored value. This guards the option-bundling path where each remaining character is meant to be a further option, not a value.","triggerScenarios":"A zero-argument (arg_count == 0) single-dash option is given an attached explicit value: `-v=3` where -v is store_true, or `-v-x` where the tail begins with a prefix character. Only fires for single-dash options whose second character is not itself a prefix char (i.e. short flags, not long --options).","commonSituations":"Users accustomed to `--flag=value` syntax applying it to short boolean flags (-v=true); scripts that join a flag and its 'value' with '='; typos like -n=-1 where -n is a flag.","solutions":["Remove the attached value: write the bare flag (-v) and pass the value to an option that accepts one.","If the option should take a value, give it nargs/type (e.g. add_argument('-v', type=int)) so arg_count is not 0.","Use the double-dash long form with '=' only for options that accept exactly one argument."],"exampleFix":"# before\nparser.add_argument('-v', action='store_true')\nparser.parse_args(['-v=3'])  # error: ignored explicit argument '3'\n\n# after\nparser.add_argument('-v', action='store_true')\nparser.parse_args(['-v'])","handlingStrategy":"validation","validationCode":"import re\n\ndef has_bad_inline_short(argv, flag_names):\n    # flags declared with nargs==0, e.g. store_true\n    pat = re.compile(r'^-(?!-)([A-Za-z])(?:=(.+)|(-.+))?$')\n    for tok in argv:\n        m = pat.match(tok)\n        if m and m.group(1) in flag_names:\n            return tok  # e.g. -v=3 or -v-x\n    return None","typeGuard":null,"tryCatchPattern":"try:\n    args = parser.parse_args(argv)\nexcept argparse.ArgumentError as e:\n    if 'ignored explicit argument' in str(e):\n        print('short flags take no =value; pass values to a value-taking option')","preventionTips":["Use the bare flag form for store_true/store_const actions.","Reserve '=' only for double-dash options that take exactly one argument.","Validate generated command lines in tests before shipping wrapper scripts."],"tags":["argparse","cli","option-syntax","bundled-options"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}