[AAASM-5568] 🚨 (python-sdk): Clear 44 SonarCloud code smells - #308
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…exity Cognitive complexity of _wrap_on_invoke_tool drops 18->8 (Sonar S3776) by moving the governance pre-check into _run_async_tool_pre_execution_check. No behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Chisanan232
left a comment
There was a problem hiding this comment.
✅ Review — LGTM (Claude Code)
Reviewed against the full standard: requirements/logic, implementation, bugs/regressions, goal match, CI.
Goal match — Clears the 44 code smells surfaced by the corrected main re-scan (AAASM-5568), targeting <5. Scope is exactly the flagged rules; no unrelated changes.
Implementation — Correct and idiomatic:
- S8997 ×31: manual attr/env/context set-and-restore replaced with pytest
monkeypatch(auto-restore; manual teardown removed). This is the sanctioned pattern. - S9083 ×8: empty parens dropped only from genuinely no-arg decorators.
- S9073 ×3: top-level
assert A and Bsplit; messages preserved. - S5778: arg construction hoisted out of
pytest.raisesso only the throwing call remains inside. - S3776:
patch.pytool pre-execution check extracted — production refactor, no behavior change.
No regression — Verified locally (Node/uv, worktree): ruff check . clean; full uv run pytest = 1204 passed, 16 skipped (skips env-gated: native _core unbuilt, optional adapter libs absent), 0 failures. mypy shows only the 4 pre-existing _core/grpc-stub import errors identical on main — not introduced here.
CI — 19 pass / 7 skip / 0 fail. SonarCloud PR analysis: open issues = 0 → all 44 resolved, no new issue introduced.
No missing requirements or logic gaps. 🟢



Description
Clears the 44 SonarCloud code smells on python-sdk
maindown toward the quality target (<5). These surfaced only after the SonarCloud main branch was corrected from the stalemastersnapshot tomainand re-scanned (AAASM-5562) — the old snapshot falsely reported 3. Nearly all are intest/; one is production code.Fixes by rule:
monkeypatchfixture for temporary attribute/env/context modifications instead of manual set-and-restore (auto-restores; manual teardown removed). Across test_runner_spawn_patch, test_crewai_spawn_context, test_edge_emission, test_pydantic_ai_spawn_patch, test_registry, bench latency contracts, etc.@pytest.fixture()→@pytest.fixture) in cli/conftest and native_core.assert A and Binto separate assertions.pytest.raisesblock so only the single throwing call remains inside.agent_assembly/adapters/openai_agents/patch.pyby extracting the tool pre-execution check (only production-code change; pure refactor).Type of Change
Breaking Changes
Related Issues
Testing
Verification (worktree,
uv):ruff check .clean; fulluv run pytest= 1204 passed, 16 skipped (skips are env-gated: native_corenot built, optional adapter libs absent), 0 failures.mypyshows only the 4 pre-existing_core/grpc-stub import errors that are identical onmain(not introduced here). SonarCloud's cognitive-complexity metric is scanner-only, so the S3776 reduction is confirmed by this PR's SonarCloud analysis.Checklist
🤖 Generated with Claude Code