From 01e8af3348fac2babe3b5218dbe4ecdaa0e1eace Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sat, 12 Nov 2022 23:54:17 +0200 Subject: Rigify: annotate and fix warnings in basic rig components. Introduce a method to annotate types and names of entries in the `bones` container of rig components and apply it, and other type annotations, to a number of not very complex rig classes. - Introduce BaseRigMixin as a typed base class for mixins intended for use in rig classes (using BaseRig as a parent causes issues). - Introduce TypedBoneDict that does not suppress the unknown attribute analysis in PyCharm, and use it in a system of subclasses to annotate the bones in various rigs. BaseBoneDict is necessary because the annotation affects all subclasses, so TypedBoneDict cannot inherit from BoneDict with the annotation. - Add or adjust other type annotations of rig methods and utilities. - Fix other warnings, e.g. undeclared attributes, excessively long lines, whitespace style issues and typos. --- rigify/utils/animation.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'rigify/utils/animation.py') diff --git a/rigify/utils/animation.py b/rigify/utils/animation.py index 21aa2a89..6e0a9739 100644 --- a/rigify/utils/animation.py +++ b/rigify/utils/animation.py @@ -7,11 +7,15 @@ import math # noinspection PyUnresolvedReferences from mathutils import Matrix, Vector -from typing import Callable, Any, Collection, Iterator +from typing import TYPE_CHECKING, Callable, Any, Collection, Iterator, Optional, Sequence from bpy.types import Action, bpy_struct, FCurve import json +if TYPE_CHECKING: + from ..rig_ui_template import PanelLayout + + rig_id = None @@ -849,7 +853,7 @@ class POSE_OT_rigify_clear_keyframes(bpy.types.Operator): # noinspection PyDefaultArgument,PyUnusedLocal -def add_clear_keyframes_button(panel, *, bones=[], label='', text=''): +def add_clear_keyframes_button(panel: 'PanelLayout', *, bones: list[str] = [], label='', text=''): panel.use_bake_settings() panel.script.add_utilities(SCRIPT_UTILITIES_OP_CLEAR_KEYS) panel.script.register_classes(SCRIPT_REGISTER_OP_CLEAR_KEYS) @@ -921,8 +925,10 @@ class POSE_OT_rigify_generic_snap_bake(RigifyGenericSnapBase, RigifyBakeKeyframe '''] -def add_fk_ik_snap_buttons(panel, op_single, op_bake, *, label=None, rig_name='', properties=None, - clear_bones=None, compact=None): +def add_fk_ik_snap_buttons(panel: 'PanelLayout', op_single: str, op_bake: str, *, + label, rig_name='', properties: dict[str, Any], + clear_bones: Optional[list[str]] = None, + compact: Optional[bool] = None): assert label and properties if rig_name: @@ -944,8 +950,12 @@ def add_fk_ik_snap_buttons(panel, op_single, op_bake, *, label=None, rig_name='' # noinspection PyDefaultArgument -def add_generic_snap(panel, *, output_bones=[], input_bones=[], input_ctrl_bones=[], label='Snap', - rig_name='', undo_copy_scale=False, compact=None, clear=True, locks=None, tooltip=None): +def add_generic_snap(panel: 'PanelLayout', *, + output_bones: list[str] = [], input_bones: list[str] = [], + input_ctrl_bones: list[str] = [], label='Snap', + rig_name='', undo_copy_scale=False, compact: Optional[bool] = None, + clear=True, locks: Optional[Sequence[bool]] = None, + tooltip: Optional[str] = None): panel.use_bake_settings() panel.script.add_utilities(SCRIPT_UTILITIES_OP_SNAP) panel.script.register_classes(SCRIPT_REGISTER_OP_SNAP) @@ -972,8 +982,11 @@ def add_generic_snap(panel, *, output_bones=[], input_bones=[], input_ctrl_bones # noinspection PyDefaultArgument -def add_generic_snap_fk_to_ik(panel, *, fk_bones=[], ik_bones=[], ik_ctrl_bones=[], label='FK->IK', - rig_name='', undo_copy_scale=False, compact=None, clear=True): +def add_generic_snap_fk_to_ik(panel: 'PanelLayout', *, + fk_bones: list[str] = [], ik_bones: list[str] = [], + ik_ctrl_bones: list[str] = [], label='FK->IK', + rig_name='', undo_copy_scale=False, + compact: Optional[bool] = None, clear=True): add_generic_snap( panel, output_bones=fk_bones, input_bones=ik_bones, input_ctrl_bones=ik_ctrl_bones, label=label, rig_name=rig_name, undo_copy_scale=undo_copy_scale, compact=compact, clear=clear -- cgit v1.2.3