Skip to content

[cleanup] clear radon C and deptry warnings on develop#38

Merged
VGonPa merged 4 commits into
developfrom
ws-cleanup-radon-deptry
May 25, 2026
Merged

[cleanup] clear radon C and deptry warnings on develop#38
VGonPa merged 4 commits into
developfrom
ws-cleanup-radon-deptry

Conversation

@VGonPa
Copy link
Copy Markdown
Owner

@VGonPa VGonPa commented May 25, 2026

Summary

Pure tech-debt cleanup. Clears the two warnings that survived on develop:

  • Radon WARN — 3 grade-C functions refactored down to A/B
  • Deptry WARN — 1 DEP003 false positive on the optional browser_cookie3 helper silenced

Behaviour unchanged. All 506 existing tests pass without modification — these are pure refactors plus a config tweak.

The four fixes

  1. validate.validate_judgment C(16) → A(2) — split into focused sub-validators (_validate_judgment_keys, _validate_summary, _validate_topics_list, _validate_primary_topic). Top-level orchestrator just concatenates errors and keeps the early-return on non-list topics.
  2. archive._archive_tweet_to_item C(11) → A(3) — extracted two substantive parsing helpers: _extract_archive_links (entities.urls navigation + domain derivation) and _extract_archive_media (extended/legacy media source selection + type normalisation + URL fallback).
  3. generate._render_index C(13) → B(10) — extracted _count_topic_frequency (the only non-rendering logic — nested loop + dict mutation). Stat counters and markdown emission stay inline; that's the function's actual job.
  4. pyproject.toml — added DEP003 = ["browser_cookie3"] to [tool.deptry.per_rule_ignores]. The helper is guarded by try/except ImportError in scripts/import_*_session.py and was already covered by DEP001; DEP003 surfaces on installs where the package gets pulled in via another extra. Comment updated to explain both. Chose the per-rule ignore over an [project.optional-dependencies] sessions group because the helper is install-on-demand and isn't part of the project's dependency surface.

Proof — scripts/check.sh SUMMARY

Before (develop)

  ✅ Ruff (linting)       PASS
  ✅ Ruff (format)        PASS
  ✅ Mypy (types)         PASS
  ⚠️  Radon (complexity)   WARN - Has grade C
  ✅ Bandit (security)    PASS
  ✅ Vulture (dead code)  PASS
  ✅ Interrogate (docs)   PASS - 84.0%
  ✅ Detect-secrets       PASS
  ✅ Tests                PASS - 506 tests
  ✅ Coverage             91%
  ⚠️  Deptry (deps)        WARN

After (this branch)

  ✅ Ruff (linting)       PASS
  ✅ Ruff (format)        PASS
  ✅ Mypy (types)         PASS
  ✅ Radon (complexity)   PASS - All A/B
  ✅ Bandit (security)    PASS
  ✅ Vulture (dead code)  PASS
  ✅ Interrogate (docs)   PASS - 84.9%
  ✅ Detect-secrets       PASS
  ✅ Tests                PASS - 506 tests
  ✅ Coverage             91%
  ✅ Deptry (deps)        PASS

Test plan

  • uv run pytest — 506 passed (unchanged count)
  • uv run ruff check src/ tests/ — All checks passed
  • uv run ruff format --check src/ tests/ — clean
  • uv run mypy --ignore-missing-imports src/ — no issues
  • bash scripts/check.sh — ALL CRITICAL CHECKS PASSED, zero warnings
  • Radon grade C count: 3 → 0
  • Deptry findings: 2 → 0

VGonPa added 4 commits May 25, 2026 16:05
Drops radon complexity from C(16) → A(2) for the orchestrator, with each
new sub-validator at A or B. Behaviour is unchanged: tests pass without
modification (506 passed).

Sub-validators introduced:
- _validate_judgment_keys (extra-key rejection)
- _validate_summary (presence + non-empty)
- _validate_topics_list (count bounds, dupes, vocab membership)
- _validate_primary_topic (presence, vocab membership, inclusion)

The orchestrator still owns the early-return on a non-list topics value
so callers see a single canonical error message.
Drops radon complexity from C(11) → A(3) by lifting the two list
comprehensions into named helpers with substantive parsing logic:

- _extract_archive_links: walks entities.urls, derives domain from
  expanded_url, filters missing entries
- _extract_archive_media: prefers extended_entities.media over
  entities.media, normalises type (video/animated_gif → "video"
  else "photo") and picks media_url_https with expanded_url fallback

Behaviour unchanged: all 506 tests pass without modification. The
helpers carry the dict-navigation + conditional URL selection that
the orchestrator no longer needs to spell out.
Drops radon complexity from C(13) → B(10) by lifting the topic-frequency
accumulation (the nested loop + dict mutation, the only substantive
non-rendering logic) into its own helper:

- _count_topic_frequency(items) -> dict[str, int]

The four corpus stat counters (bookmarks, own, noted, enriched) and the
markdown line assembly stay inline — they are the function's actual job,
and extracting them would be gold-plating. Radon now reports PASS
(All A/B). Behaviour unchanged: all 506 tests pass.
scripts/import_chrome_session.py and scripts/import_safari_session.py
import browser-cookie3 behind a guarded `try/except ImportError`. The
existing config already silenced DEP001 (undeclared); DEP003 (transitive)
was still surfacing because on some installs the package is pulled in
indirectly via another extra.

Chose the per-rule ignore over an `[project.optional-dependencies]
sessions` group because the helper is install-on-demand outside the
project's dependency surface — adding an extra would imply the project
ships the integration, which it does not. Comment updated to explain
both DEP001 and DEP003 are intentional.

scripts/check.sh now reports ✅ Deptry: PASS.
@VGonPa VGonPa merged commit f5029e3 into develop May 25, 2026
1 check passed
@VGonPa VGonPa deleted the ws-cleanup-radon-deptry branch May 25, 2026 14:11
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.

1 participant