You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After adding Literal type hints, most text editors and IDEs can provide better autocompletion for the valid values. For example (please ignore the incorrect registration="registration" code in the demo below. It's caused by a typo):
autocompletion-valid-values.mov
TODO
Some notes:
For each PR, we should work on a single parameter used by multiple functions (e.g., updating registration in all load_earth_xxx functions), rather than working on multiple parameters in a single function (e.g., updating registration and data_source in the load_earth_relief function). I think it will make the review much easier.
Focus on parameters listed in function definitions (e.g., registration in load_earth_relief) rather than GMT's aliased parameters (e.g., registration in pygmt.xyz2grd, which is aliased to the -r option). Type hints for these aliased parameters need more discussions.
Some parameters may have a long list of valid values (e.g., load_earth_relief's resolution parameter can have 15 valid values). Need to discuss if we should add such a long list Literal values.
Here is an incomplete list of parameters that we should add Literal type hints. **Please add your name to the end of the entry if you wan to work on it (in case you can edit this post) or just leave a comment so that we know you're working on it).
Literal Types indicate a variable has a specific and concrete value. It was introduced in PEP 586 and is available since Python 3.8.
I'll take the
pygmt.datasets.load_earth_relief
function as an example. Currently, the function definition is:in which,
registration
can begridline
,pixel
or None, anddata_source
can beigpp
,gebco
,gebcosi
,synbath
.To add Literal type hints for these two parameters, we need to change the function definition to:
We also need to remove the "type" from the docstrings (e.g., changing
registration : str
toregistration
(see https://www.sphinx-doc.org/en/master/usage/extensions/example_numpy.html).After adding Literal type hints, most text editors and IDEs can provide better autocompletion for the valid values. For example (please ignore the incorrect
registration="registration"
code in the demo below. It's caused by a typo):autocompletion-valid-values.mov
TODO
Some notes:
registration
in allload_earth_xxx
functions), rather than working on multiple parameters in a single function (e.g., updatingregistration
anddata_source
in theload_earth_relief
function). I think it will make the review much easier.registration
inload_earth_relief
) rather than GMT's aliased parameters (e.g.,registration
inpygmt.xyz2grd
, which is aliased to the-r
option). Type hints for these aliased parameters need more discussions.load_earth_relief
'sresolution
parameter can have 15 valid values). Need to discuss if we should add such a long list Literal values.Here is an incomplete list of parameters that we should add Literal type hints. **Please add your name to the end of the entry if you wan to work on it (in case you can edit this post) or just leave a comment so that we know you're working on it).
registration
in allload_earth_xxx
functions inpygmt/datasets/load_*.py
TYP: Add type hints for the 'registration' parameter in pygmt.datasets.load_* functions #2867data_source
inload_earth_relief
andload_earth_magnetic_anomaly
TYP: Add type hints for 'data_source' in load_earth_relief and load_earth_magnetic_anomaly functions #2849resolution
in allload_earth_xxx
functions (? The list of available resolutions is very long).load_sample_data
'sname
parameter (? More maintenance burden ) TYP: Add type hints support for pygmt.datasets.load_sample_data #2859output_type
(valid values arefile
,numpy
andpandas
) in modules likegrdtrack
,grd2xyz
Figure.solar
'sterminator
parameter Figure.solar: Add type hints to the 'terminator' parameter and simplify codes #2881References:
The text was updated successfully, but these errors were encountered: