From 5c1d366813e46c6f9f2c71aa8b89e0c916a92b2f Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Fri, 17 Mar 2023 15:56:06 +0100 Subject: [PATCH] Python 2.0 added a warning on ByteStorage, so using UntypedStorage (#196) * Python 2.0 added a warning on ByteStorage, so using UntypedStorage directly for that version. Small error in their docs, `size` got renamed `nbytes`. * Remove unused work. --- bindings/python/src/lib.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index 0e4624d..7c01cba 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -371,10 +371,15 @@ impl Open { let py_filename: PyObject = filename.into_py(py); let size: PyObject = buffer.len().into_py(py); let shared: PyObject = false.into_py(py); - let kwargs = [(intern!(py, "shared"), shared), (intern!(py, "size"), size)] - .into_py_dict(py); + let (size_name, storage_name) = if version >= Version::new(2, 0, 0) { + (intern!(py, "nbytes"), intern!(py, "UntypedStorage")) + } else { + (intern!(py, "size"), intern!(py, "ByteStorage")) + }; + let kwargs = + [(intern!(py, "shared"), shared), (size_name, size)].into_py_dict(py); let storage = module - .getattr(intern!(py, "ByteStorage"))? + .getattr(storage_name)? .getattr(intern!(py, "from_file"))? .call((py_filename,), Some(kwargs))?; -- 2.43.0