Skip to content

Start replacing ACCEPTS table by parsing numpydoc. #11300

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
May 26, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented May 24, 2018

In most cases, we can just look for 'param : type' in the docstring.

We let ACCEPTS still have the priority to handle weird cases such as
set_xlim where we document the first arg as "bottom", but it's "bottom,
top" for the purpose of the ACCEPTS table; resolving that problem is
punted to later.

Only removed a few ACCEPTS entries as a proof of principle.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 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

@anntzer anntzer added this to the v3.0 milestone May 24, 2018
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Would have merged if you didn't throw the artist.py change in there 😉

@anntzer
Copy link
Contributor Author

anntzer commented May 25, 2018

Well I did need to change artist.py to update the regex matching... (I didn't need to update the docstring, though, indeed.)

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.

Can you please add a test for added logic.

Parameters
----------
labels : list of str
labels : List[str]
Copy link
Member

Choose a reason for hiding this comment

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

Did we somewhere agree to switch to type annotation syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Grepping for 'List[' shows that it's definitely already being used.

lib/matplotlib/contour.py
576:        lw = self.get_label_width(self.labelLevelList[lmin],
577:                                  self.labelFmt, self.labelFontSizeList[lmin])
591:        self.add_label(xmin, ymin, rotation, self.labelLevelList[lmin],
592:                       self.labelCValueList[lmin])
1039:        artists : List[`.Artist`]
1042:        labels : List[str]
1810:        hatches : List[str], optional

lib/matplotlib/collections.py
386:        urls : List[str] or None
387:            .. ACCEPTS: List[str] or None

lib/matplotlib/tight_layout.py
52:    num1num2_list : List[int]

lib/matplotlib/widgets.py
515:        labels : List[str]
518:        actives : List[bool], optional
2484:    button : List[Int], optional

lib/matplotlib/backend_bases.py
1257:    callbacks : List[Tuple[callable, Tuple, Dict]]
2368:        callbacks : List[Tuple[callable, Tuple, Dict]]

lib/matplotlib/axes/_base.py
1613:        v : List[float] or one of the strings listed below.

Copy link
Member

Choose a reason for hiding this comment

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

I'll accept this for now, even tough I would like to have it discussed and agreed upon. I'm not sure if this is really the best way. Whatever the policy is, it needs documentation. I'll leave the topic for #10225.

In most cases, we can just look for 'param : type' in the docstring.

We let ACCEPTS still have the priority to handle weird cases such as
set_xlim where we document the first arg as "bottom", but it's "bottom,
top" for the purpose of the ACCEPTS table; resolving *that* problem is
punted to later.

Only removed a few ACCEPTS entries as a proof of principle.
@anntzer
Copy link
Contributor Author

anntzer commented May 26, 2018

Added test.

Parameters
----------
labels : list of str
labels : List[str]
Copy link
Member

Choose a reason for hiding this comment

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

I'll accept this for now, even tough I would like to have it discussed and agreed upon. I'm not sure if this is really the best way. Whatever the policy is, it needs documentation. I'll leave the topic for #10225.

# Much faster than list(inspect.signature(func).parameters)[1],
# although barely relevant wrt. matplotlib's total import time.
param_name = func.__code__.co_varnames[1]
match = re.search("(?m)^ *{} : (.+)".format(param_name), docstring)
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 quite sure, what we want the exact sematics to be.

What about foo : int, optional, default: None?

Do we want just int or int, optional, default: None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are all setters, so the first argument "should" never be optional or have a default. As always, there are exceptions (set_xlim(left=...)), but again the point is to handle these with the fallback ACCEPTS table.

I don't think it's worth adding more machinery to this.

@timhoffm timhoffm merged commit ec66f36 into matplotlib:master May 26, 2018
@anntzer anntzer deleted the noACCEPTS branch May 26, 2018 19:45
:class:`Artists` are of the same type) and it is your responsibility
to make sure this is so.
Initialize the artist inspector with an `Artist` or an iterable of
`Artist`\s. If an iterable is used, we assume it is a homogeneous
Copy link
Member

Choose a reason for hiding this comment

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

This make the tests fail for me: SyntaxError: invalid escape sequence \s Do I have an old version of something lying around?

Copy link
Member

Choose a reason for hiding this comment

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

Handled by #11336

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