Repository navigation
Make @validate_quantities accept Quantity[Unit] style annotations - #2346
Conversation
|
Thank you for submitting a pull request (PR) to PlasmaPy! ✨ The future of the project depends on contributors like you, so we deeply appreciate it! 🌱 Our contributor guide has information on:
The bottom of this page shows several checks that are run for every PR. Don't worry if something broke! We break stuff all the time. 😺 Click on "Details" to learn why a check didn't pass. Please also feel free to ask for help. We do that all the time as well. 🌸 You can find us in our chat room or weekly community meeting & office hours. Here are some tips:
If this PR is marked as ready for review, someone should stop by to provide a code review and offer suggestions soon. ✅ If you don't get a review within a few days, please feel free to send us a reminder. Please also use SI units within PlasmaPy, except when there is strong justification otherwise or in some examples. We thank you once again! |
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2346 +/- ##
=======================================
Coverage 98.35% 98.35%
=======================================
Files 100 100
Lines 8567 8571 +4
=======================================
+ Hits 8426 8430 +4
Misses 141 141
☔ View full report in Codecov by Sentry. |
…ntities-annotations
Description
This PR makes it so that
@validate_quantitiesaccepts annotations of the style:I still need to update the documentation and make more thorough tests.
This might not work for Python 3.9, but it should work for Python 3.10+. We can add the capability now, but we will not be able to apply it in our repository until we drop Python 3.9 support for our 2024.5.0 release.I was pleasantly surprised that this is working for Python 3.9 as well as 3.10 & 3.11. Not sure why...but I'll take it!
Motivation and context
Before this pull request, annotations used by
@validate_quantitieshad to be unit-like objects, likef(x: u.m):. However, this is incompatible with mypy, which is expectingQuantityas an annotation. This PR will make it so that annotations can actually be type hint annotations.Related issues
Closes #1413. Related to #268.