Skip to content

Conversation

@Andrej730
Copy link
Contributor

Support Literal[A,B,C] kind of types that started to be used in Blender codebase around Blender 5.0.

Diff for fake bpy module after this PR:

diff --git a/build_files/bmesh/types/__init__.pyi b/build_files/bmesh/types/__init__.pyi
index a641bb5..f19d629 100644
--- a/build_files/bmesh/types/__init__.pyi
+++ b/build_files/bmesh/types/__init__.pyi
@@ -1631,7 +1631,9 @@ class BMesh:
         loop_verts: collections.abc.Iterable[BMLoop] = (),
         loop_edges: collections.abc.Iterable[BMLoop] = (),
         faces: collections.abc.Iterable[BMFace] = (),
-        sticky_select_mode="SHARED_LOCATION",
+        sticky_select_mode: typing.Literal[
+            "SHARED_LOCATION", "DISABLED", "SHARED_VERTEX"
+        ] = "SHARED_LOCATION",
     ) -> None:
         """Set the UV selection state for loop-vertices, loop-edges & faces.This is a close equivalent to selecting in the UV editor.
 
@@ -1644,6 +1646,7 @@ class BMesh:
         :param faces: Faces to operate on.
         :type faces: collections.abc.Iterable[BMFace]
         :param sticky_select_mode: See UV_STICKY_SELECT_MODE_REF.
+        :type sticky_select_mode: typing.Literal['SHARED_LOCATION', 'DISABLED', 'SHARED_VERTEX']
         """
 
     def uv_select_foreach_set_from_mesh(
@@ -1654,7 +1657,9 @@ class BMesh:
         verts: collections.abc.Iterable[BMVert] = (),
         edges: collections.abc.Iterable[BMEdge] = (),
         faces: collections.abc.Iterable[BMFace] = (),
-        sticky_select_mode="SHARED_LOCATION",
+        sticky_select_mode: typing.Literal[
+            "SHARED_LOCATION", "DISABLED", "SHARED_VERTEX"
+        ] = "SHARED_LOCATION",
     ) -> None:
         """Select or de-select mesh elements, updating the UV selection.An equivalent to selecting from the 3D viewport for selection operations that support maintaining a synchronized UV selection.
 
@@ -1667,12 +1672,20 @@ class BMesh:
         :param faces: Faces to operate on.
         :type faces: collections.abc.Iterable[BMFace]
         :param sticky_select_mode: See UV_STICKY_SELECT_MODE_REF.
+        :type sticky_select_mode: typing.Literal['SHARED_LOCATION', 'DISABLED', 'SHARED_VERTEX']
         """
 
-    def uv_select_sync_from_mesh(self, *, sticky_select_mode="SHARED_LOCATION") -> None:
+    def uv_select_sync_from_mesh(
+        self,
+        *,
+        sticky_select_mode: typing.Literal[
+            "SHARED_LOCATION", "DISABLED", "SHARED_VERTEX"
+        ] = "SHARED_LOCATION",
+    ) -> None:
         """Sync selection from mesh to UVs.
 
         :param sticky_select_mode: Behavior when flushing from the mesh to UV selection UV_STICKY_SELECT_MODE_REF. This should only be used when preparing to create a UV selection.
+        :type sticky_select_mode: typing.Literal['SHARED_LOCATION', 'DISABLED', 'SHARED_VERTEX']
         """
 
     def uv_select_sync_to_mesh(self) -> None:
diff --git a/build_files/mathutils/__init__.pyi b/build_files/mathutils/__init__.pyi
index e26d5f9..2d9acc4 100644
--- a/build_files/mathutils/__init__.pyi
+++ b/build_files/mathutils/__init__.pyi
@@ -409,8 +409,11 @@ class Euler:
     :type: bool
     """
 
-    order: typing.Any
-    """ Euler rotation order."""
+    order: typing.Literal["XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX"]
+    """ Euler rotation order.
+
+    :type: typing.Literal['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX']
+    """
 
     owner: typing.Any
     """ The item this is wrapping or None  (read-only)."""
@@ -476,7 +479,7 @@ class Euler:
 
     def rotate_axis(
         self,
-        axis,
+        axis: typing.Literal["X", "Y", "Z"],
         angle: float,
         /,
     ) -> None:
@@ -484,6 +487,7 @@ class Euler:
         (no 720 degree pitches).
 
                 :param axis: An axis string.
+                :type axis: typing.Literal['X', 'Y', 'Z']
                 :param angle: angle in radians.
                 :type angle: float
         """
