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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions doc/devel/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,23 @@ C/C++ extensions
docstrings, and the Numpydoc format is well understood in the
scientific Python community.

New public APIs
---------------

Public APIs added to Matplotlib are bound by backwards compatibility, and
therefore cumbersome to change. Therefore, when adding new functionality, try
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." ?


In order to make it easier to evolve APIs, 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

.. _keyword-argument-processing:

Keyword argument processing
Expand Down