{"record":{"id":"add48c1e0d601a24","repo":"PyO3/pyo3","slug":"empty-enum","errorCode":null,"errorMessage":"Empty enum","messagePattern":"Empty enum","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pyo3-macros-backend/src/frompyobject.rs","lineNumber":108,"sourceCode":"            ::core::result::Result::Err(\n                #pyo3_path::impl_::frompyobject::failed_to_extract_enum(\n                    obj.py(),\n                    #ty_name,\n                    &[#(#variant_names),*],\n                    &[#(#error_names),*],\n                    &errors\n                )\n            )\n        )\n    }\n\n    #[cfg(feature = \"experimental-inspect\")]\n    fn input_type(&self) -> PyExpr {\n        self.variants\n            .iter()\n            .map(|var| var.input_type())\n            .reduce(PyExpr::union)\n            .expect(\"Empty enum\")\n    }\n}\n\nstruct NamedStructField<'a> {\n    ident: &'a syn::Ident,\n    getter: Option<FieldGetter>,\n    from_py_with: Option<FromPyWithAttribute>,\n    default: Option<DefaultAttribute>,\n    ty: &'a syn::Type,\n}\n\nstruct TupleStructField {\n    from_py_with: Option<FromPyWithAttribute>,\n    ty: syn::Type,\n}\n\n/// Container Style\n///","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/PyO3/pyo3/blob/ac9b6899d348be4d54614d060dea53a645a12e36/pyo3-macros-backend/src/frompyobject.rs#L90-L126","documentation":"When generating `FromPyObject` implementations for an enum, pyo3 unions the input type expressions of all variants to know which Python types the enum can extract from. `reduce` on an empty iterator returns None, so an enum with zero variants panics with 'Empty enum'. Rust also disallows empty enums at the type level, so this usually indicates macro-generated or partially-written code.","triggerScenarios":"Deriving FromPyObject on a Rust enum declared with no variants, e.g. `enum Never {}` inside the pyo3 derive path.","commonSituations":"Placeholder empty enums left during refactors; code generators emitting enums with zero variants for empty unions/oneOf schemas.","solutions":["Add at least one variant to the enum","Remove the derive/impl for the empty enum and handle it explicitly (e.g. an uninhabited type converter)","Fix the code generator to skip empty enums"],"exampleFix":"// before\n#[derive(FromPyObject)]\nenum Shape {}\n// after\n#[derive(FromPyObject)]\nenum Shape {\n    Circle { r: f64 },\n    Square { s: f64 },\n}","handlingStrategy":"validation","validationCode":"// fail fast when generating derives for empty enums\nif variants.is_empty() { return Err(\"cannot derive FromPyObject on empty enum\".into()); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never derive FromPyObject on an empty enum","Fix schema generators to skip zero-variant enums","Remove placeholder empty enums before release"],"tags":["rust","pyo3","derive","enum"],"backgroundTag":"empty-enum-derive","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"}