Skip to content

In contributing.rst, encourage kwonly args and minimizing public APIs. #14545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jun 13, 2019

... so that we can just point PR authors to it instead of explaining
again and again why.

Thought of this while looking at #14512.

Rewordings welcome.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

... so that we can just point PR authors to it instead of explaining
again and again why.
to add as little public API as possible. In particular, make sure that helper
methods and internal attributes are private (i.e., start with an underscore).
Remember that any non-private method can be directly called by the end user,
and any non-private attribute can be directly set!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably leave out this sentence. It is extraneous and doesn't really explain why this is a "bad thing" (it can also confuse some contributors because they'll notice that they can do exactly the same thing with private methods and attributes).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not particularly in love with the wording here, but I do want to stress that point extremely strongly: if an attribute is public, the implementation should be robust against the end user modifying it; otherwise, make it private, or hide it behind a getter or a property.
If you have a better wording I'm all ears :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or add a "And therefore once we have released that API the behavior, arguments, and names can not be changed without going through a multi-version deprecation process." ?

@tacaswell tacaswell added this to the v3.2.0 milestone Jun 13, 2019
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full agreement that we should document this better. (n.b. I'm planning to give a talk on API evolution at PyCon.DE).

You've said, you welcome rewording, so I wrote my own two paragraphs: 😄

API Changes

Changes to the public API must follow a standard deprecation procedure to prevent unexpected breaking of code that uses Matplotlib.

  • Deprecations must be announced via an entry in doc/api/next_api_changes.
  • Deprecations are targeted at the next point-release (i.e. 3.x.0).
  • The respective API must still be fully functional during the deprecation period. If possible, usage of that API should emit a MatplotlibDeprecationWarning (see cbook.warn_deprecated(), the @cbook.deprecated decorator and other helper functions in matplotlib.cbook.deprecation that ease the deprecation of various aspects of an API).
  • Deprecated API may be removed two point-releases after they were deprecated.

Adding new API

Every new function, parameter and attribute that are not explicitly marked as private (i.e., start with an underscore) become part of Matplotlib's public API. As discussed above, changing the existing API is cumbersome. Therefore, take particular care when adding new API:

  • Mark helper functions and internal attributes as private by prefixing them with an underscore.

  • Carefully think about good names for your functions and variables.

  • Try to adopt patterns and naming conventions from existing parts of the Matplotlib API.

  • Consider making as many arguments keyword-only as possible.

    .. seealso:: API Evolution the Right Way -- Add Parameters Compatibly__

__ https://emptysqua.re/blog/api-evolution-the-right-way/#adding-parameters

@anntzer
Copy link
Contributor Author

anntzer commented Jun 13, 2019

It's great :p Do you want to PR it separately, or should I just copy-paste that?

@anntzer
Copy link
Contributor Author

anntzer commented Jun 13, 2019

Although I do want to comment on

The respective API must still be fully functional during the deprecation period.

I think my view is closer to (with pretty bad wording)

The deprecated API should, to the maximum extent possible, remain fully functional during the deprecation period. In cases where this is not possible, the deprecation must never make a given piece of code do something different than it was before; at least an exception should be raised.

(Basically, if something changes and the user gets an exception, the user knows that, well, something needs to be fixed, or at least they'll pin to the previous release. If the behavior of the code changes, on the other hand, the user may well generate incorrect plots without ever realizing it.)

See e.g. #14544...

@timhoffm
Copy link
Member

Feel free to use my text and adapt as proposed. It's getting late here. If nothing has been done tomorrow, I'll pick it up again. 😄

@anntzer
Copy link
Contributor Author

anntzer commented Jun 15, 2019

Replaced by #14555.

@anntzer anntzer closed this Jun 15, 2019
@anntzer anntzer deleted the kwonly branch June 15, 2019 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants