GeezerVison is showing github.com — New Alias System: Add the Alias class by seisman · Pull Request #3993 · GenericMappingTools/pygmt
Conversation
seisman
commented
Jul 10, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
This PR adds the Alias class, 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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Alias dataclass with attributes matching _to_string parameters
- Implements a
_value property that delegates to the existing _to_string function
- 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:
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jul 26, 2025
|
|
return f"{prefix}{_value}"
|
|
|
|
|
|
|
|
|
@dataclasses.dataclass
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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,
)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|