Proposal - Targeted Refactoring For Cognitive Complexity in Core Modules

Hi all,

While doing a code ‘onboarding’, I ran a local SQ scan that flagged some areas for high cognitive complexity. One example would be _merge_splits()`in`langchain_text_splitters/base.py`. See the image below.

There are others, but this is not the point. What I am trying to sell is that I would be happy to refactor a small number of specific and high-value methods where cognitive complexity is actually costing readability.

Before anything, I wanted to check with the maintainers;

  • Are you open to targeted refactoring for cognitive complexity reduction?
  • If so, you prefer an issue first, labeled “refactor” to discuss the approach, or a PR

Separately, I could also suggest adding to CI/CD either complexipy or flake8-cognitive-complexity and run as an informational, non-blocking quality gate.

I totally understand that this could be a pain for a repo that large and complex as langchain, so I wanted to check the interests first.

Please, let me know your thoughts.

◦°˚(´•̛ᴗ•̛`)/˚°◦