From 1a16da1a1c17046f611cf93d1d918dff959cbcbe Mon Sep 17 00:00:00 2001 From: jakirkham Date: Tue, 15 Oct 2024 22:37:25 -0700 Subject: [PATCH] Simplify `_to_string` encoding of Python `str`s --- python/kvikio/kvikio/_lib/remote_handle.pyx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/python/kvikio/kvikio/_lib/remote_handle.pyx b/python/kvikio/kvikio/_lib/remote_handle.pyx index 5e58da32f0..93c6ac398a 100644 --- a/python/kvikio/kvikio/_lib/remote_handle.pyx +++ b/python/kvikio/kvikio/_lib/remote_handle.pyx @@ -40,11 +40,13 @@ cdef extern from "" nogil: size_t file_offset ) except + -cdef string _to_string(str_or_none): + +cdef string _to_string(str s): """Convert Python object to a C++ string (if None, return the empty string)""" - if str_or_none is None: + if s is not None: + return s.encode() + else: return string() - return str.encode(str(str_or_none)) cdef class RemoteFile: