GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — New Alias System: Add the Alias class by seisman · Pull Request #3993 · GenericMappingTools/pygmt

Conversation

@seisman

@seisman seisman commented Jul 10, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

All reactions
@seisman
New Alias System: Add the Alias class
654261c
@seisman seisman added this to the 0.17.0 milestone Jul 10, 2025
@seisman seisman added enhancement Improving an existing feature needs review This PR has higher priority and needs review. and removed needs review This PR has higher priority and needs review. labels Jul 10, 2025
seisman added 5 commits July 16, 2025 09:14
@seisman
Fix
7f43055
@seisman
Merge branch 'main' into AliasSystem/alias
a42c2d8
@seisman
Merge branch 'main' into AliasSystem/alias
bc0401e
@seisman
Put name after value
fae3ab0
@seisman
Merge branch 'main' into AliasSystem/alias
f4f3012
@seisman seisman added the needs review This PR has higher priority and needs review. label Jul 21, 2025
@seisman
seisman requested a review from Copilot July 22, 2025 06:08
Copilot AI reviewed Jul 22, 2025
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
Comment thread pygmt/alias.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@seisman
Merge branch 'main' into AliasSystem/alias
d0ebbcb
This was referenced Jul 26, 2025
POC: Implement the new alias system, general parameter classes and some refactors #3238
Closed
New alias system towards a more Pythonic interface #3239
Closed
@seisman
Merge branch 'main' into AliasSystem/alias
5a9817d
seisman
seisman commented Jul 28, 2025
View reviewed changes
Comment thread pygmt/alias.py Outdated
return f"{prefix}{_value}"


@dataclasses.dataclass

@seisman seisman Jul 28, 2025

Copy link
Copy Markdown
Member Author

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.

All reactions

@seisman seisman Jul 28, 2025

Copy link
Copy Markdown
Member Author

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.

All reactions
seisman added 2 commits July 28, 2025 17:52
@seisman
Avoid using dataclass
4cdef8b
@seisman
No need to store properties that won't be used
e57954d
@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Jul 29, 2025
@seisman
seisman merged commit 3418acd into main Jul 29, 2025
@seisman
seisman deleted the AliasSystem/alias branch July 29, 2025 03:52
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

enhancement Improving an existing feature

Projects

None yet

Milestone

0.17.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@seisman
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.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.