Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor prepare_single_task to reduce cyclomatic complexity #3700

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

o1eg0
Copy link

@o1eg0 o1eg0 commented Mar 5, 2025

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.

- Split the function into helper subfunctions.
- Simplify bulky nested if-statements.
- Maintain original functionality.
Copy link

vercel bot commented Mar 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langgraph-docs-preview ⬜️ Ignored (Inspect) Visit Preview Mar 5, 2025 6:45pm

Copy link
Contributor

@nfcampos nfcampos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont mind merging this in, but the helper functions should be defined at module top-level, not redefined every time the outer function runs

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.

2 participants