Description
Jupyter and most modern text editors support tab autocompletion, which is useful for typing long function and parameter names. However, currently, most PyGMT functions don't support tab autocompletion, since we use the alias system (use_alias
), *args
, and **kwargs
. The only way I know to enable tab autocompletion is using normal Python parameters instead of relying on the **kwargs
and use_alias
decorator (see #262 for the original issue).
The solution seems straightforward. For example, for the pygmt.info()
function, the current function is defined as:
@fmt_docstring
@use_alias(
C="per_column",
I="spacing",
T="nearest_multiple",
V="verbose",
a="aspatial",
f="coltypes",
r="registration",
)
@kwargs_to_strings(I="sequence")
def info(table, **kwargs):
To make it support tab autocompletion, we just need to change the def info()
part:
@fmt_docstring
@use_alias(
C="per_column",
I="spacing",
T="nearest_multiple",
V="verbose",
a="aspatial",
f="coltypes",
r="registration",
)
@kwargs_to_strings(I="sequence")
def info(
table,
per_column=False,
spacing=None,
nearest_multiple=None,
verbose=None,
aspatial=None,
coltypes=None,
registration=None,
**kwargs
):
Since all parameters are defined as normal Python parameters, tab autocompletion should work. The new function definition still keeps the **kwargs
parameter, so that single-letter options are still supported (but we are likely to disallow single-letter options in future releases, see #262). Thus, this would be backward compatible, and is the first step to address #262.
The screenshots below show how the autocompletion work after applying the changes in PR #1202:
Current pygmt.info() |
Updated pygmt.info() |
---|---|
![]() |
![]() |
![]() |
![]() |
Please give #1202 a try and leave your thoughts.