jnwatson / py-lmdb

Universal Python binding for the LMDB 'Lightning' Database
http://lmdb.readthedocs.io/
Other
646 stars 106 forks source link

Fix build with Python 3.13+ #368

Open hroncok opened 2 months ago

hroncok commented 2 months ago

Avoid using PyObject_AsReadBuffer, do what PyObject_AsReadBuffer does.

Note that this is not safe, and it has never been safe, but the code does exactly what it used to do (at least on Python 3.8+).

Fixes https://github.com/jnwatson/py-lmdb/issues/362

kloczek commented 2 months ago

Please do not use

#if PY_VERSION_HEX < 0x030d0000
   .
   .
#else
   .
   .
#endif

Because this makes that code not pyupgradeable. Please use

if sys.version_info < (3, 13):
   .
   .
else:
   .
   .

This would allow in the future drop first part of the code on use pyupgrade --py313. Or if you want to use that please first submit to pyupgrade PR which would allow recognise code like in your PR.

hroncok commented 2 months ago

Tomasz, this is C. Feel free to submit an alternate PR, but I won't try to figure out how to make changes in C pyupgradeable.