Refactor: WM_OT_batch_rename #118967
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#118967
Loading…
Reference in New Issue
No description provided.
Delete Branch "ChrisLend/blender:refactor_wm_py"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
No functional changes.
This PR splits the function
_data_from_context
onWM_OT_batch_rename
Firstly it removes the parameter
check_context
. This bool would cause the functionto return something completely different.
Secondly it splits the code from the long
if/else
chains into separate functions.Which function is called is determined by a dictionary lookup.
This is in response to the feedback from @dr.sybren on #115185: Fix #115166: Batch Rename Action Clips error
I agree that we shouldn't be calling the functions like this.
WM_OT_batch_rename._get_edit_bone_data
as called from_data_from_context()
can just be refactored tocls._get_edit_bone_data()
, as_data_from_context()
is a class method. If a@staticmethod
needs to call functions from that same class, to me it's an indicator that it's not a static method at all, but should have been a@classmethod
.Depending on how unwieldy things become, I don't mind having these related functions all defined on the same class. It makes it clear tha they belong together.
Phew, this is quite a beast to untangle! Nice progress, and although I think there's lots else to improve, I think your choice to keep certain bits of code as-is is good. Small steps, makes it easier to figure out where things went wrong if bugs are introduced.
@ -2727,1 +2726,3 @@
def _data_from_context(cls, context, data_type, only_selected, *, check_context=False):
@staticmethod
def _data_type_from_context(context):
space_type = None if (context.space_data is None) else context.space_data.type
This can be simplified to:
or:
but I think the former is a bit nicer.
@ -2728,0 +2726,4 @@
@staticmethod
def _data_type_from_context(context):
space_type = None if (context.space_data is None) else context.space_data.type
space_type_mapping = {
These mappings are a bit strange, as their values seem to be keys into
space_type_mapping
andmode_mapping
defined in_data_from_context()
. Is this really a necessary indirection? Because if this can be avoided, and thesesomething → data type → function
mappings can be reduced tosomething → function
, those functions also don't have to test that they're being called for the right data type any more.Do you think that would be a possibility?
I think it would be possible but I'd prefer to do that in a second step. It seems risky to me trying that without understanding how the thing works
@dr.sybren with this PR there is an issue where you can only rename Collections in the outliner. I am considering splitting this PR into even smaller steps since I can't tell where that bug is coming from
Good idea.
going to drop this. This is too hairy code to get into in the near future
Pull request closed