Skip to content

Conversation

@ogenstad
Copy link
Contributor

@ogenstad ogenstad commented Sep 10, 2025

Summary by CodeRabbit

  • Refactor

    • Streamlined multiple SDK methods to return values directly, removing unnecessary temporary variables. Areas include branch listing, version retrieval, artifact fetching, diff creation, playback responses, active branch lookup, and timestamp parsing. No functional changes; improves readability and consistency.
  • Chores

    • Updated linting configuration to enforce detection of unnecessary assignments in production code while ignoring them in tests, aligning codebase with stricter quality standards without affecting behavior.

@coderabbitai
Copy link

coderabbitai bot commented Sep 10, 2025

Walkthrough

This change refactors multiple modules to inline return expressions by removing intermediate local variables before returning. Updates span branch management, client version retrieval (async and sync), diff construction, node artifact fetch (async and sync), playback response creation, repository active branch retrieval, and timestamp parsing. Behavior and control flow remain the same, with no public API or signature changes. The Ruff configuration in pyproject.toml now enforces RET504 globally, with RET504 ignored only for tests via per-file ignores.

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely summarizes the primary change in the pull request, which is the removal of redundant local variable assignments just before return statements across multiple modules. It avoids unnecessary detail while accurately reflecting the developer’s intent and the core refactoring performed.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pog-returns

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@cloudflare-workers-and-pages
Copy link

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8c266e7
Status: ✅  Deploy successful!
Preview URL: https://698c030d.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pog-returns.infrahub-sdk-python.pages.dev

View logs

@codecov
Copy link

codecov bot commented Sep 10, 2025

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/playback.py 0.00% 1 Missing ⚠️
@@            Coverage Diff             @@
##           stable     #542      +/-   ##
==========================================
- Coverage   75.74%   75.57%   -0.18%     
==========================================
  Files         100      100              
  Lines        9421     8891     -530     
  Branches     1949     1750     -199     
==========================================
- Hits         7136     6719     -417     
+ Misses       1755     1689      -66     
+ Partials      530      483      -47     
Flag Coverage Δ
integration-tests 34.69% <20.00%> (+0.15%) ⬆️
python-3.10 48.11% <90.00%> (-0.49%) ⬇️
python-3.11 48.11% <90.00%> (-0.49%) ⬇️
python-3.12 48.09% <90.00%> (-0.49%) ⬇️
python-3.13 48.09% <90.00%> (-0.49%) ⬇️
python-3.9 46.73% <90.00%> (-0.54%) ⬇️
python-filler-3.12 24.99% <10.00%> (-0.16%) ⬇️

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

Files with missing lines Coverage Δ
infrahub_sdk/branch.py 53.90% <100.00%> (-0.65%) ⬇️
infrahub_sdk/client.py 67.34% <100.00%> (-3.96%) ⬇️
infrahub_sdk/diff.py 95.23% <100.00%> (-0.12%) ⬇️
infrahub_sdk/node/node.py 76.13% <100.00%> (-0.06%) ⬇️
infrahub_sdk/repository.py 100.00% <100.00%> (ø)
infrahub_sdk/timestamp.py 83.16% <100.00%> (+0.81%) ⬆️
infrahub_sdk/playback.py 60.00% <0.00%> (+2.30%) ⬆️

... and 1 file with indirect coverage changes

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

Copy link

@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

Caution

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

⚠️ Outside diff range comments (1)
infrahub_sdk/node/node.py (1)

578-583: Wrong feature message for fetch (async).

artifact_fetch() validates support using the “generate” message constant instead of the “fetch” one. This yields a misleading error.

Apply:

-        self._validate_artifact_support(ARTIFACT_GENERATE_FEATURE_NOT_SUPPORTED_MESSAGE)
+        self._validate_artifact_support(ARTIFACT_FETCH_FEATURE_NOT_SUPPORTED_MESSAGE)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 565674f and 8c266e7.

