Skip to content

Provide signatures to some C-level classes and methods. #15009

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

Merged
merged 1 commit into from
Aug 10, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Aug 8, 2019

Compare e.g. an excerpt of the docs of matplotlib._tri.Triangulation
before

 |  calculate_plane_coefficients(...)
 |      calculate_plane_coefficients(z, plane_coefficients)
 |
 |      Calculate plane equation coefficients for all unmasked triangles
 |
 |  get_edges(...)
 |      get_edges()
 |
 |      Return edges array

and after

 |  calculate_plane_coefficients(z, plane_coefficients)
 |      Calculate plane equation coefficients for all unmasked triangles
 |
 |  get_edges()
 |      Return edges array

This means that inspect.signature() now knows about the correct
signature, and signature tests can use inspect.signature().bind rather
than matching on the error string.

The convention of using "func_name(arg, ...)--\n\n" for
C-level signatures is admittedly undocumented, but comes from
https://bugs.python.org/issue20530.

Inspired by the need to update error message strings in #14964 (although this would not have helped because Py2 doesn't support inspect.signature, but heh).

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

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.

+1 for the signature changes.

-0.5 for the changes to the tests. I think they should be pytest.raises(TypeError, match=...).

@@ -382,9 +383,8 @@ def test_subplots_shareax_loglabels():

def test_savefig():
fig = plt.figure()
msg = r"savefig\(\) takes 2 positional arguments but 3 were given"
with pytest.raises(TypeError, match=msg):
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that these replacements are beneficial to the tests. Understanding bind is more difficult and less readable.

@QuLogic
Copy link
Member

QuLogic commented Aug 10, 2019

I agree with @timhoffm; the test is there to confirm that if a user runs x, they will get y error. I think very few users would use inspect.signature.

Compare e.g. an excerpt of the docs of matplotlib._tri.Triangulation
before
```
 |  calculate_plane_coefficients(...)
 |      calculate_plane_coefficients(z, plane_coefficients)
 |
 |      Calculate plane equation coefficients for all unmasked triangles
 |
 |  get_edges(...)
 |      get_edges()
 |
 |      Return edges array
```
and after
```
 |  calculate_plane_coefficients(z, plane_coefficients)
 |      Calculate plane equation coefficients for all unmasked triangles
 |
 |  get_edges()
 |      Return edges array
```

The convention of using "func_name(arg, ...)--\n\n" for
C-level signatures is admittedly undocumented, but comes from
https://bugs.python.org/issue20530.
@anntzer
Copy link
Contributor Author

anntzer commented Aug 10, 2019

ok, reverted the tests change

Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

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

When tests pass

@timhoffm timhoffm merged commit f254b79 into matplotlib:master Aug 10, 2019
@anntzer anntzer deleted the csig branch August 10, 2019 10:27
@dstansby dstansby added this to the v3.2.0 milestone Aug 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants