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

Skip to content

MNT: Simplify imports #22558

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
Mar 3, 2022
Merged

MNT: Simplify imports #22558

merged 1 commit into from
Mar 3, 2022

Conversation

oscargus
Copy link
Member

PR Summary

import matplotlib.foo as foo

is typically better (shorter) written as

from matplotlib import foo

Note that some of the existing ones are changed in #22148 so these should be (most) of the remaining ones.

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@oscargus oscargus marked this pull request as draft February 25, 2022 14:51
@tacaswell tacaswell added this to the v3.6.0 milestone Feb 25, 2022
@oscargus oscargus marked this pull request as ready for review February 26, 2022 17:31
@oscargus oscargus marked this pull request as draft February 28, 2022 23:02
@oscargus oscargus marked this pull request as ready for review March 2, 2022 12:56
# For clarity, names from _image are given explicitly in this module
from matplotlib import _image
# For user convenience, the names from _image are also imported into
# the image namespace
Copy link
Member Author

Choose a reason for hiding this comment

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

One can actually question this comment. At least, assuming that the whole idea of putting things into _image was to make these functions and classes "private".

Copy link
Member

Choose a reason for hiding this comment

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

It's _image because it's a compiled extension, not necessarily to be private.

Copy link
Member

@timhoffm timhoffm Mar 2, 2022

Choose a reason for hiding this comment

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

_image contains C code (see image_wrapper.cpp). It's a standard but arguably confusing convention to use a leading underscore for C parts of of a python module.

OTOH it's questionable whether we need these wildcard imports. It's just the function resample() plus a number of constants. We don't uses these in image.py (only via the qualified _image.*). Users could use resample(), but it's rather low-level. The only use for the constants is as parameters to resample. The high-level image interface uses string versions of the constants instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the clarification!

I double-checked that nothing is imported from _image through image in the code base and unless I failed or there were some missing dependency not triggering the code, it should at least be OK from that perspective.

But probably safest to keep it as is for now.

@timhoffm timhoffm merged commit 2bb9b03 into matplotlib:main Mar 3, 2022
@oscargus oscargus deleted the simplifyimports branch March 3, 2022 00:15
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