Skip to content

Refactor code for consistency and add Pylint backlog - #36

Merged
ainetx merged 3 commits into
mainfrom
pylint-3
Jun 14, 2026
Merged

Refactor code for consistency and add Pylint backlog#36
ainetx merged 3 commits into
mainfrom
pylint-3

Conversation

@ainetx

@ainetx ainetx commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

Improve code readability and consistency across multiple files. Include a prioritized backlog of Pylint rules for future reference.

Summary by CodeRabbit

Release Notes

  • Chores
    • Enhanced static analysis configuration with expanded code quality checks.
    • Internal code structure improvements through refactoring of conditional logic and control flow patterns for improved maintainability.

ainetx added 3 commits June 13, 2026 18:22
…cy across multiple files

Signed-off-by: ainetx <viator@via-net.org>
…erence

Signed-off-by: ainetx <viator@via-net.org>
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR systematically modernizes the studio codebase by enabling additional Pylint rules and refactoring Python idioms throughout 40+ files. Changes replace explicit == 0 / != 0 comparisons with truthiness checks, restructure control flow from if/elif/else chains to multiple if statements, simplify string/container emptiness validation, and clean up formatting and documentation.

Changes

Code Modernization Across Studio & Proxy

Layer / File(s) Summary
Pylint Configuration Expansion
pyproject.toml
Enables additional Pylint C* and R* rule codes and documents the planned rule rollout backlog.
Subprocess Return Code Modernization
skills/studio/scripts/studio/commands/migrate_from_cypilot.py, skills/studio/scripts/studio/commands/map/cli.py, skills/studio/scripts/studio/ralphex_discover.py, skills/studio/scripts/studio/ralphex_export.py, skills/studio/scripts/studio/utils/git_kit_source.py, skills/studio/scripts/studio/utils/git_utils.py, src/studio_proxy/update_check.py
Replaces explicit proc.returncode != 0 and == 0 comparisons with idiomatic truthiness checks (if proc.returncode:, not proc.returncode) across git operations, subprocess spawning, and validation logic.
Numeric & Boolean Truthiness
skills/studio/scripts/studio/commands/agents.py, skills/studio/scripts/studio/commands/spec_coverage.py, skills/studio/scripts/studio/commands/update.py, skills/studio/scripts/studio/commands/validate.py, skills/studio/scripts/studio/commands/workspace_init.py, skills/studio/scripts/studio/commands/workspace_sync.py, skills/studio/scripts/studio/utils/artifacts_meta.py, skills/studio/scripts/studio/utils/coverage.py, skills/studio/scripts/studio/utils/pdsl.py, skills/studio/scripts/studio/utils/toc.py, skills/studio/scripts/studio/utils/toml_utils.py
Converts explicit zero comparisons (== 0, != 0) to falsy/truthy checks in coverage metrics, validation counts, command execution results, and flag conditions.
String & Container Truthiness
skills/studio/scripts/studio/utils/diff_engine.py, skills/studio/scripts/studio/utils/document.py, skills/studio/scripts/studio/utils/manifest.py
Simplifies empty-string and empty-list detection using not x, not x.strip() instead of explicit == "" and len(x) == 0 comparisons in TOC stripping, text content checks, and resource validation.
Control Flow Restructuring
skills/studio/scripts/studio/cli.py, skills/studio/scripts/studio/commands/kit.py, skills/studio/scripts/studio/utils/manifest.py, skills/studio/scripts/studio/utils/toc.py, skills/studio/scripts/studio/utils/whatsnew.py, src/studio_proxy/cli.py
Refactors command dispatch and conditional branching from if/elif/else chains to multiple independent if statements and simplifies branch logic while preserving observable behavior.
Process Management Refactoring
skills/studio/scripts/studio/ralphex_export.py
Refactors subprocess lifecycle in run_delegation to use context managers (with proc:) and reorganizes timeout/termination handling, preserving retry decisions and lifecycle failure signaling.
Formatting & Documentation
skills/studio/scripts/studio/commands/doctor.py, skills/studio/scripts/studio/commands/self_check.py, skills/studio/scripts/studio/utils/context.py, skills/studio/scripts/studio/utils/files.py, skills/studio/scripts/studio/utils/language_config.py, skills/studio/scripts/studio/utils/parsing.py, skills/studio/scripts/studio/utils/constraints.py
Adjusts blank lines, whitespace, and docstring formatting across parsing utilities, configuration loaders, and helper functions without altering functional logic.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • constructorfabric/studio#33: Both PRs modify pyproject.toml's Pylint message control rules to enable additional warning codes.
  • constructorfabric/studio#31: Both PRs expand and refactor the Pylint tool.pylint."messages control".enable configuration for staged rule rollout.
  • constructorfabric/studio#21: Both PRs touch skills/studio/scripts/studio/commands/update.py to refine self-check failure detection conditions.

