PyO3 / pyo3

Rust bindings for the Python interpreter
https://pyo3.rs
Other
11.44k stars 693 forks source link

RFC: rename `PyString` -> `PyStr`, and `PyLong` -> `PyInt` #4260

Open davidhewitt opened 2 weeks ago

davidhewitt commented 2 weeks ago

We currently have PyString to represent Python str, and PyLong to represent Python int.

While PyString is reasonably clear, PyLong is primarily a historical accident based on the fact that Python 2's integers were split between int and long types, and so the Python C API is based on PyLongObject etc.

Interestingly, we do currently expose PyInt as pyo3::types::PyInt as an import alias.

Similar history applies to PyString; we currently have a PyUnicode type alias kicking around which is again a throwback to Python 2's str and unicode split (they became approximately bytes and str respectively in Python 3).

I would propose the following:

The only counter-arguments I can see:

Subject to agreement from maintainers that we want to make this change, I think this is a relatively easy change to implement, so tentatively marking as "Good First Issue".

LilyFoote commented 2 weeks ago

Makes sense to me!

Stargateur commented 2 weeks ago

for me PyString make sense cause it's allocate.

davidhewitt commented 2 weeks ago

for me PyString make sense cause it's allocate.

I do like this argument tbh; and if we chose to leave PyString as-is and just update PyLong -> PyInt, this argument would be a somewhat reasonable justification (alongside the benefit of avoiding churn).

Icxolu commented 2 weeks ago

I also think PyString is fine as is. PyStr can also make the impression that is would somehow be coupled to Rust's &str, which it is not really. Renaming PyLong to PyInt sounds reasonable to me, given that long is neither a thing in Rust or Python, and PyInt makes is clearer what it refers to.

davidhewitt commented 1 week ago

It sounds like the conclusion here is PyString will stay as-is (we can deprecate the PyUnicode alias, I think, though).

On the other hand, we have broad agreement that PyLong -> PyInt is desirable.

Just need someone to find a moment implement, in that case 👍

shreyash2002 commented 1 week ago

Hi @davidhewitt I would love to do changes for PyLong -> PyInt.

I'm still a beginner in rust & open-source. So, this issue would be a good starting point for me

davidhewitt commented 1 week ago

Please feel free to go for it! I suggest starting with a PR and we can review and help iterate that way.