Skip to content

Reduce too-many-branches across piccolo codebase#1398

Open
waniasantos wants to merge 13 commits into
piccolo-orm:masterfrom
grazi-lima:refactor/too-many-instance-branches
Open

Reduce too-many-branches across piccolo codebase#1398
waniasantos wants to merge 13 commits into
piccolo-orm:masterfrom
grazi-lima:refactor/too-many-instance-branches

Conversation

@waniasantos

@waniasantos waniasantos commented Jun 30, 2026

Copy link
Copy Markdown

Summary

Refactors 6 occurrences of Pylint's too-many-branches (R0912) by extracting cohesive blocks of conditional logic into smaller, well-named auxiliary methods. Consistent pattern applied across the codebase: large functions broken down by responsibility (engine-specific SQL handling, M2M result processing, clause building, column introspection), with no changes to existing business logic.

Refactored functions/methods

  • Table.__init_subclass__ (table.py)
  • Query._process_results (query/base.py)
  • Select.response_handler (query/methods/select.py)
  • Select.default_querystrings (query/methods/select.py)
  • Column.get_sql_value (columns/base.py)
  • create_table_class_from_db / get_column_default (apps/schema/commands/generate.py)

Validation

  • Full test suite (pytest) passes after each refactor
  • Pylint R0912 score: 10/10 on all affected functions/methods
  • No changes to the public API

Notes

  • get_column_default in generate.py was additionally refactored from a long if/elif chain into a dispatch table (dict), which more cleanly eliminates the branch count without adding auxiliary methods
  • The extracted helpers in Select.response_handler and Query._process_results follow the same naming convention established in previous refactors on this branch, keeping the split consistent across the query layer

@waniasantos waniasantos marked this pull request as ready for review June 30, 2026 12:53
@dantownsend

Copy link
Copy Markdown
Member

Thanks for this. It looks like one test failed.

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.

3 participants