Add support for PyFrozenDict#6174
Conversation
ee55a45 to
fd12ac9
Compare
|
I am a bit at a loss when it comes to the ffi checks. Pointers welcome |
|
AFAIK the header that contains this in CPython is (Not opining on any part of this patch.) |
|
Thanks I will try that. |
|
So the ffi-check situtation is a bit more complex since accessing the core headers requires Py_BUILD_CORE define. Is this something pyo3 maintainers would be willing to accept ? |
Icxolu
left a comment
There was a problem hiding this comment.
I'm also not an expert on the FFI layer, but here are some comment from my side.
(I haven't looked at the wrapping code, as we first need to get the FFI bindings correct.)
We should not be using any symbols from |
27e8799 to
b3a52c3
Compare
|
|
Icxolu
left a comment
There was a problem hiding this comment.
Thank you, I think we are getting closer. I went through the safe wrapper as well and left some comments below.
| #[inline] | ||
| #[cfg(Py_3_15)] | ||
| pub unsafe fn PyAnyDict_CheckExact(op: *mut PyObject) -> c_int { | ||
| (Py_TYPE(op) == &raw mut PyDict_Type || Py_TYPE(op) == &raw mut PyFrozenDict_Type) as c_int |
There was a problem hiding this comment.
| (Py_TYPE(op) == &raw mut PyDict_Type || Py_TYPE(op) == &raw mut PyFrozenDict_Type) as c_int | |
| (PyDict_CheckExact(op) != 0 || PyFrozenDict_CheckExact(op) != 0) as c_int |
To be consistent I think we should so this instead.
|
Thanks for the review. I have been fighthing a bit cfg when it comes to the limited API. I will have to look into your suggestions. |
|
I did a first pass in addressing the review and got clean clippy and test execution locally. The wrapper is now available without the limited API and the cfg are a bit more tiddy. I will check the CI run tomorrow and see if I missed anything else. |
Icxolu
left a comment
There was a problem hiding this comment.
Thank you, some smaller suggestions and some more cfg massaging is needed, but not too much more until we can land this I would say.
4efcac1 to
0373aee
Compare
|
Thanks for the early reviews @Icxolu I think I now have everything in order (including the cfgs). |
Icxolu
left a comment
There was a problem hiding this comment.
Thank you, looking good! Just one small comment regarding the constructor after which I think this is good to go.
| pub fn new<'py, T>(py: Python<'py>, iterable: T) -> PyResult<Bound<'py, PyFrozenDict>> | ||
| where | ||
| T: IntoPyObject<'py>, | ||
| err::PyErr: core::convert::From<<T as conversion::IntoPyObject<'py>>::Error>, |
There was a problem hiding this comment.
Typically the new constructor for similar types takes a Rust iterator. See for example PyFrozenSet or PyTuple. To be consistent I think we should follow that here as well.
I can see that it could be useful to build a PyFrozenDict directly from a Python. The equivalent on dict is called from_sequence, we can use the same here. Similarly we should not make that generic to make users aware that they need to check what they are passing in.
I also saw that for PyFrozenSet we have a PyFrozenSetBuilder. This could be useful for PyFrozenDict as well, out of scope for this PR, but could be a possible followup.
| } | ||
| } | ||
|
|
||
| #[cfg(all(Py_3_15, test))] |
There was a problem hiding this comment.
| #[cfg(all(Py_3_15, test))] | |
| #[cfg(test)] |
There was a problem hiding this comment.
#[cfg(Py_3_15)] on all entries should be enough here.
|
As a possible followup we can add support for a |
| #[inline] | ||
| #[cfg(Py_3_15)] | ||
| pub unsafe fn PyFrozenDict_CheckExact(op: *mut PyObject) -> c_int { | ||
| (Py_TYPE(op) == &raw mut PyFrozenDict_Type) as c_int |
There was a problem hiding this comment.
| (Py_TYPE(op) == &raw mut PyFrozenDict_Type) as c_int | |
| Py_IS_TYPE(op, &raw mut PyFrozenDict_Type) |
| (Py_TYPE(op) == &raw mut PyFrozenDict_Type | ||
| || PyType_IsSubtype(Py_TYPE(op), &raw mut PyFrozenDict_Type) != 0) as c_int |
There was a problem hiding this comment.
| (Py_TYPE(op) == &raw mut PyFrozenDict_Type | |
| || PyType_IsSubtype(Py_TYPE(op), &raw mut PyFrozenDict_Type) != 0) as c_int | |
| PyObject_TypeCheck(op, &raw mut PyFrozenDict_Type) |
No description provided.