Skip to content

Conversation

@ogenstad
Copy link
Contributor

@ogenstad ogenstad commented Nov 18, 2025

Summary by CodeRabbit

  • Tests

    • Added explicit return type annotations to many test functions and fixtures across suites; some fixtures now include explicit teardown/reset behavior.
  • Chores

    • Linting configuration tightened to enforce return type annotations for public test functions.

@coderabbitai
Copy link

coderabbitai bot commented Nov 18, 2025

Walkthrough

pyproject.toml removed a per-file ignore for ANN201, causing the linter to enforce return type annotations. The changes add explicit return type hints and necessary typing imports (e.g., Generator, AsyncGenerator, Callable, Any) across multiple test fixtures and test functions in the tests/ tree. No runtime logic, control flow, or external behavior was modified; edits are limited to type annotations and minor formatting.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.37% 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 accurately describes the main objective of the changeset: adding return type annotations throughout the test suite and related configuration changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pog-return-annotations-to-infrahub-develop-20251118

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22a9811 and 0aa08c2.

📒 Files selected for processing (12)
  • pyproject.toml (0 hunks)
  • tests/conftest.py (3 hunks)
  • tests/fixtures/integration/test_infrahubctl/tags_transform/tags_transform.py (1 hunks)
  • tests/integration/test_infrahub_client.py (2 hunks)
  • tests/unit/ctl/conftest.py (2 hunks)
  • tests/unit/ctl/test_render_app.py (1 hunks)
  • tests/unit/ctl/test_transform_app.py (2 hunks)
  • tests/unit/sdk/conftest.py (23 hunks)
  • tests/unit/sdk/graphql/conftest.py (6 hunks)
  • tests/unit/sdk/graphql/test_plugin.py (2 hunks)
  • tests/unit/sdk/test_repository.py (2 hunks)
  • tests/unit/sdk/test_schema.py (1 hunks)
💤 Files with no reviewable changes (1)
  • pyproject.toml
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/unit/sdk/graphql/test_plugin.py
  • tests/unit/ctl/test_transform_app.py
  • tests/unit/sdk/test_schema.py
🧰 Additional context used
🧬 Code graph analysis (2)
tests/integration/test_infrahub_client.py (2)
tests/unit/sdk/conftest.py (1)
  • client (32-33)
infrahub_sdk/client.py (1)
  • InfrahubClient (318-1688)
tests/fixtures/integration/test_infrahubctl/tags_transform/tags_transform.py (1)
infrahub_sdk/ctl/cli_commands.py (1)
  • transform (302-360)
⏰ 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). (6)
  • GitHub Check: integration-tests-latest-infrahub
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: unit-tests (3.12)
  • GitHub Check: unit-tests (3.10)
  • GitHub Check: unit-tests (3.11)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (14)
tests/fixtures/integration/test_infrahubctl/tags_transform/tags_transform.py (1)

8-13: LGTM!

The return type annotation -> dict[str, str] accurately reflects the method's return value.

tests/conftest.py (2)

3-3: LGTM!

The Generator[asyncio.AbstractEventLoop] annotation correctly reflects the fixture's yield behavior.

Also applies to: 15-20


30-42: LGTM!

The Generator annotation is appropriate for this fixture. While you could use the fully explicit Generator[None, None, None], the short form is acceptable and commonly used for fixtures that only manage setup/teardown without yielding meaningful values.

tests/unit/ctl/conftest.py (1)

1-2: LGTM!

The dict[str, Any] return type accurately describes the error payload structure, and the direct return is cleaner than the previous pattern.

Also applies to: 68-77

tests/integration/test_infrahub_client.py (1)

3-3: LGTM!

The AsyncGenerator annotation is correct for this async fixture. The teardown logic properly restores the original pagination_size value, which is good test hygiene.

Also applies to: 37-41

tests/unit/ctl/test_render_app.py (1)

82-84: LGTM!

The -> None annotation is correct for this test function, and the multi-line formatting improves readability.

tests/unit/sdk/test_repository.py (1)

2-2: LGTM!

The Generator[str] annotation correctly reflects that this fixture yields a string (the temporary directory path).

Also applies to: 14-17

tests/unit/sdk/graphql/conftest.py (1)

2-2: LGTM!

All fixtures now have accurate dict[str, Any] return type annotations that match their actual return values. The refactoring to direct returns (removing intermediate variables) is also cleaner.

Also applies to: 18-102

tests/unit/sdk/conftest.py (6)

5-5: LGTM!

The Callable[[str], str] return type annotation accurately describes that this fixture returns a function taking a string and returning a string.

Also applies to: 9-9, 96-102


106-118: LGTM!

The complex Callable[[Mapping[str, Parameter]], list[tuple[str, str]]] return type accurately reflects the inner function's signature that processes parameter mappings into tuples.


