Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Property tables #9461

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 4 commits into from
Nov 7, 2017
Merged

Property tables #9461

merged 4 commits into from
Nov 7, 2017

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Oct 17, 2017

As mentoned by @efiring in #9414 (comment), the "unknown" entries in the property tables are rather, hum, unsightly. Fix this by adding ACCEPTS entries to the relevant setters (or at least most of them). Also added a numpydoc Parameters table when appropriate.

I can't say I particularly like the approach, but it's what we have right now. The "dot dot" syntax puts the entry in a rst comment, so they won't appear in the rendered docs. I would also have preferred putting them after the numpydoc Parameters table, but numpydoc is apparently unaware that these are comments, and think that they are documentation for an argument named ...

Also deleted some useless explicit renderings of the table (Text and Patch) -- these get overwritten after the corresponding artist class is fully defined.

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

Note that the syntax used puts the ACCEPTS string in a rst comment, so
they won't appear in the rendered docs.

They need to be put higher than the Parameters table because numpydoc
does not handle rst comments correctly...
@dstansby dstansby added this to the v2.1.1 milestone Nov 4, 2017
# these are not available for the object inspector until after the
# class is built so we define an initial set here for the init
# function and they will be overridden after object definition
docstring.interpd.update(Patch="""
Copy link
Member

Choose a reason for hiding this comment

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

All looks good to me, but I'm not sure why these have been deleted?

Copy link
Contributor Author

@anntzer anntzer Nov 4, 2017

Choose a reason for hiding this comment

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

Because the proper version (with all the properties extracted from the docstrings) is defined at https://github.com/anntzer/matplotlib/blob/8cc0c57bc7dd638a503221f600f933efa671a046/lib/matplotlib/patches.py#L560, overwriting the old (& thus unused) definition. (Other cases are similar.)

----------
t : `~.Transform`

..
Copy link
Member

Choose a reason for hiding this comment

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

This looks funny when rendered. Is that what was wanted? From your comment I assumed this wouldn't render...

matplotlib_artist_artist_set_transform_ _matplotlib_2_0_2_post5339_g8cc0c57_documentation

Copy link
Contributor Author

@anntzer anntzer Nov 6, 2017

Choose a reason for hiding this comment

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

I had to put it before the table, or indented within it (actually that will probably look better). Fix coming...

(This is really a limitation of numpydoc.)

@jklymak
Copy link
Member

jklymak commented Nov 6, 2017

That renders better. I'm not clear on what this is supposed to do, however... Where do these "Accepts" now show up? Just in the code? Sorry for not following...

@anntzer anntzer force-pushed the property-tables branch 2 times, most recently from 6dc8c7a to 55708b9 Compare November 6, 2017 20:36
@anntzer
Copy link
Contributor Author

anntzer commented Nov 6, 2017

Compare
https://298-7439715-gh.circle-artifacts.com/0/home/circleci/project/doc/build/html/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D
and
http://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D
or the class docstring at the prompt.

(for some reason the property table was not added to the Artist class itself, but it is inherited by subclasses).

----------
snap : Optional[bool]
..
ACCEPTS: Optional[bool]
Copy link
Member

Choose a reason for hiding this comment

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

This renders to this
image
Is it what you meant?
P.S: For me an optional argument is the one you can skip, so in that case .set_snap() should be valid, but here we have [ None | bool ]

Copy link
Contributor Author

@anntzer anntzer Nov 6, 2017

Choose a reason for hiding this comment

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

No, Optional[t] means Union[t, None] (https://docs.python.org/3/library/typing.html#typing.Optional).

Note that this is not the same concept as an optional argument, which is one that has a default. An optional argument with a default needn’t use the Optional qualifier on its type annotation (although it is inferred if the default is None). A mandatory argument may still have an Optional type if an explicit value of None is allowed.

Copy link
Member

Choose a reason for hiding this comment

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

Well, that was confusing, thanks for clarifying.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I agree that foo or None is less confusing than Optional[None], fixed accordingly.

@jklymak
Copy link
Member

jklymak commented Nov 6, 2017

You have some funky error though:

lib/matplotlib/tests/test_artist.py:248: AssertionError

@anntzer
Copy link
Contributor Author

anntzer commented Nov 6, 2017

should be fixed

@jklymak jklymak merged commit 2fdef9e into matplotlib:master Nov 7, 2017
@lumberbot-app
Copy link

lumberbot-app bot commented Nov 7, 2017

There seem to be a conflict, please backport manually

@jklymak
Copy link
Member

jklymak commented Nov 7, 2017

@anntzer Hopefully I didn't mess up this merge, but the backport needs to be manually monkeyed with.

@anntzer anntzer deleted the property-tables branch November 7, 2017 21:26
tacaswell pushed a commit that referenced this pull request Dec 6, 2017
Property tables

Conflicts:
	lib/matplotlib/axes/_base.py
	   - rejected documentation updates for behavior that was
	     not backported
	lib/matplotlib/tests/test_artist.py
	   - conflicts between added tests
@tacaswell
Copy link
Member

backported to v2.1.x as 0f86067

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.

5 participants