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

Skip to content

Commit 8305079

Browse files
committed
Reduce do_3d_projection deprecation warnings
Previously, when finding the 3D zorder, external artists were assumed to use the calling convention of `Patch3D.do_3d_projection` from Matplotlib 3.3, where it took a positional `renderer` parameter. This triggered a deprecation warning, even if the artist could support the new convention. Now we attempt to bind the signature first, and only emit a deprecation warning if the calling convention does not appear to work.
1 parent 73304d2 commit 8305079

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-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
@@ -412,24 +413,27 @@ def do_3d_projection(artist):
412413
Call `do_3d_projection` on an *artist*, and warn if passing
413414
*renderer*.
414415
415-
For our Artists, never pass *renderer*. For external Artists,
416-
in lieu of more complicated signature parsing, always pass
417-
*renderer* and raise a warning.
416+
Attempt to bind the empty signature first, so external Artists
417+
can avoid the deprecation warning if they support the new
418+
calling convention.
418419
"""
419-
420-
if artist.__module__ == 'mpl_toolkits.mplot3d.art3d':
421-
# Our 3D Artists have deprecated the renderer parameter, so
422-
# avoid passing it to them; call this directly once the
423-
# deprecation has expired.
420+
try:
421+
signature = inspect.signature(artist.do_3d_projection)
422+
signature.bind()
423+
# ValueError if `inspect.signature` cannot provide a signature
424+
# and TypeError if the binding fails or the object does not
425+
# appear to be callable - the next call will then re-raise.
426+
except (ValueError, TypeError):
427+
_api.warn_deprecated(
428+
"3.4",
429+
message="The 'renderer' parameter of "
430+
"do_3d_projection() was deprecated in Matplotlib "
431+
"%(since)s and will be removed %(removal)s.")
432+
return artist.do_3d_projection(renderer)
433+
else:
434+
# Call this directly once the deprecation period expires.
424435
return artist.do_3d_projection()
425436

426-
_api.warn_deprecated(
427-
"3.4",
428-
message="The 'renderer' parameter of "
429-
"do_3d_projection() was deprecated in Matplotlib "
430-
"%(since)s and will be removed %(removal)s.")
431-
return artist.do_3d_projection(renderer)
432-
433437
collections_and_patches = (
434438
artist for artist in self._children
435439
if isinstance(artist, (mcoll.Collection, mpatches.Patch))

0 commit comments

Comments
 (0)