Skip to content

fix(types): annotate rank_rules_for_draft to satisfy pyright#82

Merged
Gradata merged 4 commits intomainfrom
fix/pyright-jit-inject
Apr 15, 2026
Merged

fix(types): annotate rank_rules_for_draft to satisfy pyright#82
Gradata merged 4 commits intomainfrom
fix/pyright-jit-inject

Conversation

@Gradata
Copy link
Copy Markdown
Owner

@Gradata Gradata commented Apr 15, 2026

Fixes 4 pyright errors at src/gradata/hooks/jit_inject.py:216 that have been blocking main CI. Pre-existing — not introduced by this PR.

Switches the return type from list[tuple[object, float]] to the actual Lesson type (imported from gradata._types). Approach (a) — clean import, no circular issues.

Local pyright on src/gradata/hooks/jit_inject.py: 0 errors, 0 warnings, 0 informations.

Unblocks PR #76 (cloud-split) which inherits this failure.

The return type was list[tuple[object, float]] which made pyright reject
attribute access on the unpacked rule (r.state, r.confidence, etc).
Switch to the actual Lesson type (or Any if Lesson import is awkward).

Unblocks PR #76 (cloud-split) which inherits this CI failure.

Signed-off-by: Oliver Le <oliver@gradata.ai>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d283250d-8bf1-4cee-873d-a335f9669be6

📥 Commits

Reviewing files that changed from the base of the PR and between a188b12 and 6a0c44e.

📒 Files selected for processing (1)
  • src/gradata/rules/rule_context.py
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: Test (Python 3.11)
  • GitHub Check: Test (Python 3.12)
  • GitHub Check: Test (Python 3.13)
  • GitHub Check: test (3.13)
  • GitHub Check: test (3.12)
  • GitHub Check: test (3.11)
  • GitHub Check: Python 3.12
  • GitHub Check: Python 3.11
  • GitHub Check: Python 3.11
  • GitHub Check: Python 3.12
  • GitHub Check: Test (Python 3.12)
  • GitHub Check: Test (Python 3.11)
  • GitHub Check: Test (Python 3.13)
  • GitHub Check: Cloudflare Pages
🧰 Additional context used
📓 Path-based instructions (1)
src/gradata/**/*.py

⚙️ CodeRabbit configuration file

src/gradata/**/*.py: This is the core SDK. Check for: type safety (from future import annotations required), no print()
statements (use logging), all functions accepting BrainContext where DB access occurs, no hardcoded paths. Severity
scoring must clamp to [0,1]. Confidence values must be in [0.0, 1.0].

Files:

  • src/gradata/rules/rule_context.py
🔇 Additional comments (1)
src/gradata/rules/rule_context.py (1)

67-67: Boolean return simplification is correct.

Line 67 now returns a strict boolean while preserving domain/prefix matching semantics.


📝 Walkthrough
  • Fixed pyright type annotation errors blocking main CI by annotating Lesson in rank_rules_for_draft and using TYPE_CHECKING to avoid circular imports.
  • Updated rank_rules_for_draft signature: lessons: list → lessons: list[Lesson], return type list[tuple[object, float]] → list[tuple[Lesson, float]]; internal accumulator types narrowed accordingly.
  • Ensured callers can access Lesson attributes (e.g., r.state, r.confidence) without pyright errors; no runtime logic changes.
  • Corrected boolean evaluation in _rule_matches_domain() to guarantee a bool result from the applies_to prefix check (replaced a truthy expression with explicit startswith()).
  • Local pyright on src/gradata/hooks/jit_inject.py reports 0 errors/warnings/informations after the change.
  • No breaking changes to public API, no security fixes, and no new public API methods introduced.
  • Unblocks PR #76 (cloud-split) which inherited the same CI failure.

Walkthrough

Update narrows type annotations to use the Lesson type in JIT injection and fixes a boolean-evaluation issue in rule domain matching to ensure an explicit boolean is returned.

Changes

Cohort / File(s) Summary
Type annotation changes
src/gradata/hooks/jit_inject.py
Added TYPE_CHECKING import and type-only Lesson import; changed rank_rules_for_draft signature to lessons: list[Lesson] and return type to list[tuple[Lesson, float]]; adjusted internal accumulator typing.
Boolean-return fix
src/gradata/rules/rule_context.py
Changed _rule_matches_domain() expression to use applies == domain_norm or applies.startswith(f"{domain_norm}:"), ensuring the function returns a boolean value for the startswith branch.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

