Skip to content

refactor(python): harden support script parsing#145

Merged
acgetchell merged 2 commits into
mainfrom
refactor/142-python-boundary-parsing
Jun 5, 2026
Merged

refactor(python): harden support script parsing#145
acgetchell merged 2 commits into
mainfrom
refactor/142-python-boundary-parsing

Conversation

@acgetchell

@acgetchell acgetchell commented Jun 5, 2026

Copy link
Copy Markdown
Owner
  • Require Python 3.13 for support-script tooling and align Ruff/Ty with that baseline.
  • Replace mypy with strict Ty checking in the Python workflow.
  • Parse TOML, JSON, argparse, and Semgrep inputs into typed boundary objects before downstream use.
  • Reject malformed Criterion estimates, non-finite timings, invalid confidence intervals, and malformed Semgrep result shapes.

Closes #142

Summary by CodeRabbit

  • Chores

    • Raised project Python requirement to 3.13 and updated tooling configs.
    • Switched type-checking to the new typechecker and tightened CI checks.
    • Converted key dataclasses to slot-based, improving runtime efficiency.
  • New Features

    • Improved CLI and data-parsing validations with clearer error reporting.
    • Structured parsing for external tool results to reject malformed inputs.
  • Tests

    • Added comprehensive tests covering parsing, validation, and error cases.

- Require Python 3.13 for support-script tooling and align Ruff/Ty with that baseline.
- Replace mypy with strict Ty checking in the Python workflow.
- Parse TOML, JSON, argparse, and Semgrep inputs into typed boundary objects before downstream use.
- Reject malformed Criterion estimates, non-finite timings, invalid confidence intervals, and malformed Semgrep result shapes.

Closes #142
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 79e3ae13-3a93-47b8-a3cd-67a9399085b7

📥 Commits

Reviewing files that changed from the base of the PR and between 87e1d00 and b9e0ba0.

📒 Files selected for processing (1)
  • ty.toml

📝 Walkthrough

Walkthrough

This PR upgrades the project to Python 3.13, migrates type checking from mypy to ty, and refactors development scripts to parse and validate external inputs (TOML, JSON, CLI args) at boundaries into typed, validated objects before computation.

Changes

Python 3.13 Upgrade and Parse-at-Boundaries Refactoring

Layer / File(s) Summary
Python 3.13 & Type Checker Upgrade
.python-version, pyproject.toml, justfile
Project requirement bumped to Python 3.13. Ruff target version updated to py313. Mypy configuration block and mypy dev dependency removed from pyproject.toml. Type checking recipe switched from mypy to ty over scripts/ with --error all.
check_docs_version_sync Type Safety
scripts/check_docs_version_sync.py
Added ParsedObject alias and _is_parsed_object/_require_parsed_object TypeGuard helpers. PackageInfo and VersionMismatch dataclasses now include slots=True. _read_cargo_package_info refactored to use parsed-object validation.
check_semgrep_fixtures Structured Parsing
scripts/check_semgrep_fixtures.py, scripts/tests/test_check_semgrep_fixtures.py
Introduced ParsedObject alias and SemgrepResults frozen dataclass. Rewrote _semgrep_results() to read SEMGREP_JSON, validate top-level shape and each results entry, and return SemgrepResults. Updated main() to consume structured output. Added tests for valid/malformed payloads and fixture integration.
criterion_dim_plot Data Types & Validation
scripts/criterion_dim_plot.py
Added PlotCliArgs dataclass replacing argparse.Namespace. Row now implements __post_init__ validation enforcing dim>0, finite/non-negative timing values, and CI containment of point estimates. Added Protocols and ParsedObject alias for parsed content.
criterion_dim_plot Parsing & Function Signatures
scripts/criterion_dim_plot.py, scripts/tests/test_criterion_dim_plot.py
Added _is_parsed_object/_require_parsed_object helpers. Rewrote _read_estimate to validate stat presence/type, parse numeric fields robustly, and enforce CI invariants. Cargo TOML parsing routed through validators. _parse_args now returns PlotCliArgs. _maybe_update_readme and _maybe_render_plot accept narrowed Protocol-typed args. Tests expanded with many _read_estimate error cases and Row validation tests; existing markdown-table tests updated with valid CI bounds.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

  • acgetchell/la-stack#19: Modifies scripts/criterion_dim_plot.py in the same area of Cargo/TOML extraction and test updates; code-level related.

"🐰 From mypy's gaze to ty's keen eye,
Three scripts now parse ere they apply,
With slots so slim and types so clear,
Boundary guards stand steadfast here.
Python three‑thirteen hops on stage — hooray!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.70% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor(python): harden support script parsing' directly and concisely describes the main objective of the pull request - strengthening the type safety and validation in Python support scripts.
Linked Issues check ✅ Passed The changes comprehensively address all coding requirements from issue #142: Python baseline upgraded to 3.13, mypy replaced with Ty, explicit boundary parsing implemented with typed dataclasses and TypeGuard validators, and validation tests added.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #142 objectives: version upgrades (Python, pyproject.toml, justfile, ty.toml), tooling replacement (mypy→Ty), and hardened parsing in all affected scripts.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/142-python-boundary-parsing

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.61%. Comparing base (5bde071) to head (b9e0ba0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #145   +/-   ##
=======================================
  Coverage   99.61%   99.61%           
=======================================
  Files           5        5           
  Lines        2846     2846           
=======================================
  Hits         2835     2835           
  Misses         11       11           
Flag Coverage Δ
unittests 99.61% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@justfile`:
- Around line 495-496: Update ty.toml so ty type-checks against Python 3.13:
open ty.toml and change the python-version key from "3.12" to "3.13" to match
.python-version and pyproject.toml (this affects the python-typecheck target
invoked by the justfile); ensure there are no other references to 3.12 in
ty.toml that need updating so ty uses the correct stdlib/features for Python
3.13.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 06c993f2-92af-4139-ab4f-31bd3b67226a

📥 Commits

Reviewing files that changed from the base of the PR and between 5bde071 and 87e1d00.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • .python-version
  • justfile
  • pyproject.toml
  • scripts/check_docs_version_sync.py
  • scripts/check_semgrep_fixtures.py
  • scripts/criterion_dim_plot.py
  • scripts/tests/test_check_semgrep_fixtures.py
  • scripts/tests/test_criterion_dim_plot.py

Comment thread justfile
@acgetchell acgetchell self-assigned this Jun 5, 2026
@acgetchell acgetchell merged commit eeeb1e7 into main Jun 5, 2026
17 checks passed
@acgetchell acgetchell deleted the refactor/142-python-boundary-parsing branch June 5, 2026 18:28
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.

Update Python tooling to 3.13 and parse scripts at boundaries

1 participant