Skip to content

Commit 05df015

Browse files
authored
Merge pull request #27768 from rcomer/draw-args-kwargs
MNT: deprecate draw method args and kwargs
2 parents 33b9b27 + f763aae commit 05df015

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``[XYZ]Axis.draw``, ``*Image.draw`` *args* and *kwargs*...
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
... are deprecated because they have no effect. This will make the calling sequence
5+
consistent with the ``draw`` method of other artists.

galleries/examples/misc/demo_ribbon_box.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ def __init__(self, ax, bbox, color, *, extent=(0, 1, 0, 1), **kwargs):
4949
self._ribbonbox = RibbonBox(color)
5050
self.set_transform(BboxTransformTo(bbox))
5151

52-
def draw(self, renderer, *args, **kwargs):
52+
def draw(self, renderer):
5353
stretch_factor = self._bbox.height / self._bbox.width
5454

5555
ny = int(stretch_factor*self._ribbonbox.nx)
5656
if self.get_array() is None or self.get_array().shape[0] != ny:
5757
arr = self._ribbonbox.get_stretched_image(stretch_factor)
5858
self.set_array(arr)
5959

60-
super().draw(renderer, *args, **kwargs)
60+
super().draw(renderer)
6161

6262

6363
def main():

lib/matplotlib/axis.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,8 @@ def get_tick_padding(self):
13731373
values.append(self.minorTicks[0].get_tick_padding())
13741374
return max(values, default=0)
13751375

1376+
@_api.delete_parameter('3.9', 'args')
1377+
@_api.delete_parameter('3.9', 'kwargs')
13761378
@martist.allow_rasterization
13771379
def draw(self, renderer, *args, **kwargs):
13781380
# docstring inherited

lib/matplotlib/image.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ def _check_unsampled_image(self):
626626
"""
627627
return False
628628

629+
@_api.delete_parameter('3.9', 'args')
630+
@_api.delete_parameter('3.9', 'kwargs')
629631
@martist.allow_rasterization
630632
def draw(self, renderer, *args, **kwargs):
631633
# if not visible, declare victory and return

tools/stubtest.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,33 @@ def __init__(self, filepath, output):
1818
self.output = output
1919

2020
def visit_FunctionDef(self, node):
21-
if any("delete_parameter" in ast.unparse(line) for line in node.decorator_list):
22-
parents = []
23-
if hasattr(node, "parent"):
24-
parent = node.parent
25-
while hasattr(parent, "parent") and not isinstance(parent, ast.Module):
26-
parents.insert(0, parent.name)
27-
parent = parent.parent
28-
self.output.write(f"{'.'.join(self.context + parents)}.{node.name}\n")
21+
# delete_parameter adds a private sentinel value that leaks
22+
# we do not want that sentinel value in the type hints but it breaks typing
23+
# Does not apply to variadic arguments (args/kwargs)
24+
for dec in node.decorator_list:
25+
if "delete_parameter" in ast.unparse(dec):
26+
deprecated_arg = dec.args[1].value
27+
if (
28+
node.args.vararg is not None
29+
and node.args.vararg.arg == deprecated_arg
30+
):
31+
continue
32+
if (
33+
node.args.kwarg is not None
34+
and node.args.kwarg.arg == deprecated_arg
35+
):
36+
continue
37+
38+
parents = []
39+
if hasattr(node, "parent"):
40+
parent = node.parent
41+
while hasattr(parent, "parent") and not isinstance(
42+
parent, ast.Module
43+
):
44+
parents.insert(0, parent.name)
45+
parent = parent.parent
46+
self.output.write(f"{'.'.join(self.context + parents)}.{node.name}\n")
47+
break
2948

3049
def visit_ClassDef(self, node):
3150
for dec in node.decorator_list:

0 commit comments

Comments
 (0)