Cleaning up variable argument signatures · Issue #9912 · matplotlib/matplotlib · GitHub
Skip to content

Cleaning up variable argument signatures #9912

Description

@timhoffm

There are a lot of *args, **kwargs signatures in the API. In many cases, they could be better described by explicit arguments/kw-arguments. This makes for a more clear API and reduces the chance of unintended misuse.

For example pyplot.delaxes

def delaxes(*args):
    """..."""
    if not len(args):
        ax = gca()
    else:
        ax = args[0]
    ...

would be more clear with

def delaxes(ax=None):
    """..."""
    if ax is None:
        ax = gca()
    ...

For all intended uses, the API compatibility is preserved. Unreasonable and possibly wrong uses like
delaxes(ax1, ax2) or delaxes(ax, mykwarg=True) would raise an Exception after the change. In itself, this is a benefit, because these cases will then be detected as false usage. However it may break existing programs.

Before I do any pull requests, is there a policy how to handle such cases?

  • Do you want to change these things, or should they be left as they are:
    • for cases like the above one where arguments are directly resolved in the function/method?
    • for cases where the all the arguments are passed like e.g. pyplot.savefig?
  • Which branch should changes go into?

Activity

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

    API: changesChanges to the public API, typically requiring deprecation.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions