-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
RFCRequest for commentsRequest for comments
Description
Summary
This is only about python objects like #[pymodule], #[pyclass], #[pyfunction], #[pymethod] and #[pyproperty].
Sometimes python names are not fit for rust naming convention.
- Though we can specify the name with
(name = "")attributes, we also need to decide how we give names for its rust side API. - There are also python names conflict to rust keywords. They also need a special rule because we normally cannot name them same in Rust.
Detailed Explanation
List of unmatching names.
- Python type
intis typePyIntin Rust API. - Python function
posix.WIFSIGNALEDisposix::wifsignaledin Rust. - Python type
_struct.erroris PyTypeRef objectpystruct::error_typein Rust. - Python type
_weakref.ReferenceTypeis a function returning PyTypeRef_weakref::reference_typein Rust. - Python variable
sys.api_versionis constsys::API_VERSIONin Rust. - Python variable
dis.COMPILER_FLAG_NAMESis a function returning PyDictRefdis::compiler_flag_namesin Rust.
We must handle types differently.
For example, we can expose &PyTypeRef for builtins::int() but PyInt through builtins::PyInt.
We can choose one of these kind of options for other names:
- Strictly follow Python names unless it is impossible.
- The names will not conflict.
- Some names will be
r#prefixed in Rust. They would need human-friendly aliases.
- Follow Python names as much as possible but with exceptions by its paired Rust type.
- For example,
_weakref.ReferenceTypeandintare both type in Python butPyTypeRefinstance andPyIntstruct for each in Rust. Similar for sys.api_version and dis.COMPILER_FLAG_NAMES
- Export a python-name aliased module separately. This can be generated by
derivemacros.
- For this choice, we can optionally suggest more consistency.
- We can expose variable always through a function call. A function to return a const will be generated.
- We can attach emitted
vmparameter again to functions.
- Still types will be problem.
List of keyword conflict.
structmodule.
- The exact python name is
_struct
modoperator.
- The exact python name is
__mod__
matchfunction.typetype.enummodule.
List of confusing non-keyword names.
booltypesstrtypesIteratorfor python and rust
Example of solutions
- Always keep python name using
r#. But allow alias. - Add additional
_suffix for conflicting type.matchwill bematch_. But allowr#alias. - Add
pyprefix like currentpybool,pytype,pystruct.
Drawbacks, Rationale, and Alternatives
Unresolved Questions
Everything. Any dicision will give concrete idea about public API design.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
RFCRequest for commentsRequest for comments