Poem

🐰 A rabbit hops through dusty code,

With truthiness along the road,

No more == 0 to confuse,

Just if x: for clearer clues!

Pylint rules now brightly shine,

Refactored code—so very fine! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: refactoring code for consistency across multiple files and adding a Pylint backlog section in configuration.
Docstring Coverage ✅ Passed Docstring coverage is 83.56% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 pylint-3

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

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
skills/studio/scripts/studio/utils/document.py (1)

96-107: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Restore has_priority to a strict boolean.

priority is not None and str(priority).strip() returns a string when present, so has_priority is no longer consistently bool. That changes the scan_cpt_ids hit schema across definition/reference paths.

💡 Proposed fix
             h: Dict[str, object] = {
                 "id": id_value,
                 "line": idx0 + 1,
                 "type": "definition",
                 "checked": checked,
                 "has_task": m.group("task") is not None,
-                "has_priority": priority is not None and str(priority).strip(),
+                "has_priority": bool(priority is not None and str(priority).strip()),
             }
@@
             h = {
                 "id": mref.group("id"),
                 "line": idx0 + 1,
                 "type": "reference",
                 "checked": checked,
                 "has_task": mref.group("task") is not None,
-                "has_priority": priority is not None and str(priority).strip(),
+                "has_priority": bool(priority is not None and str(priority).strip()),
             }

Also applies to: 122-132

🤖 Prompt for 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.

In `@skills/studio/scripts/studio/utils/document.py` around lines 96 - 107, The
"has_priority" field in the h dict is sometimes a string because it uses
"priority is not None and str(priority).strip()"; change it to a strict boolean
by assigning bool(str(priority).strip()) (or simply bool(priority and
str(priority).strip())) so "has_priority" is always True/False; update the same
pattern wherever the other definition/reference dict is created (the other
h-like dict that sets "id", "line", "type", "checked", "has_task",
"has_priority") to use the same boolean conversion for the "has_priority" key.
🤖 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 `@skills/studio/scripts/studio/commands/validate.py`:
- Around line 1115-1116: The current check (if k in _HANDLED_KEYS or v is None
or not v or v == []: continue) incorrectly drops other falsy but meaningful
values like False and 0; update the condition to only skip keys in
_HANDLED_KEYS, None, and genuinely empty lists/iterables. Replace the clause
with something like: check membership in _HANDLED_KEYS first, skip when v is
None, and for empty collections check specifically (e.g., isinstance(v, list)
and len(v) == 0) or use a utility that distinguishes empty sequences from falsy
scalars so that False and 0 are preserved for rendering (keep references to
_HANDLED_KEYS, k, and v when making the change).

---

Outside diff comments:
In `@skills/studio/scripts/studio/utils/document.py`:
- Around line 96-107: The "has_priority" field in the h dict is sometimes a
string because it uses "priority is not None and str(priority).strip()"; change
it to a strict boolean by assigning bool(str(priority).strip()) (or simply
bool(priority and str(priority).strip())) so "has_priority" is always
True/False; update the same pattern wherever the other definition/reference dict
is created (the other h-like dict that sets "id", "line", "type", "checked",
"has_task", "has_priority") to use the same boolean conversion for the
"has_priority" key.
🪄 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: ec6c3303-e81e-47ff-8529-2a8827f44efd

