indygreg / python-zstandard

Python bindings to the Zstandard (zstd) compression library
BSD 3-Clause "New" or "Revised" License
499 stars 86 forks source link

Use PyType_Spec to define types instead of PyTypeObject. #187

Closed glandium closed 1 year ago

glandium commented 1 year ago

This is a first step towards possibly using the stable ABI.

glandium commented 1 year ago

Would it help if I split this change in pieces, one per type?

The only two things that (besides Py_buffer, which is in the stable API since 3.11) are not in the stable API are _PyBytes_Resize and Py_SET_SIZE. When I looked superficially, it seemed it might be possible to switch to bytearrays.

indygreg commented 1 year ago

Would it help if I split this change in pieces, one per type?

Yes.

The only two things that (besides Py_buffer, which is in the stable API since 3.11) are not in the stable API are _PyBytes_Resize and Py_SET_SIZE. When I looked superficially, it seemed it might be possible to switch to bytearrays.

In theory we could switch to bytearray. But I consider this an API change since it is a distinct type from bytes. I'll need to think about the implications. I want to say I support the backwards compatibility break - it's for a good cause.

I also recall there being issues in older versions of Python where bytearray wasn't exactly as interchangeable with bytes as it should be. My memory is fuzzy. Maybe it was only on versions of Python we no longer support? But I do recall wanting to use bytearray at some point and something discouraged me from doing it. Maybe I left a breadcrumb somewhere...

indygreg commented 1 year ago

I'm going to ship the next release with zstd 1.5.4 to get that out the door. Then I'm going to drop Python 3.6 support. Then I'll look at this PR. And possibly start chipping at moving to the stable API so we can ship fewer wheels.