Fix #115166: Batch Rename Action Clips error #115185

Closed
Philipp Oeser wants to merge 1 commits from lichtwerk/blender:115166 into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Code from cd7ec0dac6 was assuming the selected IDs in the Outliner
were always objects, however actions can also be selected directly (in
Blender File view).

Code from cd7ec0dac6a8 was assuming the selected IDs in the Outliner were always objects, however actions can also be selected directly (in Blender File view).
Philipp Oeser added 1 commit 2023-11-20 14:46:51 +01:00
de785aa670 Fix #115166: Batch Rename Action Clips error
Code from cd7ec0dac6 was assuming the selected IDs in the Outliner
were always objects, however actions can also be selected directly (in
Blender File view).
Philipp Oeser requested review from Campbell Barton 2023-11-20 14:47:01 +01:00
Philipp Oeser requested review from Sybren A. Stüvel 2023-11-20 14:47:28 +01:00
Philipp Oeser added this to the User Interface project 2023-11-20 14:47:35 +01:00
Philipp Oeser added the
Interest
Animation & Rigging
label 2023-11-20 14:47:41 +01:00

The original code was already unnecessarily complex and hard to read. IMO before any more complexity is added, it should be refactored. I don't want to block a bugfix, but I also can't approve of the change, so I'll step down as reviewer.

The original code was already unnecessarily complex and hard to read. IMO before any more complexity is added, it should be refactored. I don't want to block a bugfix, but I also can't approve of the change, so I'll step down as reviewer.
Sybren A. Stüvel refused to review 2023-12-05 11:11:00 +01:00

@dr.sybren how are you suggesting to refactor the code. I would extract the logic out of the data = (..... tuple. But I'd like to have your opinion on that before I start doing things.
Also if I do a refactor, should that include all the areas in that function that generate data?

@dr.sybren how are you suggesting to refactor the code. I would extract the logic out of the `data = (.....` tuple. But I'd like to have your opinion on that before I start doing things. Also if I do a refactor, should that include all the areas in that function that generate `data`?

A few things that come to mind while reading the code of the WM_OT_batch_rename operator:

  • Type annotations, or at least documentation of expected types.
  • The if space_type == 'SEQUENCE_EDITOR': / elif / else chain should be replaced with some registry/strategy pattern, where each space type can be added by simply implementing some class/interface and adding it to the registry.
  • Split _data_from_context into two functions, for check_context=False and check_context=True. This might be considerably easier given the above step.
  • Use appropriate, ideally self-explaining data-structures. Having a tuple called data as a cheap class instance is super hard to follow.

But that's only when reading basically the _data_from_context function. So maybe these changes would be too limited. Long functions, deep nesting, mixing many different abstraction levels within the same function, all of these I would feel could use attention.

Things like assert 0 is of course unacceptable, as that should be at the bare minimum an exception with a clear explanation.

There are many more if/elif/else chains that can be converted to a strategy pattern, or at least be reduced to a dictionary lookup of some sort. For example, there are mulitple of such chains that all use action.type, which indicates that their code could be implemented as various functions on the same class, with one such class per action type.

Those are just some thoughts I get when browsing through the code.

A few things that come to mind while reading the code of the `WM_OT_batch_rename` operator: - Type annotations, or at least documentation of expected types. - The `if space_type == 'SEQUENCE_EDITOR':` / `elif` / `else` chain should be replaced with some registry/strategy pattern, where each space type can be added by simply implementing some class/interface and adding it to the registry. - Split `_data_from_context` into two functions, for `check_context=False` and `check_context=True`. This might be considerably easier given the above step. - Use appropriate, ideally self-explaining data-structures. Having a tuple called `data` as a cheap class instance is super hard to follow. But that's only when reading basically the `_data_from_context` function. So maybe these changes would be too limited. Long functions, deep nesting, mixing many different abstraction levels within the same function, all of these I would feel could use attention. Things like `assert 0` is of course unacceptable, as that should be at the bare minimum an exception with a clear explanation. There are many more `if`/`elif`/`else` chains that can be converted to a strategy pattern, or at least be reduced to a dictionary lookup of some sort. For example, there are mulitple of such chains that all use `action.type`, which indicates that their code could be implemented as various functions on the same class, with one such class per action type. Those are just some thoughts I get when browsing through the code.

Since this fix works, I think it'd be best to apply this for 4.1 and handle refactoring separately.

Since this fix works, I think it'd be best to apply this for 4.1 and handle refactoring separately.
Author
Member

Closing in favor of d4610e70db

Closing in favor of d4610e70dbd1531cd736ecbd6ac871d1131396ce
Philipp Oeser closed this pull request 2024-03-12 11:32:15 +01:00

Pull request closed

Sign in to join this conversation.
No reviewers
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
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#115185
No description provided.