Skip to content

Add quantity stub file?#617

Open
adrn wants to merge 10 commits intoGalacticDynamics:mainfrom
adrn:quantity-stub
Open

Add quantity stub file?#617
adrn wants to merge 10 commits intoGalacticDynamics:mainfrom
adrn:quantity-stub

Conversation

@adrn
Copy link
Copy Markdown
Contributor

@adrn adrn commented Mar 13, 2026

When I use parametric Quantity's for typing, I get loads of mypy errors like "type[Quantity] is not generic and not indexable". I think this is because mypy only recognizes subscriptability for classes that inherit from typing.Generic, so it doesn't understand plum.parametric's __class_getitem__ at runtime.

This adds a minimal .pyi stub declaring Quantity and AbstractParametricQuantity as Generic[_T] (_T: LiteralString), plus most of the relevant operators inherited from the quax_blocks mixins. I think with this, mypy should accept Quantity["time"] and treat Quantity["time"] and Quantity["length"] as distinct types.

This is minimal so far and doesn't replicate the full mixin hierarchy, but I think that's ok for type checking purposes?

(btw: ty handles plum.parametric correctly without the stub, so I guess this is specific to mypy?)

Copilot AI review requested due to automatic review settings March 13, 2026 01:02
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.11%. Comparing base (e9deafa) to head (d0e7e3b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #617      +/-   ##
==========================================
- Coverage   96.29%   94.11%   -2.19%     
==========================================
  Files          57       46      -11     
  Lines        2540     2414     -126     
  Branches      127      121       -6     
==========================================
- Hits         2446     2272     -174     
- Misses         71      121      +50     
+ Partials       23       21       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a typing stub for unxt.quantity to help mypy accept Plum-parametric Quantity[...] usage by declaring AbstractParametricQuantity/Quantity as generics.

Changes:

  • Introduces src/unxt/quantity.pyi defining AbstractQuantity, AbstractParametricQuantity, and Quantity as typed/generic stubs.
  • Adds operator method signatures intended to mirror quax_blocks mixins for basic arithmetic typing.

You can also share your feedback on Copilot code review. Take the survey.

adrn and others added 3 commits March 13, 2026 08:49
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.18%. Comparing base (e9deafa) to head (d63cafa).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #617      +/-   ##
==========================================
- Coverage   96.29%   96.18%   -0.12%     
==========================================
  Files          57       46      -11     
  Lines        2540     2414     -126     
  Branches      127      121       -6     
==========================================
- Hits         2446     2322     -124     
+ Misses         71       70       -1     
+ Partials       23       22       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Copy link
Copy Markdown
Contributor

@nstarman nstarman left a comment

Choose a reason for hiding this comment

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

If this fixes mypy errors then that's good. But does this limit ty's inference?

Copy link
Copy Markdown
Contributor

@nstarman nstarman left a comment

Choose a reason for hiding this comment

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

I think this is correct. It annotates the set types while keeping the init general

@adrn
Copy link
Copy Markdown
Contributor Author

adrn commented Mar 13, 2026

If this fixes mypy errors then that's good. But does this limit ty's inference?

ty is borked for me on any parametric Quantity, but I don't understand why. Potentially related to: astral-sh/ty#2294

adrn and others added 3 commits March 13, 2026 10:34
Co-authored-by: Nathaniel Starkman <[email protected]>
Signed-off-by: Adrian Price-Whelan <[email protected]>
@nstarman nstarman added this to the v1.11.x milestone Mar 13, 2026
adrn and others added 2 commits March 16, 2026 13:12
Co-authored-by: Nathaniel Starkman <[email protected]>
Signed-off-by: Adrian Price-Whelan <[email protected]>
nstarman
nstarman previously approved these changes Mar 16, 2026
Copy link
Copy Markdown
Contributor

@nstarman nstarman left a comment

Choose a reason for hiding this comment

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

We should add a ty job to CI.

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