📥 Commits

Reviewing files that changed from the base of the PR and between b90695b and 8554651.

📒 Files selected for processing (35)
  • pyproject.toml
  • skills/studio/scripts/studio/cli.py
  • skills/studio/scripts/studio/commands/agents.py
  • skills/studio/scripts/studio/commands/doctor.py
  • skills/studio/scripts/studio/commands/kit.py
  • skills/studio/scripts/studio/commands/map/cli.py
  • skills/studio/scripts/studio/commands/map/cpt_edges.py
  • skills/studio/scripts/studio/commands/map/scan.py
  • skills/studio/scripts/studio/commands/migrate_from_cypilot.py
  • skills/studio/scripts/studio/commands/self_check.py
  • skills/studio/scripts/studio/commands/spec_coverage.py
  • skills/studio/scripts/studio/commands/update.py
  • skills/studio/scripts/studio/commands/validate.py
  • skills/studio/scripts/studio/commands/workspace_init.py
  • skills/studio/scripts/studio/commands/workspace_sync.py
  • skills/studio/scripts/studio/ralphex_discover.py
  • skills/studio/scripts/studio/ralphex_export.py
  • skills/studio/scripts/studio/utils/artifacts_meta.py
  • skills/studio/scripts/studio/utils/constraints.py
  • skills/studio/scripts/studio/utils/context.py
  • skills/studio/scripts/studio/utils/coverage.py
  • skills/studio/scripts/studio/utils/diff_engine.py
  • skills/studio/scripts/studio/utils/document.py
  • skills/studio/scripts/studio/utils/files.py
  • skills/studio/scripts/studio/utils/git_kit_source.py
  • skills/studio/scripts/studio/utils/git_utils.py
  • skills/studio/scripts/studio/utils/language_config.py
  • skills/studio/scripts/studio/utils/manifest.py
  • skills/studio/scripts/studio/utils/parsing.py
  • skills/studio/scripts/studio/utils/pdsl.py
  • skills/studio/scripts/studio/utils/toc.py
  • skills/studio/scripts/studio/utils/toml_utils.py
  • skills/studio/scripts/studio/utils/whatsnew.py
  • src/studio_proxy/cli.py
  • src/studio_proxy/update_check.py
💤 Files with no reviewable changes (1)
  • skills/studio/scripts/studio/commands/doctor.py

Comment on lines +1115 to 1116
if k in _HANDLED_KEYS or v is None or not v or v == []:
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Avoid dropping falsy diagnostic fields in issue rendering.

Line 1115 now skips all falsy values, which can hide meaningful fields like False and 0 and breaks the “nothing is lost” intent in this formatter.

💡 Suggested fix
-        if k in _HANDLED_KEYS or v is None or not v or v == []:
+        if k in _HANDLED_KEYS or v is None:
+            continue
+        if isinstance(v, str) and v == "":
+            continue
+        if isinstance(v, (list, tuple, set, dict)) and not v:
             continue
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if k in _HANDLED_KEYS or v is None or not v or v == []:
continue
if k in _HANDLED_KEYS or v is None:
continue
if isinstance(v, str) and v == "":
continue
if isinstance(v, (list, tuple, set, dict)) and not v:
continue
🤖 Prompt for 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.

In `@skills/studio/scripts/studio/commands/validate.py` around lines 1115 - 1116,
The current check (if k in _HANDLED_KEYS or v is None or not v or v == []:
continue) incorrectly drops other falsy but meaningful values like False and 0;
update the condition to only skip keys in _HANDLED_KEYS, None, and genuinely
empty lists/iterables. Replace the clause with something like: check membership
in _HANDLED_KEYS first, skip when v is None, and for empty collections check
specifically (e.g., isinstance(v, list) and len(v) == 0) or use a utility that
distinguishes empty sequences from falsy scalars so that False and 0 are
preserved for rendering (keep references to _HANDLED_KEYS, k, and v when making
the change).

@ainetx
ainetx merged commit 1c0a2f7 into main Jun 14, 2026
21 checks passed
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