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

POC: Showcases for support type hints #2793

Closed
wants to merge 7 commits into from
Closed

Conversation

seisman
Copy link
Member

@seisman seisman commented Nov 2, 2023

Description of proposed changes

Related to #2794.

Type Hints are powerful and can be used to provide better auto-completion (address #1203).

Here are some showcases in VSCode.

Autocompletion for **kwargs parameters

autocompletion-parameters.webm

Autocompletion for parameter's allowed values

autocompletion-valid-values.mov

Autocompletion for dict keys

Implement the syntax 1 in #1078 (comment) and address the concern in #1078 (comment)

autocompletion-dict-keys.webm

@seisman seisman mentioned this pull request Nov 2, 2023
3 tasks
@seisman seisman changed the title POC: Add type hints to for dataset loading functions to support autocompletion POC: Showcases for support type hints Nov 3, 2023
@seisman seisman force-pushed the typehints/datasets branch from 3d877ff to 966537f Compare November 3, 2023 09:42
projection: Any = None,
area_thresh: Any = None,
frame: Any = None,
resolution: Literal["f", "h", "i", "l", "c", "a", None] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think if we could get this to show up in the Sphinx docs too at https://pygmt-dev--2793.org.readthedocs.build/en/2793/api/generated/pygmt.Figure.coast.html? Currently we're following GMT and it might be a bit confusing for new users on what | means

image

One way is to use something like https://github.com/tox-dev/sphinx-autodoc-typehints. See example at https://pyproject-api.readthedocs.io/en/latest/#pyproject_api.Frontend.metadata_from_built on how it could look like:

image

But of course, this is the simple case. There are other cases where we can combine letters, and we'll need to think about that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth a try.

@seisman seisman added the typing Type hints and static type checking label Nov 15, 2023
@seisman
Copy link
Member Author

seisman commented Nov 24, 2023

Can anyone else check if changes in this PR work in Jupyter Notebooks? I can't make it work even after following this post (https://saturncloud.io/blog/autocomplete-jupyter-notebook/).

@weiji14
Copy link
Member

weiji14 commented Nov 25, 2023

Can anyone else check if changes in this PR work in Jupyter Notebooks? I can't make it work even after following this post (https://saturncloud.io/blog/autocomplete-jupyter-notebook/).

Doesn't seem to work for me on JupyterLab 4.0.7:

Peek 2023-11-25 17-44

Using %config IPCompleter.greedy=True seems worse, it suggests 01d 😅:

Peek 2023-11-25 17-49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typing Type hints and static type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants