{"record":{"id":"c4e385ccceb79472","repo":"RustPython/RustPython","slug":"dest-supplied-twice-for-positional-argument-did-y","errorCode":null,"errorMessage":"dest supplied twice for positional argument, did you mean metavar?","messagePattern":"dest supplied twice for positional argument, did you mean metavar\\?","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"Lib/argparse.py","lineNumber":1518,"sourceCode":"\n\n    # =======================\n    # Adding argument actions\n    # =======================\n\n    def add_argument(self, *args, **kwargs):\n        \"\"\"\n        add_argument(dest, ..., name=value, ...)\n        add_argument(option_string, option_string, ..., name=value, ...)\n        \"\"\"\n\n        # if no positional args are supplied or only one is supplied and\n        # it doesn't look like an option string, parse a positional\n        # argument\n        chars = self.prefix_chars\n        if not args or len(args) == 1 and args[0][0] not in chars:\n            if args and 'dest' in kwargs:\n                raise TypeError('dest supplied twice for positional argument,'\n                                ' did you mean metavar?')\n            kwargs = self._get_positional_kwargs(*args, **kwargs)\n\n        # otherwise, we're adding an optional argument\n        else:\n            kwargs = self._get_optional_kwargs(*args, **kwargs)\n\n        # if no default was supplied, use the parser-level default\n        if 'default' not in kwargs:\n            dest = kwargs['dest']\n            if dest in self._defaults:\n                kwargs['default'] = self._defaults[dest]\n            elif self.argument_default is not None:\n                kwargs['default'] = self.argument_default\n\n        # create the action object, and add it to the parser\n        action_name = kwargs.get('action')\n        action_class = self._pop_action_class(kwargs)","sourceCodeStart":1500,"sourceCodeEnd":1536,"githubUrl":"https://github.com/RustPython/RustPython/blob/aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd/Lib/argparse.py#L1500-L1536","documentation":"A positional argument's dest comes from the argument name itself, so passing dest= in the same call defines the destination twice. add_argument detects a single non-option string combined with an explicit dest keyword and raises this TypeError, pointing to metavar as the display-only alternative.","triggerScenarios":"parser.add_argument('input', dest='infile'); any single argument string that does not start with a prefix character combined with an explicit dest= keyword.","commonSituations":"Wanting nicer help text while keeping an internal attribute name; copy-paste from an optional-argument definition where dest= is legal.","solutions":["Rename the positional string itself: add_argument('infile') yields dest='infile' automatically.","Use metavar='input' when only the usage or help display should differ.","Switch to an option string if a custom dest is essential: add_argument('-i', '--infile', dest='infile')."],"exampleFix":"# before\nparser.add_argument('input', dest='infile')\n# after\nparser.add_argument('infile', metavar='input')","handlingStrategy":"validation","validationCode":"def add_positional(parser, name, **kwargs):\n    if 'dest' in kwargs:\n        raise TypeError('positional dest comes from its name; use metavar for display')\n    return parser.add_argument(name, **kwargs)","typeGuard":"def is_positional_call(args, prefix_chars):\n    return len(args) == 1 and args[0][:1] not in prefix_chars","tryCatchPattern":null,"preventionTips":["Wrap add_argument in a helper that rejects dest for positionals.","Reserve dest= for option strings; use metavar for renaming display text."],"tags":["argparse","positional-arguments","dest","metavar","typeerror"],"backgroundTag":"invalid-argument-definition","analyzedSha":"aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd","analyzedAt":"2026-08-17T00:37:52.100Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}