Skip to content

Commit fc34d69

Browse files
committed
Rework deprecation mechanism.
1 parent 0b282e8 commit fc34d69

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/matplotlib/cbook/deprecation.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ def _deprecate_method_override(method, obj, *, allow_empty=False, **kwargs):
465465
can always use ``__class__`` to refer to the class that is currently
466466
being defined.
467467
obj
468-
An object of the class where *method* is defined.
468+
Either an object of the class where *method* is defined, or a subclass
469+
of that class.
469470
allow_empty : bool, default: False
470471
Whether to allow overrides by "empty" methods without emitting a
471472
warning.
@@ -478,15 +479,19 @@ def empty(): pass
478479
def empty_with_docstring(): """doc"""
479480

480481
name = method.__name__
481-
bound_method = getattr(obj, name)
482-
if (bound_method != method.__get__(obj)
482+
bound_child = getattr(obj, name)
483+
bound_base = (
484+
method # If obj is a class, then we need to use unbound methods.
485+
if isinstance(bound_child, type(empty)) and isinstance(obj, type)
486+
else method.__get__(obj))
487+
if (bound_child != bound_base
483488
and (not allow_empty
484-
or (getattr(getattr(bound_method, "__code__", None),
489+
or (getattr(getattr(bound_child, "__code__", None),
485490
"co_code", None)
486491
not in [empty.__code__.co_code,
487492
empty_with_docstring.__code__.co_code]))):
488493
warn_deprecated(**{"name": name, "obj_type": "method", **kwargs})
489-
return bound_method
494+
return bound_child
490495
return None
491496

492497

lib/matplotlib/patches.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,10 @@ def transmute(self, x0, y0, width, height, mutation_size):
19551955
# This can go away once the deprecation period elapses, leaving _Base
19561956
# as a fully abstract base class just providing docstrings, no logic.
19571957
def __init_subclass__(cls):
1958-
if not cls.__module__ == "matplotlib.patches":
1958+
transmute = cbook._deprecate_method_override(
1959+
__class__.transmute, cls, since="3.4")
1960+
if transmute:
1961+
cls.__call__ = transmute
19591962
return
19601963

19611964
__call__ = cls.__call__

0 commit comments

Comments
 (0)