{"id":"48a62ac5244c07c7","repo":"pypa/pip","slug":"got-unexpected-number-of-arguments-expected-n","errorCode":null,"errorMessage":"Got unexpected number of arguments, expected {n}. (example: \"{get_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/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/commands/configuration.py#L245-L281","documentation":"Raised by ConfigurationCommand._get_n_args when the number of positional arguments to a config subcommand does not match the expected count n. Each subcommand declares its arity (list/debug=0, get/unset=1, set=2); any deviation produces this PipError with an example invocation.","triggerScenarios":"E.g. 'pip config set global.index-url' (missing value, expected 2), 'pip config get a b' (expected 1), 'pip config list extra' (expected 0). The helper is called by every config subcommand handler.","commonSituations":"Forgetting the value for 'set'; passing multiple keys to 'get'; extra tokens after 'list'/'debug'; quoting mistakes that split one value into two.","solutions":["Match the arity shown in the error's example: set takes 'command.option value', get/unset take 'command.option', list/debug take nothing.","Quote values containing spaces: pip config set global.index-url 'https://example.org/simple'.","Run 'pip config -h' to confirm each subcommand's signature."],"exampleFix":"// before\npip config set global.index-url\n// after\npip config set global.index-url https://pypi.org/simple","handlingStrategy":"validation","validationCode":"expected = {\"list\": 0, \"debug\": 0, \"get\": 1, \"unset\": 1, \"set\": 2}\nif action not in expected:\n    raise SystemExit(f\"unknown config action {action!r}\")\nif len(args) != expected[action]:\n    raise SystemExit(f\"{action} expects {expected[action]} arg(s), got {len(args)}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Memorize arities: set=2, get/unset=1, list/debug=0.","Quote values containing spaces so they count as one argument."],"tags":["pip","config","cli","invalid-argument","arity"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}