{"record":{"id":"29bc8a0dba95b3fa","repo":"python/cpython","slug":"call-not-defined","errorCode":null,"errorMessage":".__call__() not defined","messagePattern":"\\.__call__\\(\\) not defined","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"Lib/argparse.py","lineNumber":1043,"sourceCode":"            'option_strings',\n            'dest',\n            'nargs',\n            'const',\n            'default',\n            'type',\n            'choices',\n            'required',\n            'help',\n            'metavar',\n            'deprecated',\n        ]\n        return [(name, getattr(self, name)) for name in names]\n\n    def format_usage(self):\n        return self.option_strings[0]\n\n    def __call__(self, parser, namespace, values, option_string=None):\n        raise NotImplementedError('.__call__() not defined')\n\n\nclass BooleanOptionalAction(Action):\n    def __init__(self,\n                 option_strings,\n                 dest,\n                 default=None,\n                 required=False,\n                 help=None,\n                 deprecated=False):\n\n        _option_strings = []\n        neg_option_strings = []\n        for option_string in option_strings:\n            _option_strings.append(option_string)\n\n            if len(option_string) > 2 and option_string[0] == option_string[1]:\n                # two-dash long option: '--foo' -> '--no-foo'","sourceCodeStart":1025,"sourceCodeEnd":1061,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/argparse.py#L1025-L1061","documentation":"argparse.Action is an abstract base: its __call__ raises NotImplementedError('.__call__() not defined'). If a subclass (custom or from a library) does not override __call__, the error surfaces at parse time when the option the action is bound to actually appears on the command line.","triggerScenarios":"class MyAction(argparse.Action): pass used in add_argument('--x', action=MyAction), then parsing '--x' on the command line; subclassing Action but naming the handler _call__ or mis-indenting it so it is not an override.","commonSituations":"First attempts at custom argparse actions; refactors that rename __call__ to something else; incomplete copy-paste of an example action.","solutions":["Implement __call__(self, parser, namespace, values, option_string=None) in the subclass, typically calling setattr(namespace, self.dest, values).","Subclass _StoreAction or _StoreConstAction instead of Action when you only need storing behavior.","Smoke-test the CLI with the actual flag in tests so a missing __call__ is caught before release."],"exampleFix":"# before\nclass VerboseAction(argparse.Action):\n    pass  # NotImplementedError at parse time\n\n# after\nclass VerboseAction(argparse.Action):\n    def __call__(self, parser, namespace, values, option_string=None):\n        setattr(namespace, self.dest, values.upper())","handlingStrategy":"type-guard","validationCode":"import argparse\n\ndef action_implements_call(action_cls) -> bool:\n    return action_cls.__call__ is not argparse.Action.__call__","typeGuard":"def is_callable_action(action: argparse.Action) -> bool:\n    return type(action).__call__ is not argparse.Action.__call__","tryCatchPattern":"try:\n    args = parser.parse_args(['--flag'])\nexcept NotImplementedError as e:\n    if '.__call__() not defined' in str(e):\n        raise RuntimeError(f'action for --flag is incomplete: implement __call__') from e\n    raise","preventionTips":["Always implement __call__ when subclassing argparse.Action","Prefer subclassing _StoreAction for store-like behavior","Add a parse smoke test exercising every declared flag"],"tags":["python","argparse","cli","subclassing","not-implemented"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}