Skip to content

Limitations of the kwargs_to_strings decorator not handling positional arguments #2361

Closed

Description

@seisman

Here are some limitations of the kwargs_to_strings decorator:

  1. Doesn't work for the default values of parameters:

#2208 (comment)

Please note that we can't use decorator @kwargs_to_strings(offset="sequence") here, because the decorator can only deal with keyword arguments and doesn't work for the default values. I.e., it doesn't work for Figure.timestamp() but works for Figure.timestamp(offset=["-54p", "-54p"]), although offset defaults to ["-54p", "-54p"].

@kwargs_to_strings(offset="sequence")
def timestamp(
    self,
    text=None,
    label=None,
    justification="BL",
    offset=("-54p", "-54p"),
    font="Helvetica",
    timefmt="%Y %b %d %H:%M:%S",
):
  1. Doesn't work if the parameter name is not given
>>> from pygmt import which
>>> # doesn't work
>>> which(["@hotspots.txt", "@earth_relief_01d_g"])
gmtwhich [ERROR]: File ['@hotspots.txt', not found!
gmtwhich [ERROR]: File '@earth_relief_01d_g'] not found!
>>> # works
>>> which(fname=["@hotspots.txt", "@earth_relief_01d_g"])

Activity

  1. added
    bug
    on Feb 12, 2023
  2. changed the title [-]Limitations of the kwargs_to_strings decorator[/-] [+]Limitations of the kwargs_to_strings decorator not handling positional arguments[/+] on Oct 15, 2023
  3. weiji14 commented on Oct 15, 2023

    @weiji14
    Member

    This issue would also apply to fig.text's textfiles parameter that uses sequence_space added in #325.

    pygmt/pygmt/src/text.py

    Lines 41 to 50 in c9d6147

    textfiles="sequence_space",
    angle="sequence_comma",
    font="sequence_comma",
    justify="sequence_comma",
    c="sequence_comma",
    p="sequence",
    )
    def text_(
    self,
    textfiles=None,

    Should we remove sequence_space entirely since it is only used in pygmt.which and fig.text? And use the if is_nonstr_iter(fname): fname = " ".join(fname) patch in #2726?

  4. seisman commented on Oct 15, 2023

    @seisman
    MemberAuthor

    And use the if is_nonstr_iter(fname): fname = " ".join(fname) patch in #2726?

    No, it won't work for Figure.text, because textfiles can be a 2-D array, e.g., textfiles=[[1, 2, "A"], [3, 4, "B"]].

  5. weiji14 commented on Oct 15, 2023

    @weiji14
    Member

    And use the if is_nonstr_iter(fname): fname = " ".join(fname) patch in #2726?

    No, it won't work for Figure.text, because textfiles can be a 2-D array, e.g., textfiles=[[1, 2, "A"], [3, 4, "B"]].

    Ah ok, you're right. Let's keep sequence_space then. So #2726 will fix this issue entirely? Can we change Addresses #2726 to Fixes #2726 or was there something else?

  6. seisman commented on Oct 15, 2023

    @seisman
    MemberAuthor

    So #2726 will fix this issue entirely?

    No, see the first point:

    Doesn't work for the default values of parameters:

  7. added this to the 0.11.0 milestone on Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions