{"record":{"id":"54798dea63fea2cd","repo":"pydantic/monty","slug":"at-most-total-cannot-be-combined-with-style-def-or-style","errorCode":null,"errorMessage":"`at_most_total` cannot be combined with `style = def` or `style = unpack` — the total pre-count models `PyArg_ParseTupleAndKeywords`-family C parsers","messagePattern":"`at_most_total` cannot be combined with `style = def` or `style = unpack` — the total pre-count models `PyArg_ParseTupleAndKeywords`-family C parsers","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/monty-macros/src/from_args.rs","lineNumber":241,"sourceCode":"                         signature can never raise too-many-positional, so the style has no effect\");\n                }\n            }\n            Style::Unpack => {\n                if self.fields.iter().any(|f| matches!(f.kind, FieldKind::PosOrKeyword)) {\n                    return err(\"`style = unpack` models a positional-only `PyArg_UnpackTuple` \\\n                         signature — every positional field must be `pos_only`\");\n                }\n                if self.varargs_idx.is_some() || self.varkwargs_idx.is_some() {\n                    return err(\"`style = unpack` cannot be combined with `varargs` or `varkwargs` \\\n                         — it models a fixed positional min..max range\");\n                }\n            }\n            Style::Clinic | Style::C | Style::CNamed => {}\n        }\n\n        if self.at_most_total {\n            if matches!(self.style, Style::Def | Style::Unpack) {\n                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 \\","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-macros/src/from_args.rs#L223-L259","documentation":"The `at_most_total` flag was set on a `#[derive(FromArgs)]` struct whose style is `def` or `unpack`. `at_most_total` emits an up-front total-argument-count check that mirrors the `PyArg_ParseTupleAndKeywords` family of C parsers; the `def` and `unpack` styles follow different parser models where that pre-count does not exist, so the combination is rejected rather than silently ignored.","triggerScenarios":"Compiling `#[derive(FromArgs)] #[from_args(style = \"def\", at_most_total)]` or the same with `style = \"unpack\"`. Checked in `Signature::validate` (crates/monty-macros/src/from_args.rs:239-245).","commonSituations":"Copying the `at_most_total` attribute from a C-family struct while changing style to `def` or `unpack`; cargo-culting the full attribute set when adapting a handler between styles.","solutions":["Remove `at_most_total` from the def- or unpack-style struct.","If the total pre-count check is required, keep the default `clinic` style (or use the `c`/`c_named` family), which supports `at_most_total`.","If you need both def-binding and a max-count check, enforce the count manually in the function body."],"exampleFix":"// before\n#[derive(FromArgs)]\n#[from_args(style = \"def\", at_most_total)]\nstruct Args { a: Value }\n\n// after\n#[derive(FromArgs)]\n#[from_args(style = \"def\")]\nstruct Args { a: Value }","handlingStrategy":"validation","validationCode":"// at_most_total is only valid for clinic/c/c_named styles:\nfn at_most_total_allowed(style: &str) -> bool {\n    matches!(style, \"clinic\" | \"c\" | \"c_named\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep at_most_total paired only with the C-parser-family styles it models.","When changing a struct's style, re-check every modifier flag in the same edit."],"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-14T11:17:12.474Z"}