{"record":{"id":"226c52b4e3de698b","repo":"nodejs/node","slug":"can-t-handle-positional-and-keyword-arguments-at-t","errorCode":null,"errorMessage":"can't handle positional and keyword arguments at the same time","messagePattern":"can't handle positional and keyword arguments at the same time","errorType":"exception","errorClass":"FilterArgumentError","httpStatus":null,"severity":"error","filePath":"tools/inspector_protocol/jinja2/filters.py","lineNumber":683,"sourceCode":"    override this default using the first parameter.\n    \"\"\"\n    try:\n        return float(value)\n    except (TypeError, ValueError):\n        return default\n\n\ndef do_format(value, *args, **kwargs):\n    \"\"\"\n    Apply python string formatting on an object:\n\n    .. sourcecode:: jinja\n\n        {{ \"%s - %s\"|format(\"Hello?\", \"Foo!\") }}\n            -> Hello? - Foo!\n    \"\"\"\n    if args and kwargs:\n        raise FilterArgumentError('can\\'t handle positional and keyword '\n                                  'arguments at the same time')\n    return soft_unicode(value) % (kwargs or args)\n\n\ndef do_trim(value):\n    \"\"\"Strip leading and trailing whitespace.\"\"\"\n    return soft_unicode(value).strip()\n\n\ndef do_striptags(value):\n    \"\"\"Strip SGML/XML tags and replace adjacent whitespace by one space.\n    \"\"\"\n    if hasattr(value, '__html__'):\n        value = value.__html__()\n    return Markup(text_type(value)).striptags()\n\n\ndef do_slice(value, slices, fill_with=None):","sourceCodeStart":665,"sourceCodeEnd":701,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/inspector_protocol/jinja2/filters.py#L665-L701","documentation":"The format filter (do_format) mirrors Python's % operator via soft_unicode(value) % (kwargs or args). Python string interpolation cannot mix positional and keyword conversion specifiers in a single % call against a single tuple/dict, so Jinja2 rejects the combination up front with FilterArgumentError.","triggerScenarios":"Calling {{ tmpl|format(a, b, x=c) }} (both positional *args and keyword **kwargs non-empty) — e.g. {{ '%s %(x)s'|format('a', x='b') }}.","commonSituations":"Trying to combine '%s' style with '%(name)s' style placeholders in one format string and supplying both arg kinds.","solutions":["Use only positional arguments: {{ '%s %s'|format('a', 'b') }}.","Or use only keyword arguments: {{ '%(x)s %(y)s'|format(x='a', y='b') }}.","Split into two format calls if you truly need both styles."],"exampleFix":"{# before #}\n{{ '%s %(x)s'|format('a', x='b') }}\n\n{# after #}\n{{ '%s %s'|format('a', 'b') }}","handlingStrategy":"validation","validationCode":"def safe_format(tmpl, *args, **kwargs):\n    if args and kwargs:\n        raise ValueError('format: pass only positional OR only keyword args')\n    return tmpl % (kwargs or args)","typeGuard":"def format_args_consistent(args, kwargs) -> bool:\n    return not (args and kwargs)","tryCatchPattern":"from jinja2.exceptions import FilterArgumentError\ntry:\n    out = env.call_filter('format', value, args=args, kwargs=kwargs)\nexcept FilterArgumentError:\n    # fall back to whichever side is non-empty\n    only = kwargs or args\n    out = env.call_filter('format', value, args=only if isinstance(only, tuple) else (),\n                          kwargs=only if isinstance(only, dict) else {})","preventionTips":["Pick one style (%s positional or %(name)s keyword) per format string.","Lint for format strings containing both '%s' and '%('."],"tags":["jinja2","filter","format","validation"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}