Skip to content

fix: return Self from Timestamp add/subtract instead of Timestamp - #1241

Merged
ajtmccarty merged 1 commit into
stablefrom
ajtm-timestamp-self-return-type
Aug 13, 2026
Merged

fix: return Self from Timestamp add/subtract instead of Timestamp#1241
ajtmccarty merged 1 commit into
stablefrom
ajtm-timestamp-self-return-type

Conversation

@ajtmccarty

@ajtmccarty ajtmccarty commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Problem

Timestamp.add(), Timestamp.subtract() and Timestamp.add_delta() all build their result with self.__class__(...), so at runtime a subclass gets an instance of itself back. The annotations claimed Timestamp.

Any subclass — Infrahub's own Timestamp among them — therefore loses its type as soon as it does arithmetic, and callers have to cast or # type: ignore before touching anything the subclass adds.

Change

Annotate the three methods as returning Self, which is what they already do.

Self is imported from typing_extensions, not typing: typing.Self is 3.11+ and this package supports 3.10 (requires-python = ">=3.10"). The module already imports NotRequired from typing_extensions.

Annotations only — no runtime behaviour changes.

Verification

  • uv run invoke format lint-code — clean (ruff + mypy pass; the pre-existing ty unresolved-import diagnostics in unrelated test modules are an incomplete local venv, not this change)
  • Confirmed at runtime that a subclass gets its own type back from all three methods

Skipping a changelog fragment — annotation-only change.

🤖 Generated with Claude Code


Summary by cubic

Annotates Timestamp.add(), Timestamp.subtract(), and Timestamp.add_delta() to return Self instead of Timestamp, preserving subclass types. Runtime behavior is unchanged; these methods already return self.class.

  • Imports Self from typing_extensions to support Python 3.10.
  • Improves type checking for subclasses; remove any casts or type: ignore related to these returns.
  • Scope: changes limited to infrahub_sdk/timestamp.py.
  • No runtime or public API behavior change; no rollout steps required.

Written for commit ae7b4d3. Summary will update on new commits.

Review in cubic

add(), subtract() and add_delta() all construct self.__class__, so a
subclass gets an instance of itself back at runtime. The annotations said
Timestamp, so subclasses (such as Infrahub's own Timestamp) had to cast
before touching anything they add on top.

Self comes from typing_extensions rather than typing, since typing.Self
is 3.11+ and the SDK supports 3.10.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ajtmccarty
ajtmccarty requested a review from a team as a code owner August 13, 2026 00:15
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: ae7b4d3
Status: ✅  Deploy successful!
Preview URL: https://80895abf.infrahub-sdk-python.pages.dev
Branch Preview URL: https://ajtm-timestamp-self-return-t.infrahub-sdk-python.pages.dev

View logs

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

Re-trigger cubic

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##           stable    #1241      +/-   ##
==========================================
- Coverage   83.37%   82.54%   -0.84%     
==========================================
  Files         141      138       -3     
  Lines       13577    12186    -1391     
  Branches     2195     1833     -362     
==========================================
- Hits        11320    10059    -1261     
+ Misses       1642     1568      -74     
+ Partials      615      559      -56     
Flag Coverage Δ
integration-tests 40.56% <0.00%> (-0.19%) ⬇️
python-3.10 56.34% <0.00%> (-2.11%) ⬇️
python-3.11 56.34% <0.00%> (-2.11%) ⬇️
python-3.12 56.34% <0.00%> (-2.11%) ⬇️
python-3.13 56.32% <0.00%> (-2.12%) ⬇️
python-3.14 56.34% <0.00%> (-2.09%) ⬇️
python-filler-3.12 22.27% <100.00%> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
infrahub_sdk/timestamp.py 82.88% <100.00%> (ø)

... and 9 files with indirect coverage changes

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

@ajtmccarty
ajtmccarty merged commit 91bcbcb into stable Aug 13, 2026
21 checks passed
@ajtmccarty
ajtmccarty deleted the ajtm-timestamp-self-return-type branch August 13, 2026 13:22
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