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

Skip to content

Commit cd5e846

Browse files
authored
Merge pull request #18028 from QuLogic/super1
MNT: Super-ify parts of the code base, part 1
2 parents 440ddef + d10e486 commit cd5e846

File tree

21 files changed

+106
-120
lines changed

21 files changed

+106
-120
lines changed

examples/misc/custom_projection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _init_axis(self):
5353
self._update_transScale()
5454

5555
def cla(self):
56-
Axes.cla(self)
56+
super().cla()
5757

5858
self.set_longitude_grid(30)
5959
self.set_latitude_grid(15)
@@ -426,7 +426,7 @@ def inverted(self):
426426

427427
def __init__(self, *args, **kwargs):
428428
self._longitude_cap = np.pi / 2.0
429-
GeoAxes.__init__(self, *args, **kwargs)
429+
super().__init__(*args, **kwargs)
430430
self.set_aspect(0.5, adjustable='box', anchor='C')
431431
self.cla()
432432

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def __init__(self, fig, rect,
476476
The new `~.axes.Axes` object.
477477
"""
478478

479-
martist.Artist.__init__(self)
479+
super().__init__()
480480
if isinstance(rect, mtransforms.Bbox):
481481
self._position = rect
482482
else:
@@ -625,7 +625,7 @@ def _init_axis(self):
625625

626626
def set_figure(self, fig):
627627
# docstring inherited
628-
martist.Artist.set_figure(self, fig)
628+
super().set_figure(fig)
629629

630630
self.bbox = mtransforms.TransformedBbox(self._position,
631631
fig.transFigure)

lib/matplotlib/axis.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(self, axes, loc, label=None,
8282
loc is the tick location in data coords
8383
size is the tick size in points
8484
"""
85-
martist.Artist.__init__(self)
85+
super().__init__()
8686

8787
if gridOn is None:
8888
if major and (mpl.rcParams['axes.grid.which']
@@ -231,7 +231,7 @@ def get_children(self):
231231

232232
def set_clip_path(self, clippath, transform=None):
233233
# docstring inherited
234-
martist.Artist.set_clip_path(self, clippath, transform)
234+
super().set_clip_path(clippath, transform)
235235
self.gridline.set_clip_path(clippath, transform)
236236
self.stale = True
237237

@@ -675,7 +675,7 @@ def __init__(self, axes, pickradius=15):
675675
The acceptance radius for containment tests. See also
676676
`.Axis.contains`.
677677
"""
678-
martist.Artist.__init__(self)
678+
super().__init__()
679679
self._remove_overlapping_locs = True
680680

681681
self.set_figure(axes.figure)
@@ -901,7 +901,7 @@ def _translate_tick_kw(kw):
901901
return kwtrans
902902

903903
def set_clip_path(self, clippath, transform=None):
904-
martist.Artist.set_clip_path(self, clippath, transform)
904+
super().set_clip_path(clippath, transform)
905905
for child in self.majorTicks + self.minorTicks:
906906
child.set_clip_path(clippath, transform)
907907
self.stale = True

lib/matplotlib/backend_bases.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ class DrawEvent(Event):
12501250
The renderer for the draw event.
12511251
"""
12521252
def __init__(self, name, canvas, renderer):
1253-
Event.__init__(self, name, canvas)
1253+
super().__init__(name, canvas)
12541254
self.renderer = renderer
12551255

12561256

@@ -1269,7 +1269,7 @@ class ResizeEvent(Event):
12691269
Height of the canvas in pixels.
12701270
"""
12711271
def __init__(self, name, canvas):
1272-
Event.__init__(self, name, canvas)
1272+
super().__init__(name, canvas)
12731273
self.width, self.height = canvas.get_width_height()
12741274

12751275

@@ -1307,7 +1307,7 @@ def __init__(self, name, canvas, x, y, guiEvent=None):
13071307
"""
13081308
(*x*, *y*) in figure coords ((0, 0) = bottom left).
13091309
"""
1310-
Event.__init__(self, name, canvas, guiEvent=guiEvent)
1310+
super().__init__(name, canvas, guiEvent=guiEvent)
13111311
# x position - pixels from left of canvas
13121312
self.x = int(x) if x is not None else x
13131313
# y position - pixels from right of canvas
@@ -1439,7 +1439,7 @@ def __init__(self, name, canvas, x, y, button=None, key=None,
14391439

14401440
# super-init is deferred to the end because it calls back on
14411441
# 'axes_enter_event', which requires a fully initialized event.
1442-
LocationEvent.__init__(self, name, canvas, x, y, guiEvent=guiEvent)
1442+
super().__init__(name, canvas, x, y, guiEvent=guiEvent)
14431443

14441444
def __str__(self):
14451445
return (f"{self.name}: "
@@ -1483,7 +1483,7 @@ def on_pick(event):
14831483
"""
14841484
def __init__(self, name, canvas, mouseevent, artist,
14851485
guiEvent=None, **kwargs):
1486-
Event.__init__(self, name, canvas, guiEvent)
1486+
super().__init__(name, canvas, guiEvent)
14871487
self.mouseevent = mouseevent
14881488
self.artist = artist
14891489
self.__dict__.update(kwargs)
@@ -1526,7 +1526,7 @@ def on_key(event):
15261526
def __init__(self, name, canvas, key, x=0, y=0, guiEvent=None):
15271527
self.key = key
15281528
# super-init deferred to the end: callback errors if called before
1529-
LocationEvent.__init__(self, name, canvas, x, y, guiEvent=guiEvent)
1529+
super().__init__(name, canvas, x, y, guiEvent=guiEvent)
15301530

15311531

15321532
def _get_renderer(figure, print_method=None):

lib/matplotlib/backend_managers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, name, sender, tool, data=None):
2020
class ToolTriggerEvent(ToolEvent):
2121
"""Event to inform that a tool has been triggered."""
2222
def __init__(self, name, sender, tool, canvasevent=None, data=None):
23-
ToolEvent.__init__(self, name, sender, tool, data)
23+
super().__init__(name, sender, tool, data)
2424
self.canvasevent = canvasevent
2525

2626

lib/matplotlib/collections.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ def set_sizes(self, sizes, dpi=72.0):
930930
@artist.allow_rasterization
931931
def draw(self, renderer):
932932
self.set_sizes(self._sizes, self.figure.dpi)
933-
Collection.draw(self, renderer)
933+
super().draw(renderer)
934934

935935

936936
class PathCollection(_CollectionWithSizes):
@@ -1122,7 +1122,7 @@ def __init__(self, verts, sizes=None, closed=True, **kwargs):
11221122
**kwargs
11231123
Forwarded to `.Collection`.
11241124
"""
1125-
Collection.__init__(self, **kwargs)
1125+
super().__init__(**kwargs)
11261126
self.set_sizes(sizes)
11271127
self.set_verts(verts, closed)
11281128
self.stale = True
@@ -1212,7 +1212,7 @@ def __init__(self, xranges, yrange, **kwargs):
12121212
(xmin + xwidth, ymax),
12131213
(xmin + xwidth, ymin),
12141214
(xmin, ymin)] for xmin, xwidth in xranges]
1215-
PolyCollection.__init__(self, verts, **kwargs)
1215+
super().__init__(verts, **kwargs)
12161216

12171217
@classmethod
12181218
def span_where(cls, x, ymin, ymax, where, **kwargs):
@@ -1272,7 +1272,7 @@ def __init__(self,
12721272
transOffset=ax.transData,
12731273
)
12741274
"""
1275-
Collection.__init__(self, **kwargs)
1275+
super().__init__(**kwargs)
12761276
self.set_sizes(sizes)
12771277
self._numsides = numsides
12781278
self._paths = [self._path_generator(numsides)]
@@ -1292,6 +1292,8 @@ def draw(self, renderer):
12921292
transforms.Affine2D(x).rotate(-self._rotation).get_matrix()
12931293
for x in self._transforms
12941294
]
1295+
# Explicitly not super().draw, because set_sizes must be called before
1296+
# updating self._transforms.
12951297
Collection.draw(self, renderer)
12961298

12971299

@@ -1378,8 +1380,7 @@ def __init__(self, segments, # Can be None.
13781380
antialiaseds = (mpl.rcParams['lines.antialiased'],)
13791381

13801382
colors = mcolors.to_rgba_array(colors)
1381-
Collection.__init__(
1382-
self,
1383+
super().__init__(
13831384
edgecolors=colors,
13841385
facecolors=facecolors,
13851386
linewidths=linewidths,
@@ -1520,13 +1521,10 @@ def __init__(self,
15201521
--------
15211522
.. plot:: gallery/lines_bars_and_markers/eventcollection_demo.py
15221523
"""
1523-
LineCollection.__init__(self,
1524-
[],
1525-
linewidths=linewidth,
1526-
colors=color,
1527-
antialiaseds=antialiased,
1528-
linestyles=linestyle,
1529-
**kwargs)
1524+
super().__init__([],
1525+
linewidths=linewidth, linestyles=linestyle,
1526+
colors=color, antialiaseds=antialiased,
1527+
**kwargs)
15301528
self._is_horizontal = True # Initial value, may be switched below.
15311529
self._linelength = linelength
15321530
self._lineoffset = lineoffset
@@ -1677,7 +1675,7 @@ def __init__(self, sizes, **kwargs):
16771675
**kwargs
16781676
Forwarded to `.Collection`.
16791677
"""
1680-
Collection.__init__(self, **kwargs)
1678+
super().__init__(**kwargs)
16811679
self.set_sizes(sizes)
16821680
self.set_transform(transforms.IdentityTransform())
16831681
self._paths = [mpath.Path.unit_circle()]
@@ -1711,7 +1709,7 @@ def __init__(self, widths, heights, angles, units='points', **kwargs):
17111709
**kwargs
17121710
Forwarded to `Collection`.
17131711
"""
1714-
Collection.__init__(self, **kwargs)
1712+
super().__init__(**kwargs)
17151713
self._widths = 0.5 * np.asarray(widths).ravel()
17161714
self._heights = 0.5 * np.asarray(heights).ravel()
17171715
self._angles = np.deg2rad(angles).ravel()
@@ -1765,7 +1763,7 @@ def _set_transforms(self):
17651763
@artist.allow_rasterization
17661764
def draw(self, renderer):
17671765
self._set_transforms()
1768-
Collection.draw(self, renderer)
1766+
super().draw(renderer)
17691767

17701768

17711769
class PatchCollection(Collection):
@@ -1813,7 +1811,7 @@ def determine_facecolor(patch):
18131811
kwargs['linestyles'] = [p.get_linestyle() for p in patches]
18141812
kwargs['antialiaseds'] = [p.get_antialiased() for p in patches]
18151813

1816-
Collection.__init__(self, **kwargs)
1814+
super().__init__(**kwargs)
18171815

18181816
self.set_paths(patches)
18191817

@@ -1830,7 +1828,7 @@ class TriMesh(Collection):
18301828
A triangular mesh is a `~matplotlib.tri.Triangulation` object.
18311829
"""
18321830
def __init__(self, triangulation, **kwargs):
1833-
Collection.__init__(self, **kwargs)
1831+
super().__init__(**kwargs)
18341832
self._triangulation = triangulation
18351833
self._shading = 'gouraud'
18361834
self._is_filled = True
@@ -1918,7 +1916,7 @@ class QuadMesh(Collection):
19181916
"""
19191917
def __init__(self, meshWidth, meshHeight, coordinates,
19201918
antialiased=True, shading='flat', **kwargs):
1921-
Collection.__init__(self, **kwargs)
1919+
super().__init__(**kwargs)
19221920
self._meshWidth = meshWidth
19231921
self._meshHeight = meshHeight
19241922
# By converting to floats now, we can avoid that on every draw.

lib/matplotlib/container.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class BarContainer(Container):
6565
def __init__(self, patches, errorbar=None, **kwargs):
6666
self.patches = patches
6767
self.errorbar = errorbar
68-
Container.__init__(self, patches, **kwargs)
68+
super().__init__(patches, **kwargs)
6969

7070

7171
class ErrorbarContainer(Container):
@@ -97,7 +97,7 @@ def __init__(self, lines, has_xerr=False, has_yerr=False, **kwargs):
9797
self.lines = lines
9898
self.has_xerr = has_xerr
9999
self.has_yerr = has_yerr
100-
Container.__init__(self, lines, **kwargs)
100+
super().__init__(lines, **kwargs)
101101

102102

103103
class StemContainer(Container):
@@ -132,4 +132,4 @@ def __init__(self, markerline_stemlines_baseline, **kwargs):
132132
self.markerline = markerline
133133
self.stemlines = stemlines
134134
self.baseline = baseline
135-
Container.__init__(self, markerline_stemlines_baseline, **kwargs)
135+
super().__init__(markerline_stemlines_baseline, **kwargs)

lib/matplotlib/legend.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ def __init__(self, legend, use_blit=False, update="loc"):
6868
cbook._check_in_list(["loc", "bbox"], update=update)
6969
self._update = update
7070

71-
DraggableOffsetBox.__init__(self, legend, legend._legend_box,
72-
use_blit=use_blit)
71+
super().__init__(legend, legend._legend_box, use_blit=use_blit)
7372

7473
def finalize_offset(self):
7574
if self._update == "loc":

lib/matplotlib/offsetbox.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def set_figure(self, fig):
205205
----------
206206
fig : `~matplotlib.figure.Figure`
207207
"""
208-
martist.Artist.set_figure(self, fig)
208+
super().set_figure(fig)
209209
for c in self.get_children():
210210
c.set_figure(fig)
211211

@@ -800,7 +800,7 @@ def __init__(self, s,
800800
textprops = {}
801801
textprops.setdefault("va", "baseline")
802802
self._text = mtext.Text(0, 0, s, **textprops)
803-
OffsetBox.__init__(self)
803+
super().__init__()
804804
self._children = [self._text]
805805
self.offset_transform = mtransforms.Affine2D()
806806
self._baseline_transform = mtransforms.Affine2D()
@@ -931,7 +931,7 @@ class AuxTransformBox(OffsetBox):
931931
"""
932932
def __init__(self, aux_transform):
933933
self.aux_transform = aux_transform
934-
OffsetBox.__init__(self)
934+
super().__init__()
935935
self.offset_transform = mtransforms.Affine2D()
936936
# ref_offset_transform makes offset_transform always relative to the
937937
# lower-left corner of the bbox of its children.
@@ -1315,7 +1315,7 @@ def __init__(self, arr,
13151315
**kwargs
13161316
):
13171317

1318-
OffsetBox.__init__(self)
1318+
super().__init__()
13191319
self._dpi_cor = dpi_cor
13201320

13211321
self.image = BboxImage(bbox=self.get_window_extent,
@@ -1782,7 +1782,7 @@ def finalize_offset(self):
17821782

17831783
class DraggableOffsetBox(DraggableBase):
17841784
def __init__(self, ref_artist, offsetbox, use_blit=False):
1785-
DraggableBase.__init__(self, ref_artist, use_blit=use_blit)
1785+
super().__init__(ref_artist, use_blit=use_blit)
17861786
self.offsetbox = offsetbox
17871787

17881788
def save_offset(self):
@@ -1808,7 +1808,7 @@ def get_loc_in_canvas(self):
18081808

18091809
class DraggableAnnotation(DraggableBase):
18101810
def __init__(self, annotation, use_blit=False):
1811-
DraggableBase.__init__(self, annotation, use_blit=use_blit)
1811+
super().__init__(annotation, use_blit=use_blit)
18121812
self.annotation = annotation
18131813

18141814
def save_offset(self):

0 commit comments

Comments
 (0)