Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Type Hints #2794

Open
2 of 3 tasks
seisman opened this issue Nov 2, 2023 · 3 comments
Open
2 of 3 tasks

Support Type Hints #2794

seisman opened this issue Nov 2, 2023 · 3 comments
Labels
longterm Long standing issues that need to be resolved typing Type hints and static type checking

Comments

@seisman
Copy link
Member

seisman commented Nov 2, 2023

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

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

References:

Related PEPs

@seisman seisman added question Further information is requested feature request New feature wanted longterm Long standing issues that need to be resolved labels Nov 2, 2023
@weiji14
Copy link
Member

weiji14 commented Nov 11, 2023

Personally I do use type hints (and tried to add it to pygmt.grdtrack in 2019 apparently - #308 (comment)), but it can be a lot of work to add them across the whole project (and a bit tough for new contributors to learn).

Maybe we can start small with just typing.Literal since that's a practical one for when there's a choice of str type arguments, e.g. load_earth_relief(..., data_source: Literal["igpp", "gebco", "gebcosi", "synbath"], ...) in #2793? Other types like bool/int/float don't offer any autocomplete so may be less useful for now.

@seisman
Copy link
Member Author

seisman commented Nov 13, 2023

Yes, it's definitely a lot of work and a long-term goal. We need to split it into multiple smaller jobs so that people can help.

@willschlitzer
Copy link
Contributor

Maybe we can start small with just typing.Literal since that's a practical one for when there's a choice of str type arguments, e.g. load_earth_relief(..., data_source: Literal["igpp", "gebco", "gebcosi", "synbath"], ...) in #2793? Other types like bool/int/float don't offer any autocomplete so may be less useful for now.

I think specifying literal argument options is a good start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
longterm Long standing issues that need to be resolved typing Type hints and static type checking
Projects
None yet
Development

No branches or pull requests

3 participants