PyO3/pyo3 · error · syn::Error
useless `get` - the struct is already annotated with `get_al
Error message
useless `get` - the struct is already annotated with `get_all`
What it means
When a #[pyclass] is annotated with get_all, every field is automatically exposed as a getter; a per-field #[pyo3(get)] is then redundant and the macro (build_py_class) reports DUPE_GET at the field's span.
Source
Thrown at pyo3-macros-backend/src/pyclass.rs:332
let mut results = Vec::new();
if let Some(attr) = args.options.set_all {
results.push(Err(syn::Error::new_spanned(attr, UNIT_SET)));
};
if let Some(attr) = args.options.get_all {
results.push(Err(syn::Error::new_spanned(attr, UNIT_GET)));
};
results
}
}
.into_iter()
.try_combine_syn_errors()?;
if let Some(attr) = args.options.get_all {
for (_, FieldPyO3Options { get, .. }) in &mut field_options {
if let Some(old_get) = get.replace(Annotated::Struct(attr)) {
return Err(syn::Error::new(old_get.span(), DUPE_GET));
}
}
}
if let Some(attr) = args.options.set_all {
for (_, FieldPyO3Options { set, .. }) in &mut field_options {
if let Some(old_set) = set.replace(Annotated::Struct(attr)) {
return Err(syn::Error::new(old_set.span(), DUPE_SET));
}
}
}
impl_class(&class.ident, &args, doc, field_options, methods_type, ctx)
}
enum Annotated<X, Y> {
Field(X),
Struct(Y),View on GitHub (pinned to ac9b6899d3)
Solutions
- Remove the per-field #[pyo3(get)] attributes on fields where get_all already applies
- Remove get_all if only some fields should be getters
- Convert fields that need different visibility handling to explicit per-field annotations and drop get_all
Example fix
// before
#[pyclass(get_all)]
struct Point {
#[pyo3(get)]
x: f64,
y: f64,
}
// after
#[pyclass(get_all)]
struct Point {
x: f64,
y: f64,
} Defensive patterns
Strategy: validation
Validate before calling
# CI lint: flag #[pyo3(get)] inside structs whose pyclass has get_all # grep -A2 'pyclass(.*get_all' -r src/ | grep 'pyo3(get)' && exit 1
Prevention
- When introducing get_all, remove all per-field #[pyo3(get)] in the same change
- Keep one visibility convention per struct: all-fields or per-field, not both
- Run cargo check/clippy on PRs to catch macro errors early
When it happens
Trigger: Combining #[pyclass(get_all)] with #[pyo3(get)] on one or more fields of the struct.
Common situations: Refactoring a class to get_all without removing old per-field get annotations; copy-pasting field attributes from another struct.
Related errors
- useless `set` - the struct is already annotated with `set_al
- wildcard argument names are not supported
- failed to create type object for `{type_name}`
- Neither abi3 or abi3t features are enabled
- Cannot target an abi3t version below {MINIMUM_SUPPORTED_VERS
AI-assisted analysis of PyO3/pyo3@ac9b6899d3 (2026-09-05).
Data as JSON: /api/errors/23051454f589ce89.
Report an issue: GitHub.