Skip to content

Conversation

@ogenstad
Copy link
Contributor

@ogenstad ogenstad commented Sep 10, 2025

Summary by CodeRabbit

  • New Features

    • Added optional hours support to time subtraction parameters and parsing, enabling inputs with hours.
  • New Features

    • Introduced a public SubstractParams type (optional seconds, minutes, hours) for clearer parameter usage.
  • Refactor

    • Internal typing updated to use SubstractParams and removed a prior type-ignore without changing runtime behavior.
  • Documentation

    • Improved developer experience via stronger, discoverable parameter typing for better autocomplete and static analysis.

@coderabbitai
Copy link

coderabbitai bot commented Sep 10, 2025

Walkthrough

  • Added public TypedDict SubstractParams in infrahub_sdk/timestamp.py with optional keys: seconds, minutes, hours (NotRequired[float]).
  • Updated typing imports to include NotRequired and TypedDict.
  • In _parse_string, changed local params type from dict[str, float] to SubstractParams and populate keys explicitly.
  • Added an hours pattern to REGEX_MAPPING.
  • Removed a type: ignore on the subtract call and now call subtract(**params).
  • No runtime logic changes; changes are typing and parsing-pattern exposure only.

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 "Fix typing for substract params" is concise and directly describes the primary change—adjusting the typing for the subtract/substract parameters (addition of SubstractParams TypedDict and related call/site updates)—so it accurately summarizes the main change and is clear to reviewers.
✨ 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-substract-param-typing

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 Sep 10, 2025

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 751b7da
Status: ✅  Deploy successful!
Preview URL: https://dcd02a58.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pog-substract-param-typing.infrahub-sdk-python.pages.dev

View logs

@ogenstad
Copy link
Contributor Author

Old Python :(

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: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c7922f and c2737c7.

📒 Files selected for processing (1)
  • infrahub_sdk/timestamp.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.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/timestamp.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). (1)
  • GitHub Check: integration-tests-latest-infrahub
🔇 Additional comments (1)
infrahub_sdk/timestamp.py (1)

89-89: Verify no remaining type errors
mypy isn’t available in this environment—please run

mypy . --config-file pyproject.toml

locally to confirm there are no type errors.

import warnings
from datetime import datetime, timezone
from typing import Literal
from typing import Literal, NotRequired, TypedDict
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Guard NotRequired import for Python < 3.11

If the SDK supports 3.10 or earlier, this import will fail. Add a typing_extensions fallback.

-from typing import Literal, NotRequired, TypedDict
+from typing import Literal, TypedDict
+try:  # Python 3.11+
+    from typing import NotRequired  # type: ignore[attr-defined]
+except Exception:  # Python <= 3.10
+    from typing_extensions import NotRequired

Verify supported versions:


🏁 Script executed:

#!/bin/bash
# Discover declared Python support
rg -nP 'python_requires\s*=' setup.cfg pyproject.toml setup.py 2>/dev/null || true
rg -nP 'Programming Language :: Python :: (3\.\d+)' setup.cfg pyproject.toml setup.py 2>/dev/null || true

Length of output: 318


🏁 Script executed:

#!/bin/bash
rg -nP 'requires-python' -C2 -n pyproject.toml || true

Length of output: 0


Guard NotRequired import for Python < 3.11

The SDK’s classifiers include Python 3.9 and 3.10 support, but NotRequired was only added in 3.11—this import will fail under 3.10. Add a typing_extensions fallback in infrahub_sdk/timestamp.py:

-from typing import Literal, NotRequired, TypedDict
+from typing import Literal, TypedDict
+try:  # Python 3.11+
+    from typing import NotRequired  # type: ignore[attr-defined]
+except ImportError:  # Python ≤ 3.10
+    from typing_extensions import NotRequired
📝 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
from typing import Literal, NotRequired, TypedDict
from typing import Literal, TypedDict
try: # Python 3.11+
from typing import NotRequired # type: ignore[attr-defined]
except ImportError: # Python ≤ 3.10
from typing_extensions import NotRequired
🤖 Prompt for AI Agents
In infrahub_sdk/timestamp.py around line 6, the direct import of NotRequired
from typing will break on Python <3.11; change the imports to try to import
NotRequired from typing and fall back to typing_extensions when it’s unavailable
(use a try/except ImportError or AttributeError to import NotRequired from
typing_extensions), keeping other typing imports intact and preserving
type-checker compatibility.

Comment on lines 21 to 24
class SubstractParams(TypedDict):
seconds: NotRequired[int]
minutes: NotRequired[int]
hours: NotRequired[int]
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Use float types and fix public name (SubtractParams); keep alias for backward compatibility

  • Values assigned at Line 86 are floats.
  • Library subtract(...) accepts floats for hours/minutes/seconds.
  • Public type name is misspelled.

Apply:

-class SubstractParams(TypedDict):
-    seconds: NotRequired[int]
-    minutes: NotRequired[int]
-    hours: NotRequired[int]
+class SubtractParams(TypedDict):
+    seconds: NotRequired[float]
+    minutes: NotRequired[float]
+    hours: NotRequired[float]
+
+# Backward-compat alias (to avoid breaking imports)
+SubstractParams = SubtractParams

To find external uses of the misspelled name before/after the change:


🏁 Script executed:

#!/bin/bash
rg -n '\bSubstractParams\b' || true
rg -n '\bSubtractParams\b' || true

