New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make unit validators compatible with u.Quantity[u.T]
-style annotations
#1661
base: main
Are you sure you want to change the base?
Make unit validators compatible with u.Quantity[u.T]
-style annotations
#1661
Conversation
hey @rocco8773, I wanted to ping you for short feedback on what you think about this approach :) |
I wonder whether we shouldn't deprecate the old, |
Codecov ReportBase: 98.31% // Head: 97.19% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1661 +/- ##
==========================================
- Coverage 98.31% 97.19% -1.12%
==========================================
Files 95 84 -11
Lines 8404 8020 -384
==========================================
- Hits 8262 7795 -467
- Misses 142 225 +83
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Oh yeah, here's the crux of the issue. |
To answer potential questions about |
|
Thank you for contributing to PlasmaPy! The project's future depends deeply on contributors like you, so we deeply appreciate it! 🌱 The following checklist will be used by the code reviewer to help guide the code review process.
|
Looks like this won't work without a proper rewrite of |
Possibly closes #1413 and also closes #1414, maybe? Let's see if this blows up.
Essentially what happens when you do, say,
def f(B: u.Quantity[u.T])
is that the annotation becomes atyping._AnnotatedAlias
. Apparently the canonical way of reading type hints for a function istyping.get_type_hints
, but since we didn't go that route for the existing code, I didn't want to start rewriting the whole thing just yet. Instead, the annotation has a__metadata__
field, an iterable of things within the[]
parenthesis. So I just picked the first item in that for now.I've also added this kind of annotation in
frequencies
for now, to see whether they'd explode.docstrings.