Skip to content

refactor: extract _with_flow_seq_fallback helper from append/extend_list#50

Closed
nathanjmcdougall wants to merge 1 commit into
mainfrom
refactor/flow-seq-fallback-helper
Closed

refactor: extract _with_flow_seq_fallback helper from append/extend_list#50
nathanjmcdougall wants to merge 1 commit into
mainfrom
refactor/flow-seq-fallback-helper

Conversation

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

Addresses doc/todo/flow-sequence-fallback-duplication.md.

append() and extend_list() had identical try/except blocks: attempt the operation, catch PatchError, check for FLOW_SEQUENCE or NOT_A_SEQUENCE, fall back to get→mutate→replace. Extracted into _with_flow_seq_fallback(keys, patches, fallback_fn).

insert() is unchanged — it uses BLOCK_SEQUENCE_EXPECTED (a single kind covering both the flow and non-sequence cases) and needs an isinstance check, so it doesn't fit the same pattern.

Net: −22 lines, append and extend_list each collapse to two lines.

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator Author

Closing this — on reflection the helper is too shallow to justify the indirection.

The function interface is clunky: callers still compute
oute for patch construction, then the helper recomputes it independently in the fallback path. insert() doesn't fit the pattern at all (different error kind + isinstance check), so the abstraction doesn't generalize. For only 2 call sites with slightly different lambdas, the inline duplication is actually easier to follow — the reader sees the full error-handling story in one place without jumping to a callback-based helper.

The original 9-12 line try/except blocks in �ppend and �xtend_list are straightforward and self-contained. The cost of the duplication is low; the cost of the indirection (lambda stack frames, split control flow, awkward parameter set) outweighs it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant