pydantic/monty · error · syn::Error
unknown style `{other}`; expected `def`, `clinic`, `c`, `c_n
Error message
unknown style `{other}`; expected `def`, `clinic`, `c`, `c_named`, or `unpack` What it means
A compile-time error from the `FromArgs` derive macro's struct-attribute parser. The `#[from_args(style = "...")]` attribute only accepts one of `def`, `clinic`, `c`, `c_named`, or `unpack`; any other string is rejected with this message naming the invalid value.
Source
Thrown at crates/monty-macros/src/from_args.rs:790
}
attr.parse_nested_meta(|meta| {
if meta.path.is_ident("name") {
let value: LitStr = meta.value()?.parse()?;
name = Some(value.value());
Ok(())
} else if meta.path.is_ident("style") {
if style.is_some() {
return Err(meta.error("duplicate `style` attribute"));
}
let value: Ident = meta.value()?.parse()?;
style = Some(match value.to_string().as_str() {
"def" => Style::Def,
"clinic" => Style::Clinic,
"c" => Style::C,
"c_named" => Style::CNamed,
"unpack" => Style::Unpack,
other => {
return Err(syn::Error::new(
value.span(),
format!("unknown style `{other}`; expected `def`, `clinic`, `c`, `c_named`, or `unpack`"),
));
}
});
Ok(())
} else if meta.path.is_ident("at_most_total") {
at_most_total = true;
Ok(())
} else if meta.path.is_ident("vectorcall") {
vectorcall = true;
Ok(())
} else if meta.path.is_ident("kwarg_error_name") {
let value: LitStr = meta.value()?.parse()?;
kwarg_error_name = Some(value.value());
Ok(())
} else if meta.path.is_ident("bad_arg") {
if bad_arg.is_some() {View on GitHub (pinned to adc986b362)
Solutions
- Use one of the exact style names: `def`, `clinic`, `c`, `c_named`, or `unpack`
- Match the style to the CPython parser family of the target function (see crates/monty-macros/README.md for the family table)
- If no style is needed, remove the attribute entirely and let the default apply
Example fix
// before
#[derive(FromArgs)]
#[from_args(name = "f", style = "method")]
struct FArgs { x: i64 }
// after
#[derive(FromArgs)]
#[from_args(name = "f", style = "def")]
struct FArgs { x: i64 } Defensive patterns
Strategy: validation
Validate before calling
// Validate the style string before writing the attribute.
const STYLES: [&str; 5] = ["def", "clinic", "c", "c_named", "unpack"];
fn is_valid_style(s: &str) -> bool { STYLES.contains(&s) } Prevention
- Copy style names from an existing derive usage, not from memory
- Styles are lowercase snake_case: def, clinic, c, c_named, unpack
- Consult crates/monty-macros/README.md for which style matches the CPython parser family
When it happens
Trigger: Writing `#[from_args(style = "method")]`, `#[from_args(style = "C")]` (wrong case), a typo like `clinci`, or any other unrecognized style string on a struct deriving `FromArgs`.
Common situations: Guessing style names from CPython terminology, copying a style from a different macro family, or capitalization drift (`c` vs `C`).
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- positional-only fields must come before positional-or-keywor
- positional-or-keyword fields cannot appear after keyword-onl
- only one `#[from_args(varargs)]` field is allowed
- `varargs` cannot appear after keyword-only fields — Python h
- only one `#[from_args(varkwargs)]` field is allowed
AI-assisted analysis of pydantic/monty@adc986b362 (2026-09-13).
Data as JSON: /api/errors/8ac85d840c3c41bb.
Report an issue: GitHub.