122-129: LGTM!

Both replace_sync_return_annotation and replace_sync_parameter_annotations fixtures have correct Callable return type annotations that match their implementations.

Also applies to: 133-145


306-352: LGTM!

All location data fixtures now have accurate dict[str, Any] return type annotations and use direct returns for cleaner code.

Also applies to: 356-418, 422-457, 461-520, 524-559, 563-638


642-660: LGTM!

The rfile and tag data fixtures have correct dict[str, Any] return type annotations that match their return structures.

Also applies to: 678-755, 759-813, 817-842


979-1043: LGTM!

All remaining data fixtures (ipam_ipprefix_data, address_data, device_data, artifact_definition_data) have accurate dict[str, Any] return type annotations.

Also applies to: 1175-1210, 1264-1416, 1437-1466


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

cloudflare-workers-and-pages bot commented Nov 18, 2025

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0aa08c2
Status: ✅  Deploy successful!
Preview URL: https://48627493.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pog-return-annotations-to-in.infrahub-sdk-python.pages.dev

View logs

@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@                 Coverage Diff                  @@
##           infrahub-develop     #644      +/-   ##
====================================================
+ Coverage             75.56%   75.60%   +0.04%     
====================================================
  Files                   113      113              
  Lines                  9514     9522       +8     
  Branches               1448     1452       +4     
====================================================
+ Hits                   7189     7199      +10     
+ Misses                 1838     1832       -6     
- Partials                487      491       +4     
Flag Coverage Δ
integration-tests 34.96% <ø> (-0.01%) ⬇️
python-3.10 48.99% <ø> (+0.12%) ⬆️
python-3.11 49.01% <ø> (+0.14%) ⬆️
python-3.12 48.97% <ø> (+0.12%) ⬆️
python-3.13 48.97% <ø> (+0.10%) ⬆️
python-3.9 ?
python-filler-3.12 24.27% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 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.

@ogenstad ogenstad marked this pull request as ready for review November 19, 2025 06:57
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: 0

🧹 Nitpick comments (5)
tests/integration/test_infrahub_client.py (1)

37-37: Consider being more specific with the AsyncGenerator type.

The fixture yields without a value (line 40), so AsyncGenerator[None, None] would be more precise than bare AsyncGenerator.

Apply this diff for more precise typing:

-    async def set_pagination_size3(self, client: InfrahubClient) -> AsyncGenerator:
+    async def set_pagination_size3(self, client: InfrahubClient) -> AsyncGenerator[None, None]:
tests/conftest.py (1)

3-3: Generator-based fixture annotations look good; optional tightening of types

Using collections.abc.Generator for event_loop and clean_env_vars matches the recommended generator-style override pattern for event_loop and should not change behavior.(newreleases.io)

If you want stricter typing, you could parameterize the generators explicitly, e.g.:

def event_loop() -> Generator[asyncio.AbstractEventLoop, None, None]:
    ...

def clean_env_vars() -> Generator[None, None, None]:
    ...

to avoid implicit Any for the send/return types.(docs.python.org)

Also applies to: 15-15, 30-30

tests/unit/sdk/graphql/conftest.py (1)

2-2: GraphQL query/input fixtures: annotations and inlined returns are consistent

Importing Any and annotating these fixtures as dict[str, Any] is consistent with their heterogeneous JSON-like payloads, and returning the dict literals directly removes unnecessary local variables without changing behavior. If you find yourself repeating this pattern elsewhere, you could optionally introduce a small alias like JSONDict = dict[str, Any] for reuse, but what you have here is already clear.(typing.python.org)

Also applies to: 18-26, 29-37, 40-49, 53-61, 65-76, 80-90, 94-103

tests/unit/sdk/conftest.py (2)

96-102: Callable-based helper fixtures are correctly typed; consider tiny optimization

The new return types

  • replace_async_return_annotation(...) -> Callable[[str], str]
  • replace_async_parameter_annotations(...) -> Callable[[Mapping[str, Parameter]], list[tuple[str, str]]]
  • replace_sync_return_annotation(...) -> Callable[[str], str]
  • replace_sync_parameter_annotations(...) -> Callable[[Mapping[str, Parameter]], list[tuple[str, str]]]

all match the behavior of the inner functions and make the intent of these fixtures clear.(typing.python.org)

If you ever care about micro-optimizations, you could precompute the reverse replacements dict for replace_sync_return_annotation once in the outer fixture instead of rebuilding it on every call; functionally it’s fine as-is and probably not performance‑critical in tests.

Also applies to: 106-118, 122-129, 133-145


305-353: Async data fixtures now explicitly return dict[str, Any]; behavior unchanged

Across the various location_*_data*, rfile_userdata*, tag_*_data*, ipam_ipprefix_data, address_data, device_data, and artifact_definition_data fixtures, the changes are limited to:

  • adding -> dict[str, Any] return annotations, and
  • returning the dict literals directly instead of via an intermediate variable.

Given these are JSON/GraphQL-style payloads with mixed value types, dict[str, Any] is a reasonable and consistent choice here, and the refactor should be behavior‑preserving.(typing.python.org)

If you want to DRY things up later, a shared alias (e.g. JSONDict = dict[str, Any]) or a small helper factory could reduce repetition, but that’s purely optional.

Also applies to: 355-419, 422-457, 461-520, 524-559, 563-638, 642-661, 678-701, 705-728, 732-755, 759-784, 788-813, 817-842, 979-1043, 1175-1210, 1264-1416, 1437-1467

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 21d565e and 22a9811.

📒 Files selected for processing (12)
  • pyproject.toml (0 hunks)
  • tests/conftest.py (3 hunks)
  • tests/fixtures/integration/test_infrahubctl/tags_transform/tags_transform.py (1 hunks)
  • tests/integration/test_infrahub_client.py (2 hunks)
  • tests/unit/ctl/conftest.py (2 hunks)
  • tests/unit/ctl/test_render_app.py (1 hunks)
  • tests/unit/ctl/test_transform_app.py (2 hunks)
  • tests/unit/sdk/conftest.py (23 hunks)
  • tests/unit/sdk/graphql/conftest.py (6 hunks)
  • tests/unit/sdk/graphql/test_plugin.py (2 hunks)
  • tests/unit/sdk/test_repository.py (2 hunks)
  • tests/unit/sdk/test_schema.py (1 hunks)
💤 Files with no reviewable changes (1)
  • pyproject.toml
🧰 Additional context used
🧬 Code graph analysis (2)
tests/integration/test_infrahub_client.py (2)
tests/unit/sdk/conftest.py (1)
  • client (32-33)
infrahub_sdk/client.py (1)
  • InfrahubClient (318-1688)
tests/fixtures/integration/test_infrahubctl/tags_transform/tags_transform.py (1)
infrahub_sdk/ctl/cli_commands.py (1)
  • transform (302-360)
⏰ 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). (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (13)
tests/unit/sdk/test_repository.py (2)

2-2: LGTM!

The import addition is correct and necessary for the return type annotation on line 14.


14-14: LGTM!

The return type annotation Generator[str] correctly describes this fixture, which yields a string path to a temporary directory.

tests/unit/sdk/test_schema.py (1)

458-458: LGTM!

The return type annotation -> None is correct for this test function.

tests/unit/ctl/test_transform_app.py (2)

8-8: LGTM!

The import addition is correct and necessary for the return type annotation on line 31.


31-31: LGTM!

The return type annotation Generator[str] correctly describes this fixture, which yields a string path to a temporary directory.

tests/fixtures/integration/test_infrahubctl/tags_transform/tags_transform.py (1)

8-8: LGTM!

The return type annotation -> dict[str, str] accurately describes the return value, which is a dictionary with string keys and string values.

tests/integration/test_infrahub_client.py (1)

3-3: LGTM!

The import addition is correct and necessary for the return type annotation on line 37.

tests/unit/ctl/test_render_app.py (1)

87-89: LGTM!

The multi-line formatting improves readability, and the return type annotation -> None is correct for this test function.

tests/unit/ctl/conftest.py (2)

1-2: LGTM!

The import addition is correct and necessary for the return type annotation on line 68.


68-77: LGTM!

The return type annotation -> dict[str, Any] accurately describes the fixture's return value, and the direct return is cleaner than using an intermediate variable.

tests/unit/sdk/graphql/test_plugin.py (2)

38-38: LGTM!

The return type annotation -> None is correct for this test function.


51-53: LGTM!

The multi-line formatting improves readability, and the return type annotation -> None is correct for this test function.

tests/unit/sdk/conftest.py (1)

5-5: Updated type imports align with usage and modern typing style

Pulling AsyncGenerator, Callable, and Mapping from collections.abc and Any from typing matches current recommendations (PEP 585 and related typing docs) and fits how they’re used throughout this module.(peps.python.org)

Also applies to: 9-9

@ogenstad ogenstad requested a review from a team November 19, 2025 07:43
@ogenstad ogenstad force-pushed the pog-return-annotations-to-infrahub-develop-20251118 branch from 22a9811 to 0aa08c2 Compare November 19, 2025 09:18
@ogenstad ogenstad merged commit f5ed365 into infrahub-develop Nov 19, 2025
19 checks passed
@ogenstad ogenstad deleted the pog-return-annotations-to-infrahub-develop-20251118 branch November 19, 2025 09:34
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.

3 participants