From a4bc7398f42bf9cfc1983f09ffa857f58c04c0e9 Mon Sep 17 00:00:00 2001 From: Hashim1999164 <64767361+Hashim1999164@users.noreply.github.com> Date: Sun, 23 Aug 2026 01:32:12 +0500 Subject: [PATCH] Raise ValueError instead of assert in geo_to_h3shape The leftover assert isinstance check tripped Bandit and was marked for removal. Invalid inputs now get an explicit ValueError. --- src/h3/_h3shape.py | 6 +++++- tests/test_lib/polyfill/test_h3.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/h3/_h3shape.py b/src/h3/_h3shape.py index 7aa7f628..a8146df0 100644 --- a/src/h3/_h3shape.py +++ b/src/h3/_h3shape.py @@ -301,7 +301,11 @@ def geo_to_h3shape(geo): # get dict geo = geo.__geo_interface__ - assert isinstance(geo, dict) # todo: remove + if not isinstance(geo, dict): + raise ValueError( + 'geo must be a dict or implement __geo_interface__, got: ' + + str(type(geo)) + ) t = geo['type'] coord = geo['coordinates'] diff --git a/tests/test_lib/polyfill/test_h3.py b/tests/test_lib/polyfill/test_h3.py index 72ddd586..fed297f8 100644 --- a/tests/test_lib/polyfill/test_h3.py +++ b/tests/test_lib/polyfill/test_h3.py @@ -302,6 +302,11 @@ def test_geo_to_h3shape_passthrough(): assert h3.geo_to_h3shape(shape) is shape +def test_geo_to_h3shape_rejects_non_dict(): + with pytest.raises(ValueError, match='dict or implement __geo_interface__'): + h3.geo_to_h3shape('not a geo object') + + def test_polyfill_down_under(): sydney = [ (-33.8556, 151.1979),