[PR #3700] Refactor prepare_single_task to reduce cyclomatic complexity #3430

Closed
opened 2026-02-20 17:48:35 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/3700

State: closed
Merged: No


This pull request refactors the prepare_single_task function located in ./libs/langgraph/langgraph/pregel. Previously, the function had a very high cyclomatic complexity (scoring an F according to radon), making it hard to maintain and understand.

To address this, I have:

  • Divided the function into smaller, focused helper subfunctions.
  • Collapsed and simplified complex and nested if-statements.
  • Streamlined the overall logic without affecting the functionality.

These changes have improved the complexity rating from F to A. The refactor has been performed solely to improve code readability and maintainability, and the behavior of the function remains unchanged.

Please review the changes.

**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/3700 **State:** closed **Merged:** No --- This pull request refactors the `prepare_single_task` function located in `./libs/langgraph/langgraph/pregel`. Previously, the function had a very high cyclomatic complexity (scoring an F according to radon), making it hard to maintain and understand. To address this, I have: - Divided the function into smaller, focused helper subfunctions. - Collapsed and simplified complex and nested if-statements. - Streamlined the overall logic without affecting the functionality. These changes have improved the complexity rating from F to A. The refactor has been performed solely to improve code readability and maintainability, and the behavior of the function remains unchanged. Please review the changes.
yindo added the pull-request label 2026-02-20 17:48:35 -05:00
yindo closed this issue 2026-02-20 17:48:35 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#3430