@@ -704,7 +708,9 @@ class Matrix:
     @classmethod
     def OrthoProjection(
         cls,
-        axis: Vector | collections.abc.Sequence[float],
+        axis: Vector
+        | collections.abc.Sequence[float]
+        | typing.Literal["X", "Y", "XY", "XZ", "YZ"],
         size: int,
         /,
     ) -> typing_extensions.Self:
@@ -713,7 +719,7 @@ class Matrix:
                 :param axis: An axis string,
         where a single axis is for a 2D matrix.
         Or a vector for an arbitrary axis
-                :type axis: Vector | collections.abc.Sequence[float]
+                :type axis: Vector | collections.abc.Sequence[float] | typing.Literal['X', 'Y', 'XY', 'XZ', 'YZ']
                 :param size: The size of the projection matrix to construct [2, 4].
                 :type size: int
                 :return: A new projection matrix.
@@ -725,7 +731,10 @@ class Matrix:
         cls,
         angle: float,
         size: int,
-        axis: Vector | collections.abc.Sequence[float] | None = [],
+        axis: Vector
+        | collections.abc.Sequence[float]
+        | typing.Literal["X", "Y", "Z"]
+        | None = [],
         /,
     ) -> typing_extensions.Self:
         """Create a matrix representing a rotation.
@@ -736,7 +745,7 @@ class Matrix:
                 :type size: int
                 :param axis: an axis string or a 3D Vector Object
         (optional when size is 2).
-                :type axis: Vector | collections.abc.Sequence[float] | None
+                :type axis: Vector | collections.abc.Sequence[float] | typing.Literal['X', 'Y', 'Z'] | None
                 :return: A new rotation matrix.
                 :rtype: typing_extensions.Self
         """
@@ -764,7 +773,7 @@ class Matrix:
     @classmethod
     def Shear(
         cls,
-        plane,
+        plane: typing.Literal["X", "Y", "XY", "XZ", "YZ"],
         size: int,
         factor: collections.abc.Sequence[float] | float,
         /,
@@ -773,6 +782,7 @@ class Matrix:
 
                 :param plane: An axis string,
         where a single axis is for a 2D matrix only.
+                :type plane: typing.Literal['X', 'Y', 'XY', 'XZ', 'YZ']
                 :param size: The size of the shear matrix to construct [2, 4].
                 :type size: int
                 :param factor: The factor of shear to apply. For a 2 size matrix use a single float. For a 3 or 4 size matrix pass a pair of floats corresponding with the plane axis.
@@ -1399,13 +1409,14 @@ class Quaternion:
 
     def to_euler(
         self,
-        order="XYZ",
+        order: typing.Literal["XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX"] = "XYZ",
         euler_compat: Euler | collections.abc.Sequence[float] | None = None,
         /,
     ) -> Euler:
         """Return Euler representation of the quaternion.
 
                 :param order: Rotation order.
+                :type order: typing.Literal['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX']
                 :param euler_compat: Optional euler argument the new euler will be made
         compatible with (no axis flipping between them).
         Useful for converting a series of matrices to animation curves.
@@ -1430,13 +1441,14 @@ class Quaternion:
 
     def to_swing_twist(
         self,
-        axis,
+        axis: typing.Literal["X", "Y", "Z"],
         /,
     ) -> tuple[Quaternion, float]:
         """Split the rotation into a swing quaternion with the specified
         axis fixed at zero, and the remaining twist rotation angle.
 
                 :param axis: Twist axis as a string.
+                :type axis: typing.Literal['X', 'Y', 'Z']
                 :return: Swing, twist angle.
                 :rtype: tuple[Quaternion, float]
         """
@@ -4006,14 +4018,16 @@ class Vector:
 
     def to_track_quat(
         self,
-        track="Z",
-        up="Y",
+        track: typing.Literal["-", "X", "Y", "Z", "-X", "-Y", "-Z"] = "Z",
+        up: typing.Literal["X", "Y", "Z"] = "Y",
         /,
     ) -> Quaternion:
         """Return a quaternion rotation from the vector and the track and up axis.
 
         :param track: Track axis string.
+        :type track: typing.Literal['-', 'X', 'Y', 'Z', '-X', '-Y', '-Z']
         :param up: Up axis string.
+        :type up: typing.Literal['X', 'Y', 'Z']
         :return: rotation from the vector and the track and up axis.
         :rtype: Quaternion
         """

@Andrej730 Andrej730 force-pushed the support-lliteral-types branch from 40708d6 to 03e11ae Compare November 3, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant