Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces the Alias class as a dataclass-based wrapper for the existing _to_string function to establish the foundation for a new alias system. The class provides a more structured and object-oriented approach to handling parameter aliasing between PyGMT's long-form arguments and GMT's short-form options.
- Adds the
Aliasdataclass with attributes matching_to_stringparameters - Implements a
_valueproperty that delegates to the existing_to_stringfunction - Provides comprehensive documentation with usage examples
Comments suppressed due to low confidence (1)
pygmt/alias.py:185
- [nitpick] The property name '_value' uses a leading underscore which typically indicates a private/internal attribute, but this appears to be the main interface for accessing the converted value. Consider using 'value' or 'converted_value' for better API clarity.
def _value(self) -> str | list[str] | None:
This was referenced Jul 26, 2025
seisman
commented
Jul 28, 2025
pygmt/alias.py
Outdated
| return f"{prefix}{_value}" | ||
|
|
||
|
|
||
| @dataclasses.dataclass |
Member
Author
There was a problem hiding this comment.
Since it's just a simple class with one property, I'm wondering if we should avoid using dataclass and instead write it like:
class Alias:
def __init__(value, name=None, prefix="", ....):
self.value = value
self.name = name
self.prefix = prefix
...
self._value = _to_string(
value=self.value,
name=self.name,
prefix=self.prefix,
mapping=self.mapping,
separator=self.separator,
size=self.size,
ndim=self.ndim,
)
Member
Author
There was a problem hiding this comment.
The plain class is about 30% faster than dataclass. Considering that the Alias class is used extensively in the project, I've rewritten it in 4cdef8b.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the
Aliasclass, which wraps the _to_string function and is responsible for converting any value into a string or a list of strings.It's the basis of the new alias system (#4000) and class-like parameters (see #3995). So, please review PRs #3995 and #4000 first.