FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

MNT: Simplify imports by oscargus · Pull Request #22558 · matplotlib/matplotlib · GitHub

Repository navigation

MNT: Simplify imports - #22558

Merged
timhoffm merged 1 commit into
matplotlib:mainfrom
oscargus:simplifyimports
Mar 3, 2022
Merged

timhoffm merged 1 commit into
matplotlib:mainfrom
oscargus:simplifyimports

Conversation

Copy link
Copy Markdown
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).

Comment thread lib/matplotlib/image.py Outdated
oscargus marked this pull request as draft February 25, 2022 14:51
tacaswell added this to the v3.6.0 milestone Feb 25, 2022
oscargus marked this pull request as ready for review February 26, 2022 17:31
Comment thread lib/matplotlib/image.py Outdated
oscargus marked this pull request as draft February 28, 2022 23:02
oscargus marked this pull request as ready for review March 2, 2022 12:56
Comment thread lib/matplotlib/image.py
# 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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

timhoffm Mar 2, 2022 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

_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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 merged commit 2bb9b03 into matplotlib:main Mar 3, 2022
oscargus deleted the simplifyimports branch March 3, 2022 00:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL