Skip to content

Commit 713f51a

Browse files
bors[bot]qbx2
andauthored
Merge #2879
2879: Improve derive(FromPyObject) to apply intern! when applicable to get_item r=davidhewitt a=qbx2 This PR adds more `intern!`s to FromPyObject derive macro implementation. This should improve performance when using `#[pyo3(item)]`. Co-authored-by: Sunyeop Lee <[email protected]>
2 parents 556b3cf + 8026f35 commit 713f51a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

newsfragments/2879.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve `derive(FromPyObject)` to apply `intern!` when applicable to `#[pyo3(item)]`.

pyo3-macros-backend/src/frompyobject.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,13 @@ impl<'a> Container<'a> {
315315
FieldGetter::GetAttr(None) => {
316316
quote!(getattr(_pyo3::intern!(obj.py(), #field_name)))
317317
}
318+
FieldGetter::GetItem(Some(syn::Lit::Str(key))) => {
319+
quote!(get_item(_pyo3::intern!(obj.py(), #key)))
320+
}
318321
FieldGetter::GetItem(Some(key)) => quote!(get_item(#key)),
319-
FieldGetter::GetItem(None) => quote!(get_item(#field_name)),
322+
FieldGetter::GetItem(None) => {
323+
quote!(get_item(_pyo3::intern!(obj.py(), #field_name)))
324+
}
320325
};
321326
let extractor = match &field.from_py_with {
322327
None => {

0 commit comments

Comments
 (0)