Use of type hints in NLmod #446
Replies: 3 comments
-
|
I like type hints where it really helps to make it clearer what the input should be, e.g. for options especially or for functions where it isn't as clear. I don't think it's really necessary where the argument name makes it really clear what it expects. But doing it halfway is also weird, so I think my vote is yes on type hinting. But I also don't feel like adding it everywhere all at once, so slowly over time is fine by me. So big fan of this: def func(da: xr.DataArray | np.ndarray, method: Literal['simple_method', 'some_other_method']) -> xr.DataArray:This i don't think is very necessary to make things clearer, and does add a bit a of clutter. But on the whole, I'm fine with this clutter if it makes stuff more clear in the ambiguous cases. def func(ax: plt.Axes)And I think we need to define some of our own complex types that we allow for our functions e.g. |
Beta Was this translation helpful? Give feedback.
-
|
I really like type hinting as you have noticed :) from typing import Union, List
A: List[Union[int, str]]= [1,"b"]but just clean python code: A: list[int | str] = [1, "b"]I'm against type checking with MyPy for NLmod. That makes life way too difficult, especially when using other packages that aren't properly typed. But to use type hints as a form of extra documentation/readability sounds great to me. |
Beta Was this translation helpful? Give feedback.
-
|
I am not a fan of type hints, for me it is just an extra effort for which I don't see enough benefits. But to be honest I have not used them yet so maybe I am missing out on something. Therefore if you are in favor I am willing to use them. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
So @martinvonk has been adding type hints to NLmod, which make the use of the code easier. More documentation is probably better, but it does make the code more bulky. I think we should use type hints everywhere or nowhere in NLmod, to maintain some unity within NLmod. But I am curious what others think.
3 votes ·
Beta Was this translation helpful? Give feedback.
All reactions