Summary
Rename python str related stuff to str instead of string in Rust side too.
Give the name string for abstract string type for places which require either str or bytes(-like).
Detailed Explanation
For now, Python str is belong to objstr and the implementation is PyString. So it is occupying both the names.
Because both bytes and str are conceptionally a string In python, the boundary of them is not very clear.
Some functions only take bytes, other functions only take str, but the other functions take both bytes and str.
By unifying the name str for python str and giving the name string to the conceptional common strings, we will have clear names for every use case of string-like objects.
example code with the name:
type PyStringArg = Either<PyStr, PyBytes>;
type PyStringLikeArg = Either<PyStr, PyBytesLike>;
#[pyfunction]
fn system(command: PyStringArg) -> ... {
unsafe { libc::system(command.as_bytes()) }
}
Drawbacks, Rationale, and Alternatives
Drawback
str and string doesn't give a clear idea about what they do for new comers.
string is still used in Python. The standard library string module will be an exception of this renaming.
Alternatives
CPython uses unicode and bytes for its code. But this is based on its historical name from Python2, not a decision for the name. We may follow this policy.
Any other suggestion to make clear their roles are welcomed.
Unresolved Questions
Summary
Rename python
strrelated stuff tostrinstead ofstringin Rust side too.Give the name
stringfor abstract string type for places which require eitherstrorbytes(-like).Detailed Explanation
For now, Python
stris belong toobjstrand the implementation isPyString. So it is occupying both the names.Because both
bytesandstrare conceptionally a string In python, the boundary of them is not very clear.Some functions only take
bytes, other functions only takestr, but the other functions take bothbytesandstr.By unifying the name
strfor pythonstrand giving the namestringto the conceptional common strings, we will have clear names for every use case of string-like objects.example code with the name:
Drawbacks, Rationale, and Alternatives
Drawback
strandstringdoesn't give a clear idea about what they do for new comers.stringis still used in Python. The standard librarystringmodule will be an exception of this renaming.Alternatives
CPython uses
unicodeandbytesfor its code. But this is based on its historical name from Python2, not a decision for the name. We may follow this policy.Any other suggestion to make clear their roles are welcomed.
Unresolved Questions