Improve derive(FromPyObject) to apply intern! when applicable

This commit is contained in:
Sunyeop Lee 2023-01-14 04:02:20 +09:00 committed by David Hewitt
parent 556b3cf48a
commit 8026f3521e
2 changed files with 7 additions and 1 deletions

View File

@ -0,0 +1 @@
Improve `derive(FromPyObject)` to apply `intern!` when applicable to `#[pyo3(item)]`.

View File

@ -315,8 +315,13 @@ impl<'a> Container<'a> {
FieldGetter::GetAttr(None) => {
quote!(getattr(_pyo3::intern!(obj.py(), #field_name)))
}
FieldGetter::GetItem(Some(syn::Lit::Str(key))) => {
quote!(get_item(_pyo3::intern!(obj.py(), #key)))
}
FieldGetter::GetItem(Some(key)) => quote!(get_item(#key)),
FieldGetter::GetItem(None) => quote!(get_item(#field_name)),
FieldGetter::GetItem(None) => {
quote!(get_item(_pyo3::intern!(obj.py(), #field_name)))
}
};
let extractor = match &field.from_py_with {
None => {