From 8f9c1bc70a1965a4450e038888ed369f8e4a8dfb Mon Sep 17 00:00:00 2001 From: Daniel Pike Date: Fri, 24 Jul 2026 05:22:17 -0400 Subject: [PATCH] fix(python): default ImageResponse buffers to empty bytes/list image_data_uint8 was np.uint8(0) and image_data_float was 0.0, which breaks len()/frombuffer paths used throughout PythonClient samples. Align with vector-shaped RPC payloads. --- PythonClient/airsim/types.py | 4 ++-- PythonClient/tests/__init__.py | 1 + .../tests/test_image_response_types.py | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 PythonClient/tests/__init__.py create mode 100644 PythonClient/tests/test_image_response_types.py diff --git a/PythonClient/airsim/types.py b/PythonClient/airsim/types.py index 7aef005549..d4c63005fe 100644 --- a/PythonClient/airsim/types.py +++ b/PythonClient/airsim/types.py @@ -323,8 +323,8 @@ def __init__(self, camera_name, image_type, pixels_as_float = False, compress = class ImageResponse(MsgpackMixin): - image_data_uint8 = np.uint8(0) - image_data_float = 0.0 + image_data_uint8 = b"" + image_data_float = [] camera_position = Vector3r() camera_orientation = Quaternionr() time_stamp = np.uint64(0) diff --git a/PythonClient/tests/__init__.py b/PythonClient/tests/__init__.py new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/PythonClient/tests/__init__.py @@ -0,0 +1 @@ + diff --git a/PythonClient/tests/test_image_response_types.py b/PythonClient/tests/test_image_response_types.py new file mode 100644 index 0000000000..5f349de1da --- /dev/null +++ b/PythonClient/tests/test_image_response_types.py @@ -0,0 +1,21 @@ +import unittest + +from airsim.types import ImageResponse + + +class TestImageResponseDefaults(unittest.TestCase): + def test_default_buffers_are_empty_iterables(self): + r = ImageResponse() + self.assertIsInstance(r.image_data_uint8, (bytes, bytearray)) + self.assertEqual(len(r.image_data_uint8), 0) + self.assertIsInstance(r.image_data_float, list) + self.assertEqual(len(r.image_data_float), 0) + # Sample code paths + self.assertEqual(len(r.image_data_uint8), 0) + import numpy as np + arr = np.frombuffer(r.image_data_uint8, dtype=np.uint8) + self.assertEqual(arr.size, 0) + + +if __name__ == "__main__": + unittest.main()