Fix radon complexity warnings across browser table-view code + tests - #748
Merged
Merged
Conversation
All five files were in the radon ``cc --min C`` output (or for one test file, ``mi --min B``). Pure decomposition / consolidation, no behavior change. Production code: - ``intersections._compute_simple_m2m_intersections_batched`` (CC 12 → 6): extract ``_initialize_simple_m2m_buckets``, ``_union_simple_m2m_queries``, and ``_collect_simple_m2m_intersections``. Main function now reads as a 6-line pipeline. - ``order_by.BrowserOrderByView._add_comic_order_by`` (CC 11 → 1): split the order-key normalization out into ``_normalize_comic_order_key`` and the head-building branches into ``_comic_order_fields_head`` / ``_comic_sort_name_head`` / ``_comic_indexed_head``. Top-level method is now a 2-line orchestrator. - ``annotate.order.BrowserAnnotateOrderView.annotate_extra_order_values`` (CC 11 → 6): hoist the early-return predicate into ``_should_annotate_extras`` and the per-extra annotation map into ``_build_extra_annotations``. The applier function now reads top- to-bottom with no nested branches. Tests: - ``test_save_view_round_trips_table_fields`` (CC 11 → 4): extract ``_save_named_view`` and ``_load_saved_settings`` round-trip helpers; collapse four field-by-field assertions into a single dict-equality check against the live patch payload. - ``test_table_view_m2m_sort_groups_identical_sets`` (CC 19 → 5): extract ``_create_sibling_comic`` factory (replaces three ~12-line ``Comic.objects.create`` blocks) and ``_assert_genre_sort_classes`` for the equivalence-class verification. The class-counts assertion uses ``frozenset`` + ``sorted`` for a single equality check. - ``test_table_view_simple_m2m_intersections_share_one_union_query`` (CC 11 → 5): extract the seven-table ``or`` chain into a module- level ``_SIMPLE_M2M_THROUGH_TABLES`` tuple + a ``_count_through_table_queries`` helper that uses ``any()``. - ``tests/test_browser_table_response.py`` MI: B 17.08 → A 19.66 (driven by the function-level fixes above). Verified: ``bin/lint-complexity.sh`` clean, ``ruff check`` clean, 193 backend tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
All five files reported by
bin/lint-complexity.sh(radoncc --min Cplus themi --min Bfortest_browser_table_response.py) are now under threshold. Pure decomposition / consolidation — no behavior change.What changed
Production code
intersections._compute_simple_m2m_intersections_batched_initialize_simple_m2m_buckets,_union_simple_m2m_queries,_collect_simple_m2m_intersections. Main function reads as a 6-line pipeline.order_by.BrowserOrderByView._add_comic_order_by_normalize_comic_order_key(key resolution) and_comic_order_fields_head/_comic_sort_name_head/_comic_indexed_head(head-building branches). Top-level method is a 2-line orchestrator.annotate.order.BrowserAnnotateOrderView.annotate_extra_order_values_should_annotate_extrasand the per-extra annotation map into_build_extra_annotations.Tests
test_save_view_round_trips_table_fields_save_named_viewand_load_saved_settingsround-trip helpers; collapsed four field-by-field assertions into a single dict-equality check against the live patch payload.test_table_view_m2m_sort_groups_identical_sets_create_sibling_comicfactory (replaces three ~12-lineComic.objects.createblocks) and_assert_genre_sort_classes. The equivalence-class assertion usesfrozenset+sortedfor a single equality check.test_table_view_simple_m2m_intersections_share_one_union_queryorchain into a module-level_SIMPLE_M2M_THROUGH_TABLEStuple + a_count_through_table_querieshelper that usesany().File-level MI
tests/test_browser_table_response.py: B (17.08) → A (19.66). Driven entirely by the function-level fixes above; no other restructuring.Test plan
bin/lint-complexity.shclean (no functions over CC 10, no files at MI grade B)complexipyclean (no functions over CC 15)ruff checkcleanReviewer notes
_create_sibling_comictest helper is private to the test class and replicates thesetUpComic-creation shape with a uniformsize = 42 + issue_numberformula. Per-callsizekeeps cumulative-sum assertions in adjacent tests deterministic. (Existing tests didn't use the helper because their assertions don't constrainsizein ways that conflict with the formula — but if a future test does, override locally.)🤖 Generated with Claude Code