-
Notifications
You must be signed in to change notification settings - Fork 232
Open
Labels
longtermLong standing issues that need to be resolvedLong standing issues that need to be resolvedtypingType hints and static type checkingType hints and static type checking
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 POC: Showcases for support type hints #2793 for how Type Hints can affect the way we use PyGMT.
Tasks
- Use Mypy for static type checking Add Mypy for static type checking #2808
- TYP: Add type hints for Literal types #2812
- Enable ruff's
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/
weiji14
Metadata
Metadata
Assignees
Labels
longtermLong standing issues that need to be resolvedLong standing issues that need to be resolvedtypingType hints and static type checkingType hints and static type checking