GenericMappingTools / GenericMappingTools/pygmt

Support Type Hints

Open
#2,794 4 comments 1 reaction 0 assignees View on GitHub
longterm typing
Dominant language
Python
Stars
874
Forks
255
Avg merge
1d 21h
Merged PRs (30d)
40

Description

*This issue is still in draft mode. Type hints are something new to me, so I need to learn more and will keep improving the issue description.*

### What's Python's Type Hints

- A short introduction: https://vegibit.com/introduction-to-python-type-hints/

### Why we should support type hints

*Copied from https://vegibit.com/introduction-to-python-type-hints/*.

- Improved code readability: Type hints make it easier for other developers to understand your code. By clearly specifying the types of arguments and return values, you can help others quickly grasp the intent of your code.
- Improved development speed: With type hints, you can catch potential bugs and errors early in the development process. This can save you time in the long run, as you can fix errors before they cause problems in your code.
- Improved tooling support: Many tools, such as static analyzers and IDEs, use type hints to provide better support for your code. For example, they can use type hints to catch potential errors, suggest code improvements, or provide better autocompletion.
- Better auto-completion for parameter values: See #2793 for how Type Hints can affect the way we use PyGMT.

### Tasks

- [x] Use Mypy for static type checking #2808
- [x] #2812
- [ ] Enable ruff's [`ANN`](https://docs.astral.sh/ruff/rules/#flake8-annotations-ann) rules to make sure all parameters are annotated? [Maybe it's unnecessary, because mypy has a strict mode]

### References:

- https://docs.python.org/3/library/typing.html [TL;DR]
- https://typing.readthedocs.io/en/latest/source/libraries.html
- https://typing.readthedocs.io/en/latest/source/best_practices.html
- https://www.pythonlikeyoumeanit.com/Module5_OddsAndEnds/Writing_Good_Code.html#Type-Hinting

### Related PEPs

- PEP 563: https://peps.python.org/pep-0563/
- PEP 484: https://peps.python.org/pep-0484/
- PEP 585: https://peps.python.org/pep-0585/
- PEP 604: https://peps.python.org/pep-0604/

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.