refactor

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding type annotations to rank_rules_for_draft to resolve pyright type errors.
Description check ✅ Passed The description is directly related to the changeset, explaining the pyright errors being fixed and the type annotation changes made.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pyright-jit-inject

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

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Gradata has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 15, 2026

Deploying gradata-dashboard with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6a0c44e
Status: ✅  Deploy successful!
Preview URL: https://b14232e4.gradata-dashboard.pages.dev
Branch Preview URL: https://fix-pyright-jit-inject.gradata-dashboard.pages.dev

View logs

- Move Lesson import into TYPE_CHECKING block (ruff TC001)
- Cast scope-applies expression to bool to satisfy pyright reportReturnType
- rule_context fix is pre-existing on main, blocking the same CI as PR #76

Signed-off-by: Oliver Le <oliver@gradata.ai>
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Gradata has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

Signed-off-by: Oliver Le <oliver@gradata.ai>
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Gradata has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai coderabbitai Bot added the bug Something isn't working label Apr 15, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@src/gradata/rules/rule_context.py`:
- Line 67: The return expression currently uses redundant checks and a bool()
wrapper; simplify the logic in rule_context.py by replacing "return applies ==
domain_norm or bool(applies and applies.startswith(f\"{domain_norm}:\"))" with
"return applies == domain_norm or applies.startswith(f\"{domain_norm}:\")" since
applies is already a str and startswith() yields a bool; update the return in
the function where the variables applies and domain_norm are used accordingly.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 03e7ffc8-56b0-41c6-bdb8-c10ecdc5a788

📥 Commits

Reviewing files that changed from the base of the PR and between f1fc674 and a188b12.

📒 Files selected for processing (2)
  • src/gradata/hooks/jit_inject.py
  • src/gradata/rules/rule_context.py
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Test (Python 3.11)
  • GitHub Check: Test (Python 3.12)
  • GitHub Check: test (3.13)
  • GitHub Check: test (3.11)
  • GitHub Check: test (3.12)
  • GitHub Check: Python 3.12
  • GitHub Check: Python 3.11
  • GitHub Check: Test (Python 3.11)
  • GitHub Check: Test (Python 3.12)
  • GitHub Check: Cloudflare Pages
  • GitHub Check: Python 3.12
  • GitHub Check: Python 3.11
🧰 Additional context used
📓 Path-based instructions (2)
src/gradata/**/*.py

⚙️ CodeRabbit configuration file

src/gradata/**/*.py: This is the core SDK. Check for: type safety (from future import annotations required), no print()
statements (use logging), all functions accepting BrainContext where DB access occurs, no hardcoded paths. Severity
scoring must clamp to [0,1]. Confidence values must be in [0.0, 1.0].

Files:

  • src/gradata/rules/rule_context.py
  • src/gradata/hooks/jit_inject.py
src/gradata/hooks/**

⚙️ CodeRabbit configuration file

src/gradata/hooks/**: JavaScript hooks for Claude Code integration. Check for: no shell injection (no execSync with user
input), temp files must use per-user subdirectory, HTTP calls must have timeouts, errors must be silent (never block
the tool chain).

Files:

  • src/gradata/hooks/jit_inject.py
🔇 Additional comments (3)
src/gradata/hooks/jit_inject.py (3)

28-35: Type-only Lesson import is correctly structured.

Good use of TYPE_CHECKING with postponed annotations to keep runtime imports clean while satisfying static analysis.


103-109: rank_rules_for_draft typing now matches real usage.

This is the right narrowing: callers/tests treat ranked items as Lesson, so this signature fixes the previous type mismatch cleanly.


124-124: Accumulator annotation is consistent with the updated contract.

Nice follow-through on internal typing; this keeps inference stable and avoids regressions in strict pyright mode.

Comment thread src/gradata/rules/rule_context.py Outdated
startswith() already returns bool; the 'and applies' short-circuit is also
redundant since startswith() on empty string is False for any non-empty pattern.

Signed-off-by: Oliver Le <oliver@gradata.ai>
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Gradata has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai coderabbitai Bot added refactor and removed bug Something isn't working labels Apr 15, 2026
@Gradata Gradata merged commit 744c27b into main Apr 15, 2026
16 checks passed
@Gradata Gradata deleted the fix/pyright-jit-inject branch April 15, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant