Replies: 1 comment 2 replies
-
The suggestion isn't to add type hints to every part of the code (since type hints are optional and has no effect on runtime). |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Type hints (or annotations) are great self-documenting code. Along with a type checker, you can have the benefit of statically typed languages in your editor.
To introduce type hints to MulensModel there are a few compatibility code to add. For Python 3.6 (it's currently end of life), we'll need to add the
typing_extensions
package. For Python 3.7+, we need to addfrom __futures__ import annotations
to use any future typing features introduced in the latest version of Python.Use Case
In the code below,
MulensData
can be instantiated with data passed intodata_list
which accepts a list of three collections (by the docstring some users may infer you can pass in anything that can become anndarray
).Instead of relying on the users to correctly interpret docstring, we may add type hinting to explictly let the type checking check that
data_list
contains 3 items and each item can be converted to ndarray via:For code reusage, we may make use of Type Alias:
Although I much prefer using dictionaries
Beta Was this translation helpful? Give feedback.
All reactions