Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for from_py_with on struct tuples and enums #2181

Merged
merged 6 commits into from Feb 24, 2022

Conversation

ricohageman
Copy link
Contributor

Fixes #1441 by introducing from_py_with for tuple structs and enum.

@ricohageman ricohageman changed the title From py with tuple struct Add support for from_py_with on struct tuples and enums Feb 23, 2022
tests/test_frompyobject.rs Outdated Show resolved Hide resolved
tests/test_frompyobject.rs Outdated Show resolved Hide resolved
pyo3-macros-backend/src/frompyobject.rs Show resolved Hide resolved
pyo3-macros-backend/src/frompyobject.rs Outdated Show resolved Hide resolved
pyo3-macros-backend/src/frompyobject.rs Outdated Show resolved Hide resolved
@adamreichold
Copy link
Member

Concerning the failing test, isnt't the

obj.get_refcnt(unsafe { Python::assume_gil_acquired() })

part directly after releasing the GIL indeed not well-defined as it races with other test threads acquiring the GIL?

@adamreichold
Copy link
Member

adamreichold commented Feb 24, 2022

Concerning the failing test

This is obviously unrelated to this PR, I just wanted to bring it up so people more acquainted with that part of the code can shed some light on this.

@mejrs
Copy link
Member

mejrs commented Feb 24, 2022

Concerning the failing test, isnt't the

obj.get_refcnt(unsafe { Python::assume_gil_acquired() })

part directly after releasing the GIL indeed not well-defined as it races with other test threads acquiring the GIL?

Yes, this test should probably be rewritten. I'll do that in a bit.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, very grateful to see this implemented! It could be worth checking the guide to see if any documentation there would benefit from updating.

tests/test_frompyobject.rs Outdated Show resolved Hide resolved
@ricohageman
Copy link
Contributor Author

@davidhewitt thanks for pointing out the documentation. Currently the from_py_with annotation is only documented for functions. I would have expected it to be there for struct when it was introduced for normal structs. I've added some information regarding this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support from_py_with on struct tuples and enums
4 participants