From 968a5f9eb414357f4e2a1eec2afbef71772c1165 Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 7 Nov 2024 20:37:16 +0000 Subject: [PATCH] Added note to TypeError exceptions in GEOS WKTReader and WKBReader. --- django/contrib/gis/geos/prototypes/io.py | 4 ++-- tests/gis_tests/geos_tests/test_io.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/django/contrib/gis/geos/prototypes/io.py b/django/contrib/gis/geos/prototypes/io.py index efe9ec159f..05f597ccfc 100644 --- a/django/contrib/gis/geos/prototypes/io.py +++ b/django/contrib/gis/geos/prototypes/io.py @@ -156,7 +156,7 @@ class _WKTReader(IOBase): def read(self, wkt): if not isinstance(wkt, (bytes, str)): - raise TypeError + raise TypeError("'wkt' must be bytes or str.") return wkt_reader_read(self.ptr, force_bytes(wkt)) @@ -176,7 +176,7 @@ class _WKBReader(IOBase): wkb_s = wkb.encode() return wkb_reader_read_hex(self.ptr, wkb_s, len(wkb_s)) else: - raise TypeError + raise TypeError("'wkb' must be bytes, str or memoryview.") def default_trim_value(): diff --git a/tests/gis_tests/geos_tests/test_io.py b/tests/gis_tests/geos_tests/test_io.py index cab4b0ed5b..79ec3d053e 100644 --- a/tests/gis_tests/geos_tests/test_io.py +++ b/tests/gis_tests/geos_tests/test_io.py @@ -28,9 +28,10 @@ class GEOSIOTest(SimpleTestCase): self.assertEqual(ref, geom) # Should only accept string objects. - with self.assertRaises(TypeError): + msg = "'wkt' must be bytes or str." + with self.assertRaisesMessage(TypeError, msg): wkt_r.read(1) - with self.assertRaises(TypeError): + with self.assertRaisesMessage(TypeError, msg): wkt_r.read(memoryview(b"foo")) def test02_wktwriter(self):