From 0b54a1b41ce1db5e937f89ccecb559053484cbd8 Mon Sep 17 00:00:00 2001 From: Jongbin Jung Date: Sat, 5 Oct 2024 12:43:00 -0700 Subject: [PATCH 1/2] Add test for string subtypes --- tests/test_apis/test_basic_str.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_apis/test_basic_str.py b/tests/test_apis/test_basic_str.py index 0c65a8272..fccc164f0 100644 --- a/tests/test_apis/test_basic_str.py +++ b/tests/test_apis/test_basic_str.py @@ -22,3 +22,22 @@ def test5(): out = h3.grid_disk('8928308280fffff', 1) assert u.same_set(out, expected) + + +def test_string_subtypes(): + + class my_str(str): + pass + + expected = [ + '89283082873ffff', + '89283082877ffff', + '8928308283bffff', + '89283082807ffff', + '8928308280bffff', + '8928308280fffff', + '89283082803ffff' + ] + + out = h3.grid_disk(my_str('8928308280fffff'), 1) + assert u.same_set(out, expected) From 0b96c193fb06d8390e5335d4116e2de0fa4f695d Mon Sep 17 00:00:00 2001 From: Jongbin Jung Date: Sat, 5 Oct 2024 12:31:55 -0700 Subject: [PATCH 2/2] Allow string subtypes as H3str --- src/h3/_cy/h3lib.pxd | 3 ++- src/h3/api/basic_int/__init__.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/h3/_cy/h3lib.pxd b/src/h3/_cy/h3lib.pxd index a578a8fe6..e91cc2df4 100644 --- a/src/h3/_cy/h3lib.pxd +++ b/src/h3/_cy/h3lib.pxd @@ -1,7 +1,8 @@ +# cython: c_string_type=unicode, c_string_encoding=utf8 from cpython cimport bool from libc.stdint cimport uint32_t, uint64_t, int64_t -ctypedef basestring H3str +ctypedef object H3str cdef extern from 'h3api.h': cdef int H3_VERSION_MAJOR diff --git a/src/h3/api/basic_int/__init__.py b/src/h3/api/basic_int/__init__.py index 992fce788..603596629 100644 --- a/src/h3/api/basic_int/__init__.py +++ b/src/h3/api/basic_int/__init__.py @@ -53,7 +53,7 @@ def str_to_int(h): int Unsigned 64-bit integer """ - return _cy.str_to_int(str(h)) + return _cy.str_to_int(h) def int_to_str(x):