Skip to content

Commit

Permalink
Merge #2879
Browse files Browse the repository at this point in the history
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 <sunyeop97@gmail.com>
  • Loading branch information
bors[bot] and qbx2 authored Jan 15, 2023
2 parents 556b3cf + 8026f35 commit 713f51a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions newsfragments/2879.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve `derive(FromPyObject)` to apply `intern!` when applicable to `#[pyo3(item)]`.
7 changes: 6 additions & 1 deletion pyo3-macros-backend/src/frompyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 713f51a

Please sign in to comment.