From c056d03f9306a175390d8bcf16b091a23f2d62c2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 2 Nov 2024 15:43:26 +1100 Subject: [PATCH] Cleanup: move binary operator to line end in Python scripts --- .../examples/bpy.types.FileHandler.2.py | 16 +++-- intern/cycles/blender/addon/ui.py | 8 ++- .../startup/bl_operators/connect_to_output.py | 8 ++- scripts/startup/bl_ui/properties_freestyle.py | 24 +++---- .../bl_ui/properties_physics_dynamicpaint.py | 8 ++- .../bl_ui/properties_physics_rigidbody.py | 14 ++-- ...properties_physics_rigidbody_constraint.py | 66 ++++++++++++------- tests/python/curves_extrude.py | 8 ++- 8 files changed, 94 insertions(+), 58 deletions(-) diff --git a/doc/python_api/examples/bpy.types.FileHandler.2.py b/doc/python_api/examples/bpy.types.FileHandler.2.py index 8e1a09408a8..8b1e69d05da 100644 --- a/doc/python_api/examples/bpy.types.FileHandler.2.py +++ b/doc/python_api/examples/bpy.types.FileHandler.2.py @@ -37,10 +37,12 @@ class ShaderScriptImport(bpy.types.Operator, ImportHelper): @classmethod def poll(cls, context): - return (context.region and context.region.type == 'WINDOW' - and context.area and context.area.ui_type == 'ShaderNodeTree' - and context.object and context.object.type == 'MESH' - and context.material) + return ( + context.region and context.region.type == 'WINDOW' and + context.area and context.area.ui_type == 'ShaderNodeTree' and + context.object and context.object.type == 'MESH' and + context.material + ) def execute(self, context): """ The directory property need to be set. """ @@ -91,8 +93,10 @@ class SHADER_FH_script_import(bpy.types.FileHandler): @classmethod def poll_drop(cls, context): - return (context.region and context.region.type == 'WINDOW' - and context.area and context.area.ui_type == 'ShaderNodeTree') + return ( + context.region and context.region.type == 'WINDOW' and + context.area and context.area.ui_type == 'ShaderNodeTree' + ) bpy.utils.register_class(ShaderScriptImport) diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py index 681e2e82b37..8672d10dafe 100644 --- a/intern/cycles/blender/addon/ui.py +++ b/intern/cycles/blender/addon/ui.py @@ -72,9 +72,11 @@ class CyclesDebugButtonsPanel(CyclesButtonsPanel): @classmethod def poll(cls, context): prefs = bpy.context.preferences - return (CyclesButtonsPanel.poll(context) - and prefs.experimental.use_cycles_debug - and prefs.view.show_developer_ui) + return ( + CyclesButtonsPanel.poll(context) and + prefs.experimental.use_cycles_debug and + prefs.view.show_developer_ui + ) # Adapt properties editor panel to display in node editor. We have to diff --git a/scripts/startup/bl_operators/connect_to_output.py b/scripts/startup/bl_operators/connect_to_output.py index c506c0d90ce..78ca7995842 100644 --- a/scripts/startup/bl_operators/connect_to_output.py +++ b/scripts/startup/bl_operators/connect_to_output.py @@ -226,9 +226,11 @@ class NODE_OT_connect_to_output(Operator, NodeEditorBase): # Go up in the node group hierarchy. next_tree = path[path_index + 1].node_tree - node = next(n for n in next_tree.nodes - if n.type == 'GROUP' - and n.node_tree == tree) + node = next( + n for n in next_tree.nodes + if n.type == 'GROUP' and + n.node_tree == tree + ) tree = next_tree active_node_socket_id = viewer_socket.identifier return node.outputs[active_node_socket_id] diff --git a/scripts/startup/bl_ui/properties_freestyle.py b/scripts/startup/bl_ui/properties_freestyle.py index b0992f5b61f..2f6017cad36 100644 --- a/scripts/startup/bl_ui/properties_freestyle.py +++ b/scripts/startup/bl_ui/properties_freestyle.py @@ -63,10 +63,10 @@ class ViewLayerFreestyleButtonsPanel: with_freestyle = bpy.app.build_options.freestyle return ( - scene - and with_freestyle - and rd.use_freestyle - and (context.engine in cls.COMPAT_ENGINES) + scene and + with_freestyle and + rd.use_freestyle and + (context.engine in cls.COMPAT_ENGINES) ) @@ -79,9 +79,9 @@ class ViewLayerFreestyleEditorButtonsPanel(ViewLayerFreestyleButtonsPanel): return False view_layer = context.view_layer return ( - view_layer - and view_layer.use_freestyle - and view_layer.freestyle_settings.mode == 'EDITOR' + view_layer and + view_layer.use_freestyle and + view_layer.freestyle_settings.mode == 'EDITOR' ) @@ -1284,11 +1284,11 @@ class MaterialFreestyleButtonsPanel: material = context.material with_freestyle = bpy.app.build_options.freestyle return ( - with_freestyle - and material - and scene - and scene.render.use_freestyle - and (context.engine in cls.COMPAT_ENGINES) + with_freestyle and + material and + scene and + scene.render.use_freestyle and + (context.engine in cls.COMPAT_ENGINES) ) diff --git a/scripts/startup/bl_ui/properties_physics_dynamicpaint.py b/scripts/startup/bl_ui/properties_physics_dynamicpaint.py index 6d899c7853e..048e526886a 100644 --- a/scripts/startup/bl_ui/properties_physics_dynamicpaint.py +++ b/scripts/startup/bl_ui/properties_physics_dynamicpaint.py @@ -805,9 +805,11 @@ class PHYSICS_PT_dp_brush_source_color_ramp(PhysicButtonsPanel, Panel): return False brush = context.dynamic_paint.brush_settings - return ((brush.paint_source in {'DISTANCE', 'VOLUME_DISTANCE', 'POINT'}) - and (brush.proximity_falloff == 'RAMP') - and (context.engine in cls.COMPAT_ENGINES)) + return ( + (brush.paint_source in {'DISTANCE', 'VOLUME_DISTANCE', 'POINT'}) and + (brush.proximity_falloff == 'RAMP') and + (context.engine in cls.COMPAT_ENGINES) + ) def draw(self, context): layout = self.layout diff --git a/scripts/startup/bl_ui/properties_physics_rigidbody.py b/scripts/startup/bl_ui/properties_physics_rigidbody.py index 1f7e785dc13..fcff2205dbf 100644 --- a/scripts/startup/bl_ui/properties_physics_rigidbody.py +++ b/scripts/startup/bl_ui/properties_physics_rigidbody.py @@ -260,8 +260,10 @@ class PHYSICS_PT_rigid_body_dynamics(PHYSICS_PT_rigidbody_panel, Panel): obj = context.object if obj.parent is not None and obj.parent.rigid_body is not None: return False - return (obj and obj.rigid_body and obj.rigid_body.type == 'ACTIVE' - and (context.engine in cls.COMPAT_ENGINES)) + return ( + obj and obj.rigid_body and obj.rigid_body.type == 'ACTIVE' and + (context.engine in cls.COMPAT_ENGINES) + ) def draw(self, context): layout = self.layout @@ -295,9 +297,11 @@ class PHYSICS_PT_rigid_body_dynamics_deactivation(PHYSICS_PT_rigidbody_panel, Pa @classmethod def poll(cls, context): obj = context.object - return (obj and obj.rigid_body - and obj.rigid_body.type == 'ACTIVE' - and (context.engine in cls.COMPAT_ENGINES)) + return ( + obj and obj.rigid_body and + obj.rigid_body.type == 'ACTIVE' and + (context.engine in cls.COMPAT_ENGINES) + ) def draw_header(self, context): ob = context.object diff --git a/scripts/startup/bl_ui/properties_physics_rigidbody_constraint.py b/scripts/startup/bl_ui/properties_physics_rigidbody_constraint.py index 170c0fdbeff..28d4368f059 100644 --- a/scripts/startup/bl_ui/properties_physics_rigidbody_constraint.py +++ b/scripts/startup/bl_ui/properties_physics_rigidbody_constraint.py @@ -140,8 +140,10 @@ class PHYSICS_PT_rigid_body_constraint_limits(PHYSICS_PT_rigidbody_constraint_pa ob = context.object rbc = ob.rigid_body_constraint - return (ob and rbc and (rbc.type in {'GENERIC', 'GENERIC_SPRING', 'HINGE', 'SLIDER', 'PISTON'}) - and context.engine in cls.COMPAT_ENGINES) + return ( + ob and rbc and (rbc.type in {'GENERIC', 'GENERIC_SPRING', 'HINGE', 'SLIDER', 'PISTON'}) and + context.engine in cls.COMPAT_ENGINES + ) def draw(self, _context): return # do nothing. @@ -161,9 +163,11 @@ class PHYSICS_PT_rigid_body_constraint_limits_linear(PHYSICS_PT_rigidbody_constr ob = context.object rbc = ob.rigid_body_constraint - return (ob and rbc - and (rbc.type in {'GENERIC', 'GENERIC_SPRING', 'SLIDER', 'PISTON'}) - and context.engine in cls.COMPAT_ENGINES) + return ( + ob and rbc and + (rbc.type in {'GENERIC', 'GENERIC_SPRING', 'SLIDER', 'PISTON'}) and + context.engine in cls.COMPAT_ENGINES + ) def draw(self, context): layout = self.layout @@ -222,9 +226,11 @@ class PHYSICS_PT_rigid_body_constraint_limits_angular(PHYSICS_PT_rigidbody_const ob = context.object rbc = ob.rigid_body_constraint - return (ob and rbc - and (rbc.type in {'GENERIC', 'GENERIC_SPRING', 'HINGE', 'PISTON'}) - and context.engine in cls.COMPAT_ENGINES) + return ( + ob and rbc and + (rbc.type in {'GENERIC', 'GENERIC_SPRING', 'HINGE', 'PISTON'}) and + context.engine in cls.COMPAT_ENGINES + ) def draw(self, context): layout = self.layout @@ -292,8 +298,10 @@ class PHYSICS_PT_rigid_body_constraint_motor(PHYSICS_PT_rigidbody_constraint_pan ob = context.object rbc = ob.rigid_body_constraint - return (ob and rbc and rbc.type == 'MOTOR' - and context.engine in cls.COMPAT_ENGINES) + return ( + ob and rbc and rbc.type == 'MOTOR' and + context.engine in cls.COMPAT_ENGINES + ) def draw(self, _context): return # do nothing. @@ -313,8 +321,12 @@ class PHYSICS_PT_rigid_body_constraint_motor_angular(PHYSICS_PT_rigidbody_constr ob = context.object rbc = ob.rigid_body_constraint - return (ob and rbc and rbc.type == 'MOTOR' - and context.engine in cls.COMPAT_ENGINES) + return ( + ob and + rbc and + rbc.type == 'MOTOR' and + context.engine in cls.COMPAT_ENGINES + ) def draw_header(self, context): ob = context.object @@ -353,8 +365,10 @@ class PHYSICS_PT_rigid_body_constraint_motor_linear(PHYSICS_PT_rigidbody_constra ob = context.object rbc = ob.rigid_body_constraint - return (ob and rbc and rbc.type == 'MOTOR' - and context.engine in cls.COMPAT_ENGINES) + return ( + ob and rbc and rbc.type == 'MOTOR' and + context.engine in cls.COMPAT_ENGINES + ) def draw_header(self, context): ob = context.object @@ -393,9 +407,11 @@ class PHYSICS_PT_rigid_body_constraint_springs(PHYSICS_PT_rigidbody_constraint_p ob = context.object rbc = ob.rigid_body_constraint - return (ob and ob.rigid_body_constraint - and rbc.type == 'GENERIC_SPRING' - and context.engine in cls.COMPAT_ENGINES) + return ( + ob and ob.rigid_body_constraint and + rbc.type == 'GENERIC_SPRING' and + context.engine in cls.COMPAT_ENGINES + ) def draw(self, context): layout = self.layout @@ -421,9 +437,11 @@ class PHYSICS_PT_rigid_body_constraint_springs_angular(PHYSICS_PT_rigidbody_cons ob = context.object rbc = ob.rigid_body_constraint - return (ob and ob.rigid_body_constraint - and rbc.type == 'GENERIC_SPRING' - and context.engine in cls.COMPAT_ENGINES) + return ( + ob and ob.rigid_body_constraint and + rbc.type == 'GENERIC_SPRING' and + context.engine in cls.COMPAT_ENGINES + ) def draw(self, context): layout = self.layout @@ -473,9 +491,11 @@ class PHYSICS_PT_rigid_body_constraint_springs_linear(PHYSICS_PT_rigidbody_const ob = context.object rbc = ob.rigid_body_constraint - return (ob and ob.rigid_body_constraint - and rbc.type == 'GENERIC_SPRING' - and context.engine in cls.COMPAT_ENGINES) + return ( + ob and ob.rigid_body_constraint and + rbc.type == 'GENERIC_SPRING' and + context.engine in cls.COMPAT_ENGINES + ) def draw(self, context): layout = self.layout diff --git a/tests/python/curves_extrude.py b/tests/python/curves_extrude.py index 34fcb740a56..e5649a25ae5 100644 --- a/tests/python/curves_extrude.py +++ b/tests/python/curves_extrude.py @@ -103,9 +103,11 @@ class CurvesTest(ABC): if len(attribute.data.items()) != len(expected_attribute.data.items()): print("Attribute data length doesn't match") - value_attr_name = ('vector' if attribute.data_type == 'FLOAT_VECTOR' - or attribute.data_type == 'FLOAT2' else - 'color' if attribute.data_type == 'FLOAT_COLOR' else 'value') + value_attr_name = ( + 'vector' if attribute.data_type == 'FLOAT_VECTOR' or + attribute.data_type == 'FLOAT2' else + 'color' if attribute.data_type == 'FLOAT_COLOR' else 'value' + ) for v_idx, attribute_value in attribute.data.items(): if getattr(