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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import numpy as np

import matplotlib as mpl
from matplotlib import _api
from matplotlib import _api, cbook
import matplotlib.artist as martist
import matplotlib.cbook as cbook
import matplotlib.colors as mcolors
import matplotlib.lines as mlines
import matplotlib.scale as mscale
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/container.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from matplotlib import cbook
from matplotlib.artist import Artist
import matplotlib.cbook as cbook


class Container(tuple):
Expand Down
14 changes: 6 additions & 8 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
import PIL.PngImagePlugin

import matplotlib as mpl
from matplotlib import _api
from matplotlib import _api, cbook, cm
# 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.

from matplotlib._image import *
import matplotlib.artist as martist
from matplotlib.backend_bases import FigureCanvasBase
import matplotlib.colors as mcolors
import matplotlib.cm as cm
import matplotlib.cbook as cbook
# For clarity, names from _image are given explicitly in this module:
import matplotlib._image as _image
# For user convenience, the names from _image are also imported into
# the image namespace:
from matplotlib._image import *
from matplotlib.transforms import (
Affine2D, BboxBase, Bbox, BboxTransform, BboxTransformTo,
IdentityTransform, TransformedBbox)
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import numpy as np

import matplotlib
from matplotlib import _api, cm
from matplotlib import _api, cm, patches
import matplotlib.colors as mcolors
import matplotlib.collections as mcollections
import matplotlib.lines as mlines
import matplotlib.patches as patches


__all__ = ['streamplot']
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/testing/jpl_units/EpochConverter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""EpochConverter module containing class EpochConverter."""

from matplotlib import cbook
import matplotlib.units as units
from matplotlib import cbook, units
import matplotlib.dates as date_ticker

__all__ = ['EpochConverter']
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/testing/jpl_units/UnitDblConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import numpy as np

from matplotlib import cbook
import matplotlib.units as units
from matplotlib import cbook, units
import matplotlib.projections.polar as polar

__all__ = ['UnitDblConverter']
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/tests/test_backend_bases.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import re

from matplotlib import path, transforms
from matplotlib.testing import _check_for_pgf
from matplotlib.backend_bases import (
FigureCanvasBase, LocationEvent, MouseButton, MouseEvent,
NavigationToolbar2, RendererBase)
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
import matplotlib.transforms as transforms
import matplotlib.path as path

import numpy as np
import pytest
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
assert_array_almost_equal)
import pytest

from matplotlib import _api
import matplotlib.cbook as cbook
from matplotlib import _api, cbook
import matplotlib.colors as mcolors
from matplotlib.cbook import delete_masked_points

Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/tests/test_constrainedlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

from matplotlib.testing.decorators import image_comparison
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import matplotlib.transforms as mtransforms
from matplotlib import ticker, rcParams
from matplotlib import gridspec, ticker, rcParams


def example_plot(ax, fontsize=12, nodec=False):
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
import numpy as np
import pytest

from matplotlib import rc_context, style
from matplotlib import _api, rc_context, style
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
from matplotlib.testing.decorators import image_comparison
import matplotlib.ticker as mticker
import matplotlib._api as _api


def test_date_numpyx():
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from PIL import Image

import matplotlib as mpl
from matplotlib import rcParams
from matplotlib import gridspec, rcParams
from matplotlib._api.deprecation import MatplotlibDeprecationWarning
from matplotlib.testing.decorators import image_comparison, check_figures_equal
from matplotlib.axes import Axes
Expand All @@ -22,7 +22,6 @@
from matplotlib.ticker import AutoMinorLocator, FixedFormatter, ScalarFormatter
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.gridspec as gridspec


@image_comparison(['figure_align_labels'], extensions=['png', 'svg'],
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/tests/test_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import pytest

from matplotlib.testing.decorators import image_comparison
from matplotlib import pyplot as plt
import matplotlib.cm as cm
from matplotlib import cm, pyplot as plt


@image_comparison(['pngsuite.png'], tol=0.03)
Expand Down