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

Skip to content

Deprecate incorrect import locations #23565

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

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions doc/api/next_api_changes/deprecations/23565-OG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Alternative import location for ``TextPath`` and ``AxislineStyle``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

These two classes have historically sometimes been imported from incorrect
locations. This is now deprecated and `.TextPath` should be imported from
Copy link
Member

@timhoffm timhoffm Aug 6, 2022

Choose a reason for hiding this comment

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

I'm not sure we should do this. If we deprecate we break a lot of user code eventually.

https://github.com/search?q=%22from+matplotlib.textpath+import+TextPath%22&type=code
textpath -> 825 hits

https://github.com/search?q=%22from+matplotlib.text+import+TextPath%22&type=code
text -> 1783 hits

Could do a pending deprecation.

I also don't know which way I would deprecate. Sure, TextPath is in TextPath (alongside with TextToPath). But is it really necessary to have that many modules as API surface. I can see an argument that these are text-like enough to be accessed via the text module. - Which would long-term mean making textpath private, or moving the contents to text directly.

There's also the alternative to just not bother if we have no clearly better solution.

Copy link
Contributor

@anntzer anntzer Aug 6, 2022

Choose a reason for hiding this comment

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

Agreed that if we really want to pick one module (which is not clear), I'd rather make text the "official" one.
Perhaps the same argument applies to axisline_style, in fact...

Copy link
Member Author

Choose a reason for hiding this comment

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

OK! But then maybe we should at least make sure that TextPath is documented as being in text and not in textpath? https://matplotlib.org/devdocs/api/textpath_api.html

Copy link
Member Author

Choose a reason for hiding this comment

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

textpath was made its own module in 2009. Although it doesn't really mean that it was fullt used for its purposes.

Copy link
Member Author

Choose a reason for hiding this comment

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

See #23576 for the textpath module.

Copy link
Member Author

Choose a reason for hiding this comment

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

As a preparation for the dev call:

textpath 25 hits (5 matplotlib, 8 Visualization book)
https://grep.app/search?q=from%20matplotlib.textpath%20import%20TextPath

text 13 hits (3 matplotlib, 3 matplotlib-cn, 4 Visualization book)
https://grep.app/search?q=from%20matplotlib.text%20import%20TextPath

`matplotlib.textpath`, while `AxislineStyle` should be imported from
`mpl_toolkit.axisartist.axisline_style`.
8 changes: 7 additions & 1 deletion lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@
from .artist import Artist
from .font_manager import FontProperties
from .patches import FancyArrowPatch, FancyBboxPatch, Rectangle
from .textpath import TextPath # Unused, but imported by others.
from .textpath import TextPath as _TextPath # Unused, but imported by others.
from .transforms import (
Affine2D, Bbox, BboxBase, BboxTransformTo, IdentityTransform, Transform)


_log = logging.getLogger(__name__)


@_api.deprecated("3.6", message="Since %(since)s, %(name)s should be imported "
"from its correct module: matplotlib.textpath")
class TextPath(_TextPath):
pass


@_api.deprecated("3.6")
def get_rotation(rotation):
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/axes_grid1/anchored_artists.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DrawingArea, TextArea, VPacker)
from matplotlib.patches import (Rectangle, Ellipse, ArrowStyle,
FancyArrowPatch, PathPatch)
from matplotlib.text import TextPath
from matplotlib.textpath import TextPath

__all__ = ['AnchoredDrawingArea', 'AnchoredAuxTransformBox',
'AnchoredEllipse', 'AnchoredSizeBar', 'AnchoredDirectionArrows']
Expand Down
9 changes: 8 additions & 1 deletion lib/mpl_toolkits/axisartist/axislines.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@
import matplotlib.axes as maxes
from matplotlib.path import Path
from mpl_toolkits.axes_grid1 import mpl_axes
from .axisline_style import AxislineStyle
from .axisline_style import AxislineStyle as _AxislineStyle
from .axis_artist import AxisArtist, GridlinesCollection


@_api.deprecated("3.6", message="Since %(since)s, %(name)s should be imported "
"from its correct module: "
"mpl_toolkits.axisartist.axisline_style")
class AxislineStyle(_AxislineStyle):
pass


class AxisArtistHelper:
"""
AxisArtistHelper should define
Expand Down