You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Its problem is we can not use it for conversions using object protocols.
We have some conversion codes using object protocol.
For example, to extract Vec from a Python object, we try either Sequence and Buffer protocol, or only Sequence protocol via specialization, like
It's undesirable that we have to convert PyList or so into PySequence when we want to do conversion.
So we can use trait instead of struct PyBuffer or so.
This is an experimental proposal. Any feedback is welcome, but please consider that it's experimental.
TL; DR
We should have two traits
FromPyType
andFromPyProto
instead ofFromPyObject
.The problem of
FromPyObject
Currently, we have
FromPyObject
as a main interface to get a Rust type from a python object.It is defined as
It's general since it requires
PyAny
, but it has a problem: we can't raise compile error using Rust's type system.E.g.,
this code raises a runtime error.
To prevent this, we should allow just a set of python types to become a rust type.
E.g., we should have
The problem of
FromPyType
Its problem is we can not use it for conversions using object protocols.
We have some conversion codes using object protocol.
For example, to extract
Vec
from a Python object, we try eitherSequence
andBuffer
protocol, or onlySequence
protocol via specialization, like(https://github.com/PyO3/pyo3/blob/72003ec37a16634e3fdff1cd7f03ab8814ecde42/src/types/sequence.rs#L237-#L264)
This looks difficult to give an abstraction via type systems.
One solution is to use types corresponding to each protocols.
FromPyProto
It's undesirable that we have to convert
PyList
or so intoPySequence
when we want to do conversion.So we can use trait instead of
struct PyBuffer
or so.But this also needs specialization and... I'm still looking for a better design.
The text was updated successfully, but these errors were encountered: