Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Accept non-unit type annotations in @quantity_input #7672
Instead of raising an error,
>>> import astropy.units as u >>> @u.quantity_input ... def f(x: u.m, y: str) -> u.m: ... return x >>> f(1 * u.m, 'x') <Quantity 1. m> # this would otherwise give # TypeError: <class 'str'> can not be converted to a Unit
It will however, raise a
>>> import astropy.units as u >>> @u.quantity_input ... # consider the typo "kilogrammm" instead of "kilogram" ... def f(x: u.m, y: "kilogrammm") -> u.m: ... return x >>> f(1 * u.m, 2 * u.kg) ValueError: Invalid unit or physical type 'kilogrammm'.
TLDR; @quantity_input now ignores any parameter in function definition which is non-unit type annotated, but will raise a
Hi there @ritiek
I noticed the following issue with this pull request:
Would it be possible to fix this? Thanks!
If there are any issues with this message, please report them here.
@bsipocz My apologies, I completely forgot about this PR.
I'm currently in the midst of my final exams and probably won't have time to work on this until this weekend. It would probably be best if you guys could re-milestone as I wouldn't want the release to delay cuz of this PR.