8000 Merge pull request #21765 from meeseeksmachine/auto-backport-of-pr-21… · matplotlib/matplotlib@65ace07 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 65ace07

Browse files
authored
Merge pull request #21765 from meeseeksmachine/auto-backport-of-pr-21741-on-v3.5.x
Backport PR #21741 on branch v3.5.x (Reduce do_3d_projection deprecation warnings in external artists)
2 parents 647c000 + f78e873 commit 65ace07

File tree

2 files changed

+79
-15
lines changed

2 files changed

+79
-15
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from collections import defaultdict
1414
import functools
15+
import inspect
1516
import itertools
1617
import math
1718
from numbers import Integral
@@ -417,24 +418,27 @@ def do_3d_projection(artist):
417418
Call `do_3d_projection` on an *artist*, and warn if passing
418419
*renderer*.
419420
420-
For our Artists, never pass *renderer*. For external Artists,
421-
in lieu of more complicated signature parsing, always pass
422-
*renderer* and raise a warning.
421+
Attempt to bind the empty signature first, so external Artists
422+
can avoid the deprecation warning if they support the new
423+
calling convention.
423424
"""
424-
425-
if artist.__module__ == 'mpl_toolkits.mplot3d.art3d':
426-
# Our 3D Artists have deprecated the renderer parameter, so
427-
# avoid passing it to them; call this directly once the
428-
# deprecation has expired.
425+
try:
426+
signature = inspect.signature(artist.do_3d_projection)
427+
signature.bind()
428+
# ValueError if `inspect.signature` cannot provide a signature
429+
# and TypeError if the binding fails or the object does not
430+
# appear to be callable - the next call will then re-raise.
431+
except (ValueError, TypeError):
432+
_api.warn_deprecated(
433+
"3.4",
434+
message="The 'renderer' parameter of "
435+
"do_3d_projection() was deprecated in Matplotlib "
436+
"%(since)s and will be removed %(removal)s.")
437+
return artist.do_3d_projection(renderer)
438+
else:
439+
# Call this directly once the deprecation period expires.
429440
return artist.do_3d_projection()
430441

431-
_api.warn_deprecated(
432-
"3.4",
433-
message="The 'renderer' parameter of "
434-
"do_3d_projection() was deprecated in Matplotlib "
435-
"%(since)s and will be removed %(removal)s.")
436-
return artist.do_3d_projection(renderer)
437-
438442
collections_and_patches = (
439443
artist for artist in self._children
440444
if isinstance(artist, (mcoll.Collection, mpatches.Patch)))

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,3 +1711,63 @@ def test_view_init_vertical_axis(
17111711
tickdir_expected = tickdirs_expected[i]
17121712
tickdir_actual = axis._get_tickdir()
17131713
np.testing.assert_array_equal(tickdir_expected, tickdir_actual)
1714+
1715+
1716+
def test_do_3d_projection_renderer_deprecation_warn_on_argument():
1717+
"""
1718+
Test that an external artist with an old-style calling convention raises
1719+
a suitable deprecation warning.
1720+
"""
1721+
class DummyPatch(art3d.Patch3D):
1722+
def do_3d_projection(self, renderer):
1723+
return 0
1724+
1725+
def draw(self, renderer):
1726+
pass
1727+
1728+
fig = plt.figure()
1729+
ax = fig.add_subplot(111, projection='3d')
1730+
artist = DummyPatch()
1731+
ax.add_artist(artist)
1732+
1733+
match = r"The 'renderer' parameter of do_3d_projection\(\) was deprecated"
1734+
with pytest.warns(MatplotlibDeprecationWarning, match=match):
1735+
fig.canvas.draw()
1736+
1737+
1738+
def test_do_3d_projection_renderer_deprecation_nowarn_on_optional_argument():
1739+
"""
1740+
Test that an external artist with a calling convention compatible with
1741+
both v3.3 and v3.4 does not raise a deprecation warning.
1742+
"""
1743+
class DummyPatch(art3d.Patch3D):
1744+
def do_3d_projection(self, renderer=None):
1745+
return 0
1746+
1747+
def draw(self, renderer):
1748+
pass
1749+
1750+
fig = plt.figure()
1751+
ax = fig.add_subplot(111, projection='3d')
1752+
artist = DummyPatch()
1753+
ax.add_artist(artist)
1754+
fig.canvas.draw()
1755+
1756+
1757+
def test_do_3d_projection_renderer_deprecation_nowarn_on_no_argument():
1758+
"""
1759+
Test that an external artist with a calling convention compatible with
1760+
only v3.4 does not raise a deprecation warning.
1761+
"""
1762+
class DummyPatch(art3d.Patch3D):
1763+
def do_3d_projection(self):
1764+
return 0
1765+
1766+
def draw(self, renderer):
1767+
pass
1768+
1769+
fig = plt.figure()
1770+
ax = fig.add_subplot(111, projection='3d')
1771+
artist = DummyPatch()
1772+
ax.add_artist(artist)
1773+
fig.canvas.draw()

0 commit comments

Comments
 (0)
0