From 2bb4abdc27001de2ab9225669eefb9f49f192004 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 28 Apr 2023 16:36:15 +1000 Subject: [PATCH] Cleanup: assign variables & use 'match' to avoid redundant lookups Also use more verbose names for RNA subtype enum variables. --- .../startup/bl_operators/geometry_nodes.py | 8 ++++--- scripts/startup/bl_operators/wm.py | 21 ++++++++++--------- .../startup/bl_ui/properties_data_armature.py | 3 ++- scripts/startup/bl_ui/properties_object.py | 7 ++++--- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/scripts/startup/bl_operators/geometry_nodes.py b/scripts/startup/bl_operators/geometry_nodes.py index d3f2db25b71..9ef0b40e382 100644 --- a/scripts/startup/bl_operators/geometry_nodes.py +++ b/scripts/startup/bl_operators/geometry_nodes.py @@ -43,9 +43,10 @@ def get_context_modifier(context): if context.area.type == 'PROPERTIES': modifier = context.modifier else: - if context.object is None: + ob = context.object + if ob is None: return False - modifier = context.object.modifiers.active + modifier = ob.modifiers.active if modifier is None or modifier.type != 'NODES': return None return modifier @@ -207,7 +208,8 @@ class NewGeometryNodesModifier(Operator): return geometry_modifier_poll(context) def execute(self, context): - modifier = context.object.modifiers.new(data_("GeometryNodes"), "NODES") + ob = context.object + modifier = ob.modifiers.new(data_("GeometryNodes"), 'NODES') if not modifier: return {'CANCELLED'} diff --git a/scripts/startup/bl_operators/wm.py b/scripts/startup/bl_operators/wm.py index 247cad330d7..c94892c7966 100644 --- a/scripts/startup/bl_operators/wm.py +++ b/scripts/startup/bl_operators/wm.py @@ -1357,10 +1357,10 @@ rna_custom_property_type_items = ( ('PYTHON', "Python", "Edit a python value directly, for unsupported property types"), ) -rna_generic_subtype_none_item = ('NONE', "Plain Data", "Data values without special behavior") +rna_custom_property_subtype_none_item = ('NONE', "Plain Data", "Data values without special behavior") -rna_number_subtype_items = ( - rna_generic_subtype_none_item, +rna_custom_property_subtype_number_items = ( + rna_custom_property_subtype_none_item, ('PIXEL', "Pixel", ""), ('PERCENTAGE', "Percentage", ""), ('FACTOR', "Factor", ""), @@ -1371,8 +1371,8 @@ rna_number_subtype_items = ( ('TEMPERATURE', "Temperature", ""), ) -rna_vector_subtype_items = ( - rna_generic_subtype_none_item, +rna_custom_property_subtype_vector_items = ( + rna_custom_property_subtype_none_item, ('COLOR', "Linear Color", "Color in the linear space"), ('COLOR_GAMMA', "Gamma-Corrected Color", "Color in the gamma corrected space"), ('EULER', "Euler Angles", "Euler rotation angles in radians"), @@ -1388,11 +1388,12 @@ class WM_OT_properties_edit(Operator): bl_options = {'REGISTER', 'INTERNAL'} def subtype_items_cb(self, context): - if self.property_type == 'FLOAT': - return rna_number_subtype_items - elif self.property_type == 'FLOAT_ARRAY': - return rna_vector_subtype_items - return [] + match self.property_type: + case 'FLOAT': + return rna_custom_property_subtype_number_items + case 'FLOAT_ARRAY': + return rna_custom_property_subtype_vector_items + return () def property_type_update_cb(self, context): self.subtype = 'NONE' diff --git a/scripts/startup/bl_ui/properties_data_armature.py b/scripts/startup/bl_ui/properties_data_armature.py index 6df04ae2340..6e56f598a56 100644 --- a/scripts/startup/bl_ui/properties_data_armature.py +++ b/scripts/startup/bl_ui/properties_data_armature.py @@ -110,7 +110,8 @@ class DATA_PT_bone_groups(ArmatureButtonsPanel, Panel): @classmethod def poll(cls, context): - return (context.object and context.object.type == 'ARMATURE' and context.object.pose) + ob = context.object + return (ob and ob.type == 'ARMATURE' and ob.pose) def draw(self, context): layout = self.layout diff --git a/scripts/startup/bl_ui/properties_object.py b/scripts/startup/bl_ui/properties_object.py index 30fd28ba727..91617c370cb 100644 --- a/scripts/startup/bl_ui/properties_object.py +++ b/scripts/startup/bl_ui/properties_object.py @@ -276,7 +276,7 @@ class OBJECT_PT_instancing_size(ObjectButtonsPanel, Panel): @classmethod def poll(cls, context): ob = context.object - return ob.instance_type == 'FACES' + return (ob is not None) and (ob.instance_type == 'FACES') def draw_header(self, context): @@ -304,7 +304,8 @@ class OBJECT_PT_lineart(ObjectButtonsPanel, Panel): def draw(self, context): layout = self.layout - lineart = context.object.lineart + ob = context.object + lineart = ob.lineart layout.use_property_split = True @@ -385,7 +386,7 @@ class OBJECT_PT_visibility(ObjectButtonsPanel, Panel): col.prop(ob, "hide_viewport", text="Viewports", toggle=False, invert_checkbox=True) col.prop(ob, "hide_render", text="Renders", toggle=False, invert_checkbox=True) - if context.object.type == 'GPENCIL': + if ob.type == 'GPENCIL': col = layout.column(heading="Grease Pencil") col.prop(ob, "use_grease_pencil_lights", toggle=False)