{"record":{"id":"4153db9dfb4eb41c","repo":"pypa/pip","slug":"got-unexpected-number-of-arguments-expected-n","errorCode":null,"errorMessage":"Got unexpected number of arguments, expected {n}. (example: \"{prog} config {example}\")","messagePattern":"Got unexpected number of arguments, expected (.+?)\\. \\(example: \"(.+?) config (.+?)\"\\)","errorType":"exception","errorClass":"PipError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/commands/configuration.py","lineNumber":263,"sourceCode":"            )\n\n        try:\n            subprocess.check_call(f'{editor} \"{fname}\"', shell=True)\n        except FileNotFoundError as e:\n            if not e.filename:\n                e.filename = editor\n            raise\n        except subprocess.CalledProcessError as e:\n            raise PipError(f\"Editor Subprocess exited with exit code {e.returncode}\")\n\n    def _get_n_args(self, args: list[str], example: str, n: int) -> Any:\n        \"\"\"Helper to make sure the command got the right number of arguments\"\"\"\n        if len(args) != n:\n            msg = (\n                f\"Got unexpected number of arguments, expected {n}. \"\n                f'(example: \"{get_prog()} config {example}\")'\n            )\n            raise PipError(msg)\n\n        if n == 1:\n            return args[0]\n        else:\n            return args\n\n    def _save_configuration(self) -> None:\n        # We successfully ran a modifying command. Need to save the\n        # configuration.\n        try:\n            self.configuration.save()\n        except Exception:\n            logger.exception(\n                \"Unable to save configuration. Please report this as a bug.\"\n            )\n            raise PipError(\"Internal Error.\")\n\n    def _determine_editor(self, options: Values) -> str:","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/commands/configuration.py#L245-L281","documentation":"Raised by `pip config` subcommands when the number of positional arguments does not match the expected count. _get_n_args at configuration.py:256 checks `len(args) != n`; each subcommand calls it with its expected n (list=0, get=1, set=2, unset=1, debug=0). The message includes the prog name and an example invocation.","triggerScenarios":"e.g. `pip config set foo` (1 arg, expected 2), `pip config get a b` (2 args, expected 1), or `pip config list extra` (1 arg, expected 0). The mismatch trips configuration.py:258.","commonSituations":"User forgets the value for set, passes extra tokens to get/list/debug, or misremembers the subcommand arity.","solutions":["Match the argument count: `set` needs key+value (2), `get`/`unset` need key (1), `list`/`debug` need none (0).","Read the example printed in the error message — it shows the exact expected form.","Use `pip config --help` to confirm the subcommand signature."],"exampleFix":"// before\npip config set global.index-url\n// after\npip config set global.index-url https://pypi.org/simple","handlingStrategy":"validation","validationCode":"# Enforce per-subcommand arity before calling pip config\nEXPECTED = {\"list\": 0, \"get\": 1, \"set\": 2, \"unset\": 1, \"debug\": 0}\n\ndef validate_config_args(subcmd, args):\n    if subcmd not in EXPECTED:\n        raise ValueError(\"unknown config subcommand: %s\" % subcmd)\n    if len(args) != EXPECTED[subcmd]:\n        raise ValueError(\"%s expects %d arg(s), got %d\" % (subcmd, EXPECTED[subcmd], len(args)))\n    return True\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Memorize arity: list/debug=0, get/unset=1, set=2.","Wrap pip config calls with an arity-checking helper."],"tags":["cli","pip-config","argument-validation","usage-error","configuration"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}