New Alias System: Add the private _to_string function#3986
Conversation
01b8267 to
8f5c52b
Compare
pygmt/alias.py
Outdated
| match mapping: | ||
| case False: | ||
| pass | ||
| case True: | ||
| value = value[0] | ||
| case Mapping(): | ||
| if value not in mapping and value not in mapping.values(): | ||
| raise GMTValueError( | ||
| value, | ||
| description="value for parameter {name!r}" if name else "value", | ||
| choices=mapping.keys(), | ||
| ) |
There was a problem hiding this comment.
mapping=True means using the first letter of a long-form argument as its short-form argument. For example, resolution="high" will be mapped to resolution="h". If we don't support mapping=True, lines 112-123 can be simplified to a few lines:
if value not in mapping and value not in mapping.values():
raise GMTValueError(
value,
description="value for parameter {name!r}" if name else "value",
choices=mapping.keys(),
)but without mapping=True, we need to write something like
mapping={"full": "f", "high": "h", "intermediate": "i", "low": "l", "crude": "c"}
when calling the _to_string function.
There was a problem hiding this comment.
I think better to be explicit (use the full mapping {"key": "value"} dict), and just have one way to parse things. We can use the first letter for resolution, but for others like interpolation/-n, where the mapping is {"b-spline": "b", "bicubic": "c", "bilinear": "l", ...}, it doesn't work.
weiji14
left a comment
There was a problem hiding this comment.
This looks ok to me, was there anything else you wanted to add?
Need to wait for #3985 |
Part 1 of PR #3238