Length of output: 128


Rename SubstractParams to SubtractParams, switch to float, and add backward-compat alias

Apply:

-class SubstractParams(TypedDict):
-    seconds: NotRequired[int]
-    minutes: NotRequired[int]
-    hours: NotRequired[int]
+class SubtractParams(TypedDict):
+    seconds: NotRequired[float]
+    minutes: NotRequired[float]
+    hours: NotRequired[float]
+
+# Backward-compat alias
+SubstractParams = SubtractParams
🤖 Prompt for AI Agents
In infrahub_sdk/timestamp.py around lines 21 to 24, rename the TypedDict class
SubstractParams to the correctly spelled SubtractParams, change the types of
seconds, minutes, and hours from int to float (NotRequired[float]) so callers
can pass fractional values, and add a backward-compatible alias SubstractParams
= SubtractParams (preserve existing import behavior) so old code continues to
work while new code uses the corrected name and float types.

@codecov
Copy link

codecov bot commented Sep 10, 2025

Codecov Report

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

Files with missing lines Patch % Lines
infrahub_sdk/timestamp.py 92.85% 0 Missing and 1 partial ⚠️
@@             Coverage Diff             @@
##           develop     #540      +/-   ##
===========================================
- Coverage    75.94%   75.86%   -0.09%     
===========================================
  Files          100      100              
  Lines         9329     8878     -451     
  Branches      1832     1740      -92     
===========================================
- Hits          7085     6735     -350     
+ Misses        1754     1668      -86     
+ Partials       490      475      -15     
Flag Coverage Δ
integration-tests 34.80% <0.00%> (-1.44%) ⬇️
python-3.10 48.32% <50.00%> (-1.32%) ⬇️
python-3.11 48.29% <50.00%> (-1.35%) ⬇️
python-3.12 48.29% <50.00%> (-1.30%) ⬇️
python-3.13 48.29% <50.00%> (-1.33%) ⬇️
python-3.9 46.97% <50.00%> (-1.08%) ⬇️
python-filler-3.12 25.08% <42.85%> (+0.84%) ⬆️

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

Files with missing lines Coverage Δ
infrahub_sdk/timestamp.py 83.03% <92.85%> (+0.68%) ⬆️

... and 8 files 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 force-pushed the pog-substract-param-typing branch from c2737c7 to 751b7da Compare September 11, 2025 08:38
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

Caution

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

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

22-26: Harden unit regex: prevent “ms”→minutes misparse; accept decimals/whitespace; case-insensitive.
Current patterns can read “5ms” as 5 minutes and reject decimals like “1.5h”.

-REGEX_MAPPING = {
-    "seconds": r"(\d+)(s|sec|second|seconds)",
-    "minutes": r"(\d+)(m|min|minute|minutes)",
-    "hours": r"(\d+)(h|hour|hours)",
-}
+REGEX_MAPPING = {
+    "seconds": r"(\d+(?:\.\d+)?)\s*(?:s|sec|second|seconds)\b",
+    "minutes": r"(\d+(?:\.\d+)?)\s*(?:min|mins|minute|minutes|m)\b",
+    "hours":   r"(\d+(?:\.\d+)?)\s*(?:h|hr|hour|hours)\b",
+}

And make searches case-insensitive (see Line 86):

-            match = re.search(regex, value)
+            match = re.search(regex, value, re.IGNORECASE)
🧹 Nitpick comments (1)
infrahub_sdk/timestamp.py (1)

84-84: Update local annotation to the corrected type name.

-        params: SubstractParams = {}
+        params: SubtractParams = {}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c2737c7 and 751b7da.

📒 Files selected for processing (1)
  • infrahub_sdk/timestamp.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.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/timestamp.py
🧬 Code graph analysis (1)
infrahub_sdk/timestamp.py (1)
infrahub_sdk/exceptions.py (1)
  • TimestampFormatError (170-173)
⏰ 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). (7)
  • GitHub Check: integration-tests-latest-infrahub
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: unit-tests (3.9)
  • GitHub Check: unit-tests (3.10)
  • GitHub Check: unit-tests (3.11)
  • GitHub Check: unit-tests (3.12)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (4)
infrahub_sdk/timestamp.py (4)

6-9: LGTM: typing_extensions.NotRequired import fixes Py≤3.10.
Good compatibility tweak; no runtime impact.


88-93: TypedDict population is fine and type-checker-friendly.
Explicit keys avoid dynamic-key TypedDict issues.


96-96: **LGTM: remove type ignore; call subtract(params) directly.
Cleaner and type-safe with the new TypedDict.


16-21: Rename misspelled public type to SubtractParams and add backward-compatible alias

rg found only local occurrences in infrahub_sdk/timestamp.py (class at L16, usage at L84). Rename the class, add an alias to preserve external imports, and update local references to the correct name.

-class SubstractParams(TypedDict):
+class SubtractParams(TypedDict):
     seconds: NotRequired[float]
     minutes: NotRequired[float]
     hours: NotRequired[float]
 
+# Backward-compat alias (preserve imports)
+SubstractParams = SubtractParams

@ogenstad ogenstad requested a review from a team September 11, 2025 09:30
@ogenstad ogenstad merged commit 90bad6d into develop Sep 11, 2025
20 checks passed
@ogenstad ogenstad deleted the pog-substract-param-typing branch September 11, 2025 10:45
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