Skip to content
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

Make normalize_kwargs more convenient for third-party use. #13978

Merged
merged 1 commit into from
Apr 18, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Apr 17, 2019

... by making it internally fetch the artist's private _alias_map
attribute.

See https://gitter.im/matplotlib/matplotlib?at=5cb748f2375bac7470bd5a8d.

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

... by making it internally fetch the artist's private _alias_map
attribute.
# deal with default value of alias_mapping
if alias_mapping is None:
alias_mapping = dict()
elif (isinstance(alias_mapping, type) and issubclass(alias_mapping, Artist)
Copy link
Member

@timhoffm timhoffm Apr 17, 2019

Choose a reason for hiding this comment

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

Why do you require subclasses of Artist? Wouldn't it be enough to use ducktyping via getattr(alias_mapping, "_alias_map", {}) alone?

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 would rather not duck-type on a private attribute. For example, it would seem a bit silly for the doc to say that the argument can be anything that has an _alias_map attribute. If the docs does say "mapping or Artist subclass or Artist instance", then we may as well make the implementation match that.

Copy link
Member

Choose a reason for hiding this comment

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

I don‘t see a problem with duck-typing on a private attribute if it‘s documented. That would be the low-overhead variant of a KeywordShortcutsMixin. It would allow to use it for other stuff than Artists.

However, we can always revisit later and lift that restriction.

@tacaswell tacaswell added this to the v3.2.0 milestone Apr 18, 2019
@timhoffm timhoffm merged commit 76db501 into matplotlib:master Apr 18, 2019
@anntzer anntzer deleted the normalize_kwargs branch April 18, 2019 08:47
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.

3 participants