{"record":{"id":"f70d10551146f728","repo":"pola-rs/polars","slug":"expected-a-type-argument","errorCode":null,"errorMessage":"expected a type argument","messagePattern":"expected a type argument","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pyo3-polars/pyo3-polars-derive/src/lib.rs","lineNumber":110,"sourceCode":"    })\n}\n\nfn create_expression_function(ast: syn::ItemFn) -> proc_macro2::TokenStream {\n    // count how often the user define a kwargs argument.\n    let args = ast\n        .sig\n        .inputs\n        .iter()\n        .skip(1)\n        .map(|fn_arg| {\n            if let FnArg::Typed(pat) = fn_arg {\n                if let syn::Pat::Ident(pat) = pat.pat.as_ref() {\n                    pat.ident.to_string()\n                } else {\n                    panic!(\"expected an argument\")\n                }\n            } else {\n                panic!(\"expected a type argument\")\n            }\n        })\n        .collect::<Vec<_>>();\n\n    let fn_name = &ast.sig.ident;\n\n    // Get the tokenstream of the call logic.\n    let quote_call = match args.len() {\n        0 => quote_call_no_kwargs(&ast, fn_name),\n        1 => match args[0].as_str() {\n            \"kwargs\" => quote_call_kwargs(&ast, fn_name),\n            \"context\" => quote_call_context(&ast, fn_name),\n            a => panic!(\"didn't expect argument {a}\"),\n        },\n        2 => match (args[0].as_str(), args[1].as_str()) {\n            (\"context\", \"kwargs\") => quote_call_context_kwargs(&ast, fn_name),\n            (\"kwargs\", \"context\") => panic!(\"'kwargs', 'context' order should be reversed\"),\n            (a, b) => panic!(\"didn't expect arguments {a}, {b}\"),","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/pyo3-polars/pyo3-polars-derive/src/lib.rs#L92-L128","documentation":"The same derive-macro signature walk panics with \"expected a type argument\" (lib.rs:110) when a function parameter is the receiver self (FnArg::Receiver) or otherwise not a typed pattern. #[polars_expr] functions must be free-standing functions with only typed, named parameters — methods and self receivers are rejected at compile time.","triggerScenarios":"Applying #[polars_expr] (via the polars_expr macro called by polars_expr derive) to a method with self/&self parameter, or to a signature where an argument is not FnArg::Typed.","commonSituations":"Putting the macro on an impl-block method; writing associated functions with self; generating signatures programmatically that include receivers.","solutions":["Move the function out of the impl block and make it a free function without self.","Convert method state into explicit parameters (e.g. pass the Series and literals as arguments).","Keep all parameters in `name: Type` form so the macro can enumerate and forward them."],"exampleFix":"// before\nimpl MyOps {\n    #[polars_expr(output_type=Int64)]\n    fn double(&self, x: &Series) -> PolarsResult<Column> { ... }\n}\n// after\n#[polars_expr(output_type=Int64)]\nfn double(x: &Series) -> PolarsResult<Column> { ... }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never attach #[polars_expr] to methods with self; use free functions.","Convert object state into explicit parameters before macro application.","Keep plugin expression functions in plain modules, not impl blocks."],"tags":["proc-macro","compile-time","function-signature","rust"],"backgroundTag":"invalid-argument-format","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}