From f0affebaa305fec73d72a819c687afd351461a12 Mon Sep 17 00:00:00 2001 From: Joseph HENRY Date: Fri, 27 Mar 2026 18:25:34 +0100 Subject: [PATCH] Update 5.1 conformance tests with memoryview and euler, improve conformance output - Enable memoryview() tests in 5.1 conformance (Python 3.13 supports __buffer__) - Add test_mathutils_euler.py for 5.1 conformance - Show Python version in conformance check output Co-Authored-By: Claude Opus 4.6 (1M context) --- conformance/5.1/test_mathutils_color.py | 4 +-- conformance/5.1/test_mathutils_euler.py | 35 ++++++++++++++++++++ conformance/5.1/test_mathutils_matrix.py | 4 +-- conformance/5.1/test_mathutils_quaternion.py | 4 +-- conformance/5.1/test_mathutils_vector.py | 4 +-- main.py | 5 ++- 6 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 conformance/5.1/test_mathutils_euler.py diff --git a/conformance/5.1/test_mathutils_color.py b/conformance/5.1/test_mathutils_color.py index bd1711f..245f1bf 100644 --- a/conformance/5.1/test_mathutils_color.py +++ b/conformance/5.1/test_mathutils_color.py @@ -33,5 +33,5 @@ print( ) ) -# Direct buffer access is supported at runtime via C buffer protocol -# but not expressible in type stubs (requires Python 3.12+ __buffer__). +# Direct buffer access is supported. +print(memoryview(col).tobytes()) diff --git a/conformance/5.1/test_mathutils_euler.py b/conformance/5.1/test_mathutils_euler.py new file mode 100644 index 0000000..3a50ff2 --- /dev/null +++ b/conformance/5.1/test_mathutils_euler.py @@ -0,0 +1,35 @@ +import mathutils +import math + +# Create a new euler with default axis rotation order. +eul = mathutils.Euler((0.0, math.radians(45.0), 0.0), "XYZ") + +# Rotate the euler. +eul.rotate_axis("Z", math.radians(10.0)) + +# You can access its components by attribute or index. +print("Euler X", eul.x) +print("Euler Y", eul[1]) +print("Euler Z", eul[-1]) + +# Components of an existing euler can be set. +eul[:] = 1.0, 2.0, 3.0 + +# Components of an existing euler can use slice notation to get a tuple. +print("Values: {:f}, {:f}, {:f}".format(*eul)) + +# The order can be set at any time too. +eul.order = "ZYX" + +# Eulers can be used to rotate vectors. +vec = mathutils.Vector((0.0, 0.0, 1.0)) +vec.rotate(eul) + +# Often its useful to convert the euler into a matrix so it can be used as +# transformations with more flexibility. +mat_rot = eul.to_matrix() +mat_loc = mathutils.Matrix.Translation((2.0, 3.0, 4.0)) +mat = mat_loc @ mat_rot.to_4x4() + +# Direct buffer access is supported. +print(memoryview(eul).tobytes()) diff --git a/conformance/5.1/test_mathutils_matrix.py b/conformance/5.1/test_mathutils_matrix.py index 9e90814..92c5fcf 100644 --- a/conformance/5.1/test_mathutils_matrix.py +++ b/conformance/5.1/test_mathutils_matrix.py @@ -31,5 +31,5 @@ mat[0][0:3] = 0.0, 1.0, 2.0 # Each item in a matrix is a vector so vector utility functions can be used. mat[0].xyz = 0.0, 1.0, 2.0 -# Direct buffer access is supported at runtime via C buffer protocol -# but not expressible in type stubs (requires Python 3.12+ __buffer__). +# Direct buffer access is supported. +print(memoryview(mat).tobytes()) diff --git a/conformance/5.1/test_mathutils_quaternion.py b/conformance/5.1/test_mathutils_quaternion.py index 965ef80..0f0a4f7 100644 --- a/conformance/5.1/test_mathutils_quaternion.py +++ b/conformance/5.1/test_mathutils_quaternion.py @@ -36,5 +36,5 @@ quat_avg = mathutils.Quaternion(exp_avg) print("Average rotation:") print(quat_avg) -# Direct buffer access is supported at runtime via C buffer protocol -# but not expressible in type stubs (requires Python 3.12+ __buffer__). +# Direct buffer access is supported. +print(memoryview(quat_avg).tobytes()) diff --git a/conformance/5.1/test_mathutils_vector.py b/conformance/5.1/test_mathutils_vector.py index c5f1ddd..a2af1c1 100644 --- a/conformance/5.1/test_mathutils_vector.py +++ b/conformance/5.1/test_mathutils_vector.py @@ -54,5 +54,5 @@ vec.xy = vec4d.zw vec.xyz = vec4d.wzz vec4d.wxyz = vec.yxyx -# Direct buffer access is supported at runtime via C buffer protocol -# but not expressible in type stubs (requires Python 3.12+ __buffer__). +# Direct buffer access is supported. +raw_data = memoryview(vec).tobytes() diff --git a/main.py b/main.py index 30a5ed6..9ea65cb 100644 --- a/main.py +++ b/main.py @@ -433,7 +433,6 @@ def conformance_check(versions: list[str] | None = None) -> None: for version in versions: version_dir = dist_dir / version test_dir = conformance_dir / version - print(f"=== Conformance check against Blender {version} stubs ===") python_version_file = version_dir / ".python-version" python_version = ( @@ -442,6 +441,10 @@ def conformance_check(versions: list[str] | None = None) -> None: else "3.11" ) + print( + f"=== Conformance check against Blender {version} stubs with Python {python_version} ===" + ) + config = version_dir / "pyrightconfig.conformance.json" config.write_text( json.dumps(