DefDAP icon indicating copy to clipboard operation
DefDAP copied to clipboard

Add type hinting

Open rhysgt opened this issue 3 years ago • 0 comments

Details here: https://docs.python.org/3/library/typing.html. Already finished the process on the following functions:

  • [ ] base.py
  • [ ] crystal.py
  • [X] file_readers.py
  • [X] file_writers.py
  • [ ] hrdic.py
  • [X] inspector.py
  • [ ] plotting.py
  • [X] quat.py
  • [X] utils.py

I have also added a sphinx extension, which means that we no longer need the type in the arguments in docstring.

Note: If you want to specify a description of what is returned, then you also need the return type in the docstring (even if it's type hinted). Note: Numpy are adding a typing library in 1.20.0, until then it is not possible to use 'np.array[Quat]' (for example) as a type, so I have not fully defined the type in this case and have left it in the docstring instead. In future, will be able do from np.typing import ArrayLike then ArrayLike[Quat] as a type hint. Note: When referring to the parent class from a method type hint, a string literal needs to be used for forward reference in python <3.10. Postponed evaluation of annotations has been added in Python 3.10 (see https://www.python.org/dev/peps/pep-0563/).

Started in #79

rhysgt avatar Mar 02 '21 20:03 rhysgt