📒 Files selected for processing (8)
  • infrahub_sdk/branch.py (2 hunks)
  • infrahub_sdk/client.py (2 hunks)
  • infrahub_sdk/diff.py (1 hunks)
  • infrahub_sdk/node/node.py (2 hunks)
  • infrahub_sdk/playback.py (1 hunks)
  • infrahub_sdk/repository.py (1 hunks)
  • infrahub_sdk/timestamp.py (1 hunks)
  • pyproject.toml (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

When implementing Infrahub checks, subclass InfrahubCheck and override validate(data); do not implement or rely on a check() method

Files:

  • infrahub_sdk/node/node.py
  • infrahub_sdk/branch.py
  • infrahub_sdk/playback.py
  • infrahub_sdk/timestamp.py
  • infrahub_sdk/diff.py
  • infrahub_sdk/repository.py
  • infrahub_sdk/client.py
infrahub_sdk/client.py

📄 CodeRabbit inference engine (CLAUDE.md)

infrahub_sdk/client.py: Use HTTPX for transport with proxy support (single proxy or HTTP/HTTPS mounts)
Support authentication via API tokens or JWT with automatic refresh

Files:

  • infrahub_sdk/client.py
🧠 Learnings (1)
📚 Learning: 2025-08-24T13:35:12.998Z
Learnt from: CR
PR: opsmill/infrahub-sdk-python#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T13:35:12.998Z
Learning: Maintain a dual client pattern: InfrahubClient (async) and InfrahubClientSync (sync) must provide identical interfaces

Applied to files:

  • infrahub_sdk/client.py
⏰ 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). (2)
  • GitHub Check: integration-tests-latest-infrahub
  • GitHub Check: unit-tests (3.13)
🔇 Additional comments (10)
infrahub_sdk/playback.py (1)

59-59: Inline return is correct.

Semantics unchanged; constructing Response directly here is fine.

pyproject.toml (1)

275-276: Scope RET504 to tests only — good move.

This enforces the no-temp-before-return rule in prod code while keeping tests flexible.

infrahub_sdk/timestamp.py (1)

46-46: Minor simplification looks good.

No behavior change; retains the same exception semantics.

infrahub_sdk/diff.py (1)

120-127: Directly returning NodeDiff is fine.

No functional change; elements list is preserved.

infrahub_sdk/client.py (2)

307-311: Async get_version inlining — looks good and consistent.

Matches the sync version and keeps the dual-client interface aligned.


1601-1605: Sync get_version inlining — looks good.

Symmetric with async variant; interface parity maintained.

infrahub_sdk/branch.py (2)

191-191: Dict comprehension is fine.

Same behavior with clearer intent.


231-231: Sync variant matches async — good.

Keeps both managers consistent.

infrahub_sdk/node/node.py (2)

582-582: Inline await return — good.

No semantic change; reads cleaner.


1210-1210: Sync inline return — good.

Matches the async path; consistent and concise.

def active_branch(self) -> str | None:
active_branch = porcelain.active_branch(self.root_directory).decode("utf-8")
return active_branch
return porcelain.active_branch(self.root_directory).decode("utf-8")
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Handle detached HEAD to avoid AttributeError.

porcelain.active_branch() can return None (e.g., detached HEAD). Decoding without a guard may crash.

Apply:

-        return porcelain.active_branch(self.root_directory).decode("utf-8")
+        branch = porcelain.active_branch(self.root_directory)
+        return branch.decode("utf-8") if branch else None
📝 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
return porcelain.active_branch(self.root_directory).decode("utf-8")
branch = porcelain.active_branch(self.root_directory)
return branch.decode("utf-8") if branch else None
🤖 Prompt for AI Agents
In infrahub_sdk/repository.py around line 32,
porcelain.active_branch(self.root_directory) can return None (detached HEAD) so
calling .decode("utf-8") will raise AttributeError; update the code to first
assign the result to a variable, check if it's None, and if so return a sensible
fallback (e.g., None or the current commit id), otherwise decode and return the
branch name.

@ogenstad ogenstad requested a review from a team September 10, 2025 19:34
@ogenstad ogenstad merged commit a406bb0 into stable Sep 11, 2025
20 checks passed
@ogenstad ogenstad deleted the pog-returns branch September 11, 2025 10:44
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.

2 participants