Skip to content

[RFC] Rename strings #2065

Description

@youknowone

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRequest for comments

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions