pydantic/monty · error · syn::Error

`kwarg_error_name` is only meaningful with `style = def`…

Error message

`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

What it means

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.

Solutions

  1. Remove `kwarg_error_name` from the C-family struct — the C styles generate their own deferred unknown-kwarg errors.
  2. 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).

Example fix

// before
#[derive(FromArgs)]
#[from_args(style = "c", kwarg_error_name = "my_func")]
struct Args { a: i64 }

// after
#[derive(FromArgs)]
#[from_args(style = "c")]
struct Args { a: i64 }
Defensive patterns

Strategy: validation

Validate before calling

fn kwarg_error_name_allowed(style: &str, has_kwarg_error_name: bool) -> bool {
    !has_kwarg_error_name || matches!(style, "def" | "clinic" | "unpack")
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of pydantic/monty@adc986b362 (2026-09-13). Data as JSON: /api/errors/e19684d40da985cf. Report an issue: GitHub.

Appendix: source

Thrown at crates/monty-macros/src/from_args.rs:259

                return err(
                    "`at_most_total` cannot be combined with `style = def` or `style = unpack` \
                     — the total pre-count models `PyArg_ParseTupleAndKeywords`-family C parsers",
                );
            }
            if self.varargs_idx.is_some() || self.varkwargs_idx.is_some() {
                return err("`at_most_total` cannot be combined with `varargs` or `varkwargs` \
                     — the up-front total-count check is only meaningful for \
                     signatures with a fixed maximum");
            }
        }

        if self.vectorcall && !(self.at_most_total && self.style == Style::Clinic) {
            return err("`vectorcall` requires the default `clinic` style plus `at_most_total` \
                 — it models a `tp_vectorcall` fast path in front of a clinic parser");
        }

        if self.kwarg_error_name.is_some() && !matches!(self.style, Style::Def | Style::Clinic | Style::Unpack) {
            return err("`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");
        }

        if self.kwargs_not_supported_yet {
            if self.varkwargs_idx.is_some() {
                return err("`kwargs_not_supported_yet` cannot be combined with `varkwargs` \
                     — the flag rejects every kwarg up front, so there's nothing to collect");
            }
            if self.fields.iter().any(|f| matches!(f.kind, FieldKind::KwOnly)) {
                return err("`kwargs_not_supported_yet` cannot be combined with `kw_only` fields \
                     — the flag rejects every kwarg up front, so kw_only slots are unreachable");
            }
            if self.kwarg_error_name.is_some() {
                return err("`kwargs_not_supported_yet` cannot be combined with `kwarg_error_name` \
                     — the override only applies to the unknown-kwarg dispatch path, which is skipped");
            }

View on GitHub (pinned to adc986b362)