{"record":{"id":"e19684d40da985cf","repo":"pydantic/monty","slug":"kwarg-error-name-is-only-meaningful-with-style-def-the","errorCode":null,"errorMessage":"`kwarg_error_name` is only meaningful with `style = def`, the default `clinic` style, or `style = unpack` (where it names the function in the `takes no keyword arguments` error) — the C families defer unknown-kwarg errors past binding","messagePattern":"`kwarg_error_name` is only meaningful with `style = def`, the default `clinic` style, or `style = unpack` \\(where it names the function in the `takes no keyword arguments` error\\) — the C families defer unknown-kwarg errors past binding","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/monty-macros/src/from_args.rs","lineNumber":259,"sourceCode":"                return err(\n                    \"`at_most_total` cannot be combined with `style = def` or `style = unpack` \\\n                     — the total pre-count models `PyArg_ParseTupleAndKeywords`-family C parsers\",\n                );\n            }\n            if self.varargs_idx.is_some() || self.varkwargs_idx.is_some() {\n                return err(\"`at_most_total` cannot be combined with `varargs` or `varkwargs` \\\n                     — the up-front total-count check is only meaningful for \\\n                     signatures with a fixed maximum\");\n            }\n        }\n\n        if self.vectorcall && !(self.at_most_total && self.style == Style::Clinic) {\n            return err(\"`vectorcall` requires the default `clinic` style plus `at_most_total` \\\n                 — it models a `tp_vectorcall` fast path in front of a clinic parser\");\n        }\n\n        if self.kwarg_error_name.is_some() && !matches!(self.style, Style::Def | Style::Clinic | Style::Unpack) {\n            return err(\"`kwarg_error_name` is only meaningful with `style = def`, the default \\\n                 `clinic` style, or `style = unpack` (where it names the function in the \\\n                 `takes no keyword arguments` error) — the C families defer unknown-kwarg \\\n                 errors past binding\");\n        }\n\n        if self.kwargs_not_supported_yet {\n            if self.varkwargs_idx.is_some() {\n                return err(\"`kwargs_not_supported_yet` cannot be combined with `varkwargs` \\\n                     — the flag rejects every kwarg up front, so there's nothing to collect\");\n            }\n            if self.fields.iter().any(|f| matches!(f.kind, FieldKind::KwOnly)) {\n                return err(\"`kwargs_not_supported_yet` cannot be combined with `kw_only` fields \\\n                     — the flag rejects every kwarg up front, so kw_only slots are unreachable\");\n            }\n            if self.kwarg_error_name.is_some() {\n                return err(\"`kwargs_not_supported_yet` cannot be combined with `kwarg_error_name` \\\n                     — the override only applies to the unknown-kwarg dispatch path, which is skipped\");\n            }","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-macros/src/from_args.rs#L241-L277","documentation":"The `kwarg_error_name` attribute was set on a struct using one of the C parser styles (`c` or `c_named`). This option only affects the unknown-kwarg error text in `def`, `clinic`, and `unpack` styles; the C families defer unknown-keyword errors past binding, so the name override would never be used and the macro rejects it.","triggerScenarios":"Compiling `#[derive(FromArgs)] #[from_args(style = \"c\", kwarg_error_name = \"my_func\")]` (or `style = \"c_named\"`). Checked in `Signature::validate` (crates/monty-macros/src/from_args.rs:258-263).","commonSituations":"Porting a struct from `clinic` to `c`/`c_named` for exact C-parser error semantics while leaving `kwarg_error_name` behind; copying the attribute from a neighboring clinic-style struct.","solutions":["Remove `kwarg_error_name` from the C-family struct — the C styles generate their own deferred unknown-kwarg errors.","If the custom name in the 'takes no keyword arguments' error matters, stay on the default `clinic` style (or `def`/`unpack`, where it is also accepted)."],"exampleFix":"// before\n#[derive(FromArgs)]\n#[from_args(style = \"c\", kwarg_error_name = \"my_func\")]\nstruct Args { a: i64 }\n\n// after\n#[derive(FromArgs)]\n#[from_args(style = \"c\")]\nstruct Args { a: i64 }","handlingStrategy":"validation","validationCode":"fn kwarg_error_name_allowed(style: &str, has_kwarg_error_name: bool) -> bool {\n    !has_kwarg_error_name || matches!(style, \"def\" | \"clinic\" | \"unpack\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["The C families (c, c_named) produce their own deferred unknown-kwarg errors; never attach kwarg_error_name to them.","When migrating clinic -> c_named, delete kwarg_error_name in the same change."],"tags":["rust","proc-macro","fromargs","compile-time"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}