{"record":{"id":"210835e83973fb1a","repo":"PyO3/pyo3","slug":"named-fields-should-have-identifiers","errorCode":null,"errorMessage":"Named fields should have identifiers","messagePattern":"Named fields should have identifiers","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pyo3-macros-backend/src/frompyobject.rs","lineNumber":212,"sourceCode":"                    let field = tuple_fields.pop().unwrap();\n                    ContainerType::TupleNewtype(field.from_py_with, Box::new(field.ty))\n                } else if options.transparent.is_some() {\n                    bail_spanned!(\n                        fields.span() => \"transparent structs and variants can only have 1 field\"\n                    );\n                } else {\n                    ContainerType::Tuple(tuple_fields)\n                }\n            }\n            Fields::Named(named) if !named.named.is_empty() => {\n                let mut struct_fields = named\n                    .named\n                    .iter()\n                    .map(|field| {\n                        let ident = field\n                            .ident\n                            .as_ref()\n                            .expect(\"Named fields should have identifiers\");\n                        let mut attrs = FieldAttributes::from_attrs(&field.attrs)?;\n\n                        if let Some(ref from_item_all) = options.from_item_all {\n                            if let Some(replaced) = attrs.getter.replace(FieldGetter::GetItem(parse_quote!(item), None))\n                            {\n                                match replaced {\n                                    FieldGetter::GetItem(item, Some(item_name)) => {\n                                        attrs.getter = Some(FieldGetter::GetItem(item, Some(item_name)));\n                                    }\n                                    FieldGetter::GetItem(_, None) => bail_spanned!(from_item_all.span() => \"Useless `item` - the struct is already annotated with `from_item_all`\"),\n                                    FieldGetter::GetAttr(_, _) => bail_spanned!(\n                                        from_item_all.span() => \"The struct is already annotated with `from_item_all`, `attribute` is not allowed\"\n                                    ),\n                                }\n                            }\n                        }\n\n                        Ok(NamedStructField {","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/PyO3/pyo3/blob/ac9b6899d348be4d54614d060dea53a645a12e36/pyo3-macros-backend/src/frompyobject.rs#L194-L230","documentation":"When building FromPyObject extraction for a struct with named fields, pyo3 expects each syn::Field in a named-fields struct to have an identifier. `field.ident` is None only for tuple-variant fields, so encountering None here is an internal invariant violation and panics with 'Named fields should have identifiers'.","triggerScenarios":"Deriving FromPyObject on data where the code path for named fields receives an unnamed (tuple) field — typically a bug in the derive internals or mismatched variant/field handling, e.g. a unit or tuple variant routed through the named-field branch.","commonSituations":"Using pyo3 derive macros on unusual shape definitions (tuple structs handled by the wrong branch); bugs in macro-generated code; version-specific derive bugs.","solutions":["Check you're deriving FromPyObject on a struct/variant with named fields, not a tuple or unit variant","Use the appropriate derive/impl path for tuple structs (positional extraction)","Update pyo3 — if this panics on valid named-field input it's a macro bug worth reporting"],"exampleFix":"// before\n#[derive(FromPyObject)]\nstruct Point(f64, f64); // tuple struct hitting named-field path\n// after\n#[derive(FromPyObject)]\nstruct Point { x: f64, y: f64 }","handlingStrategy":"validation","validationCode":"// ensure derived items use named fields for the named-field path\nmatch data {\n    syn::Data::Struct(d) if matches!(d.fields, syn::Fields::Named(_)) => Ok(()),\n    _ => Err(\"named-field derive requires named fields\".into()),\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive FromPyObject only on structs with named fields (or proper variant kinds)","Route tuple structs to positional handling","Update pyo3 if valid input triggers this internal panic"],"tags":["rust","pyo3","derive","internal"],"backgroundTag":"derive-invariant-violation","analyzedSha":"ac9b6899d348be4d54614d060dea53a645a12e36","analyzedAt":"2026-09-05T09:20:35.319Z","contentChangedAt":"2026-09-05T09:20:35.319Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}