{"record":{"id":"c6245e1ea89eb1f9","repo":"RustPython/RustPython","slug":"unknown-action-action-class-r","errorCode":null,"errorMessage":"unknown action {action_class!r}","messagePattern":"unknown action (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Lib/argparse.py","lineNumber":1538,"sourceCode":"            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)\n        if not callable(action_class):\n            raise ValueError(f'unknown action {action_class!r}')\n        action = action_class(**kwargs)\n\n        # raise an error if action for positional argument does not\n        # consume arguments\n        if not action.option_strings and action.nargs == 0:\n            raise ValueError(f'action {action_name!r} is not valid for positional arguments')\n\n        # raise an error if the action type is not callable\n        type_func = self._registry_get('type', action.type, action.type)\n        if not callable(type_func):\n            raise TypeError(f'{type_func!r} is not callable')\n\n        if type_func is FileType:\n            raise TypeError(f'{type_func!r} is a FileType class object, '\n                            f'instance of it must be passed')\n\n        # raise an error if the metavar does not match the type\n        if hasattr(self, \"_get_validation_formatter\"):","sourceCodeStart":1520,"sourceCodeEnd":1556,"githubUrl":"https://github.com/RustPython/RustPython/blob/aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd/Lib/argparse.py#L1520-L1556","documentation":"add_argument resolves action= through the parser's 'action' registry (built-ins such as 'store', 'store_true', 'append', plus entries added with parser.register('action', ...)). If the resolved value is not callable — a typo'd string, an unregistered name, or an Action instance instead of the class — this ValueError is raised before the action is constructed.","triggerScenarios":"action='strore' (misspelled); action='mine' without prior parser.register('action', 'mine', MyAction); passing an Action instance, which has no __call__, instead of the class.","commonSituations":"Typos in action names; custom action classes referenced by string before registration; config-driven CLI builders passing unvalidated strings.","solutions":["Use a registered built-in name exactly: store, store_const, store_true, store_false, append, append_const, count, help, version, extend.","Pass the class object itself: action=MyAction, and for the boolean pair use action=argparse.BooleanOptionalAction (the class).","For string-based dispatch, register first: parser.register('action', 'mine', MyAction)."],"exampleFix":"# before\nparser.add_argument('-v', action='strore_true')\n# after\nparser.add_argument('-v', action='store_true')","handlingStrategy":"type-guard","validationCode":"BUILTIN_ACTIONS = {'store', 'store_const', 'store_true', 'store_false', 'append', 'append_const', 'count', 'help', 'version', 'extend'}\ndef valid_action(value):\n    return callable(value) or value in BUILTIN_ACTIONS\nassert valid_action(action_value), 'unknown action ' + repr(action_value)","typeGuard":"def is_action_spec(value) -> bool:\n    return callable(value) or (isinstance(value, str) and value in BUILTIN_ACTIONS)","tryCatchPattern":null,"preventionTips":["Centralize action names as constants or enums used by both config and parser code.","For config-driven CLIs, validate the action field against the built-in set before building the parser.","Pass custom action classes, not instances or unregistered strings."],"tags":["argparse","action","registry","valueerror"],"backgroundTag":"unknown-action-type","analyzedSha":"aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd","analyzedAt":"2026-08-17T00:37:52.100Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}