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

Skip to content

Commit cb0654d

Browse files
authored
Merge pull request #18044 from QuLogic/super3
Super-ify parts of the code base, part 3
2 parents d8ed5f6 + 730c5a7 commit cb0654d

17 files changed

Lines changed: 109 additions & 119 deletions

File tree

examples/units/basic_units.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __call__(self, *args):
4343

4444
class ConvertArgsProxy(PassThroughProxy):
4545
def __init__(self, fn_name, obj):
46-
PassThroughProxy.__init__(self, fn_name, obj)
46+
super().__init__(fn_name, obj)
4747
self.unit = obj.unit
4848

4949
def __call__(self, *args):
@@ -54,23 +54,23 @@ def __call__(self, *args):
5454
except AttributeError:
5555
converted_args.append(TaggedValue(a, self.unit))
5656
converted_args = tuple([c.get_value() for c in converted_args])
57-
return PassThroughProxy.__call__(self, *converted_args)
57+
return super().__call__(*converted_args)
5858

5959

6060
class ConvertReturnProxy(PassThroughProxy):
6161
def __init__(self, fn_name, obj):
62-
PassThroughProxy.__init__(self, fn_name, obj)
62+
super().__init__(fn_name, obj)
6363
self.unit = obj.unit
6464

6565
def __call__(self, *args):
66-
ret = PassThroughProxy.__call__(self, *args)
66+
ret = super().__call__(*args)
6767
return (NotImplemented if ret is NotImplemented
6868
else TaggedValue(ret, self.unit))
6969

7070

7171
class ConvertAllProxy(PassThroughProxy):
7272
def __init__(self, fn_name, obj):
73-
PassThroughProxy.__init__(self, fn_name, obj)
73+
super().__init__(fn_name, obj)
7474
self.unit = obj.unit
7575

7676
def __call__(self, *args):
@@ -96,7 +96,7 @@ def __call__(self, *args):
9696
else:
9797
arg_units.append(None)
9898
converted_args = tuple(converted_args)
99-
ret = PassThroughProxy.__call__(self, *converted_args)
99+
ret = super().__call__(*converted_args)
100100
if ret is NotImplemented:
101101
return NotImplemented
102102
ret_unit = unit_resolver(self.fn_name, arg_units)

examples/widgets/menu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MenuItem(artist.Artist):
3232

3333
def __init__(self, fig, labelstr, props=None, hoverprops=None,
3434
on_select=None):
35-
artist.Artist.__init__(self)
35+
super().__init__()
3636

3737
self.set_figure(fig)
3838
self.labelstr = labelstr

lib/matplotlib/animation.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ class FileMovieWriter(MovieWriter):
394394
This must be sub-classed to be useful.
395395
"""
396396
def __init__(self, *args, **kwargs):
397-
MovieWriter.__init__(self, *args, **kwargs)
397+
super().__init__(*args, **kwargs)
398398
self.frame_format = mpl.rcParams['animation.frame_format']
399399

400400
@cbook._delete_parameter("3.3", "clear_temp")
@@ -498,10 +498,10 @@ def finish(self):
498498
# Call run here now that all frame grabbing is done. All temp files
499499
# are available to be assembled.
500500
self._run()
501-
MovieWriter.finish(self) # Will call clean-up
501+
super().finish() # Will call clean-up
502502

503503
def cleanup(self):
504-
MovieWriter.cleanup(self)
504+
super().cleanup()
505505
if self._tmpdir:
506506
_log.debug('MovieWriter: clearing temporary path=%s', self._tmpdir)
507507
self._tmpdir.cleanup()
@@ -1387,8 +1387,7 @@ def __init__(self, fig, interval=200, repeat_delay=0, repeat=True,
13871387
# sharing timers between animation objects for syncing animations.
13881388
if event_source is None:
13891389
event_source = fig.canvas.new_timer(interval=self._interval)
1390-
Animation.__init__(self, fig, event_source=event_source,
1391-
*args, **kwargs)
1390+
super().__init__(fig, event_source=event_source, *args, **kwargs)
13921391

13931392
def _step(self, *args):
13941393
"""Handler for getting events."""
@@ -1398,7 +1397,7 @@ def _step(self, *args):
13981397
# _repeat_delay is set, change the event_source's interval to our loop
13991398
# delay and set the callback to one which will then set the interval
14001399
# back.
1401-
still_going = Animation._step(self, *args)
1400+
still_going = super()._step(*args)
14021401
if not still_going and self.repeat:
14031402
self._init_draw()
14041403
self.frame_seq = self.new_frame_seq()
@@ -1414,7 +1413,7 @@ def _stop(self, *args):
14141413
# given the potential pause here), remove the loop_delay callback as
14151414
# well.
14161415
self.event_source.remove_callback(self._loop_delay)
1417-
Animation._stop(self)
1416+
super()._stop()
14181417

14191418
def _loop_delay(self, *args):
14201419
# Reset the interval and change callbacks after the delay.
@@ -1456,7 +1455,7 @@ def __init__(self, fig, artists, *args, **kwargs):
14561455
# Use the list of artists as the framedata, which will be iterated
14571456
# over by the machinery.
14581457
self._framedata = artists
1459-
TimedAnimation.__init__(self, fig, *args, **kwargs)
1458+
super().__init__(fig, *args, **kwargs)
14601459

14611460
def _init_draw(self):
14621461
# Make all the artists involved in *any* frame invisible
@@ -1628,7 +1627,7 @@ def iter_frames(frames=frames):
16281627
# Needs to be initialized so the draw functions work without checking
16291628
self._save_seq = []
16301629

1631-
TimedAnimation.__init__(self, fig, **kwargs)
1630+
super().__init__(fig, **kwargs)
16321631

16331632
# Need to reset the saved seq, since right now it will contain data
16341633
# for a single frame from init, which is not what we want.

lib/matplotlib/dates.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ class RRuleLocator(DateLocator):
11291129
# use the dateutil rrule instance
11301130

11311131
def __init__(self, o, tz=None):
1132-
DateLocator.__init__(self, tz)
1132+
super().__init__(tz)
11331133
self.rule = o
11341134

11351135
def __call__(self):
@@ -1296,7 +1296,7 @@ def __init__(self, tz=None, minticks=5, maxticks=None,
12961296
the ticks to be at hours 0, 6, 12, 18 when hourly ticking is done
12971297
at 6 hour intervals.
12981298
"""
1299-
DateLocator.__init__(self, tz)
1299+
super().__init__(tz)
13001300
self._freq = YEARLY
13011301
self._freqs = [YEARLY, MONTHLY, DAILY, HOURLY, MINUTELY,
13021302
SECONDLY, MICROSECONDLY]
@@ -1491,7 +1491,7 @@ def __init__(self, base=1, month=1, day=1, tz=None):
14911491
Mark years that are multiple of base on a given month and day
14921492
(default jan 1).
14931493
"""
1494-
DateLocator.__init__(self, tz)
1494+
super().__init__(tz)
14951495
self.base = ticker._Edge_integer(base, 0)
14961496
self.replaced = {'month': month,
14971497
'day': day,
@@ -1579,7 +1579,7 @@ def __init__(self, bymonth=None, bymonthday=1, interval=1, tz=None):
15791579

15801580
rule = rrulewrapper(MONTHLY, bymonth=bymonth, bymonthday=bymonthday,
15811581
interval=interval, **self.hms0d)
1582-
RRuleLocator.__init__(self, rule, tz)
1582+
super().__init__(rule, tz)
15831583

15841584

15851585
class WeekdayLocator(RRuleLocator):
@@ -1607,7 +1607,7 @@ def __init__(self, byweekday=1, interval=1, tz=None):
16071607

16081608
rule = rrulewrapper(DAILY, byweekday=byweekday,
16091609
interval=interval, **self.hms0d)
1610-
RRuleLocator.__init__(self, rule, tz)
1610+
super().__init__(rule, tz)
16111611

16121612

16131613
class DayLocator(RRuleLocator):
@@ -1633,7 +1633,7 @@ def __init__(self, bymonthday=None, interval=1, tz=None):
16331633

16341634
rule = rrulewrapper(DAILY, bymonthday=bymonthday,
16351635
interval=interval, **self.hms0d)
1636-
RRuleLocator.__init__(self, rule, tz)
1636+
super().__init__(rule, tz)
16371637

16381638

16391639
class HourLocator(RRuleLocator):
@@ -1653,7 +1653,7 @@ def __init__(self, byhour=None, interval=1, tz=None):
16531653

16541654
rule = rrulewrapper(HOURLY, byhour=byhour, interval=interval,
16551655
byminute=0, bysecond=0)
1656-
RRuleLocator.__init__(self, rule, tz)
1656+
super().__init__(rule, tz)
16571657

16581658

16591659
class MinuteLocator(RRuleLocator):
@@ -1673,7 +1673,7 @@ def __init__(self, byminute=None, interval=1, tz=None):
16731673

16741674
rule = rrulewrapper(MINUTELY, byminute=byminute, interval=interval,
16751675
bysecond=0)
1676-
RRuleLocator.__init__(self, rule, tz)
1676+
super().__init__(rule, tz)
16771677

16781678

16791679
class SecondLocator(RRuleLocator):
@@ -1693,7 +1693,7 @@ def __init__(self, bysecond=None, interval=1, tz=None):
16931693
bysecond = range(60)
16941694

16951695
rule = rrulewrapper(SECONDLY, bysecond=bysecond, interval=interval)
1696-
RRuleLocator.__init__(self, rule, tz)
1696+
super().__init__(rule, tz)
16971697

16981698

16991699
class MicrosecondLocator(DateLocator):
@@ -1730,15 +1730,15 @@ def __init__(self, interval=1, tz=None):
17301730

17311731
def set_axis(self, axis):
17321732
self._wrapped_locator.set_axis(axis)
1733-
return DateLocator.set_axis(self, axis)
1733+
return super().set_axis(axis)
17341734

17351735
def set_view_interval(self, vmin, vmax):
17361736
self._wrapped_locator.set_view_interval(vmin, vmax)
1737-
return DateLocator.set_view_interval(self, vmin, vmax)
1737+
return super().set_view_interval(vmin, vmax)
17381738

17391739
def set_data_interval(self, vmin, vmax):
17401740
self._wrapped_locator.set_data_interval(vmin, vmax)
1741-
return DateLocator.set_data_interval(self, vmin, vmax)
1741+
return super().set_data_interval(vmin, vmax)
17421742

17431743
def __call__(self):
17441744
# if no data have been set, this will tank with a ValueError

lib/matplotlib/gridspec.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,9 @@ def __init__(self, nrows, ncols, figure=None,
438438
self.hspace = hspace
439439
self.figure = figure
440440

441-
GridSpecBase.__init__(self, nrows, ncols,
442-
width_ratios=width_ratios,
443-
height_ratios=height_ratios)
441+
super().__init__(nrows, ncols,
442+
width_ratios=width_ratios,
443+
height_ratios=height_ratios)
444444

445445
if self.figure is None or not self.figure.get_constrained_layout():
446446
self._layoutbox = None
@@ -583,9 +583,9 @@ def __init__(self, nrows, ncols,
583583
self._hspace = hspace
584584
self._subplot_spec = subplot_spec
585585
self.figure = self._subplot_spec.get_gridspec().figure
586-
GridSpecBase.__init__(self, nrows, ncols,
587-
width_ratios=width_ratios,
588-
height_ratios=height_ratios)
586+
super().__init__(nrows, ncols,
587+
width_ratios=width_ratios,
588+
height_ratios=height_ratios)
589589
# do the layoutboxes
590590
subspeclb = subplot_spec._layoutbox
591591
if subspeclb is None:

lib/matplotlib/hatch.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,31 +130,34 @@ def __init__(self, hatch, density):
130130
path = Path.unit_circle()
131131
self.shape_vertices = path.vertices
132132
self.shape_codes = path.codes
133-
Shapes.__init__(self, hatch, density)
133+
super().__init__(hatch, density)
134134

135135

136136
class SmallCircles(Circles):
137137
size = 0.2
138138

139139
def __init__(self, hatch, density):
140140
self.num_rows = (hatch.count('o')) * density
141-
Circles.__init__(self, hatch, density)
141+
super().__init__(hatch, density)
142142

143143

144144
class LargeCircles(Circles):
145145
size = 0.35
146146

147147
def __init__(self, hatch, density):
148148
self.num_rows = (hatch.count('O')) * density
149-
Circles.__init__(self, hatch, density)
149+
super().__init__(hatch, density)
150150

151151

152+
# TODO: __init__ and class attributes override all attributes set by
153+
# SmallCircles. Should this class derive from Circles instead?
152154
class SmallFilledCircles(SmallCircles):
153155
size = 0.1
154156
filled = True
155157

156158
def __init__(self, hatch, density):
157159
self.num_rows = (hatch.count('.')) * density
160+
# Not super().__init__!
158161
Circles.__init__(self, hatch, density)
159162

160163

@@ -169,7 +172,7 @@ def __init__(self, hatch, density):
169172
self.shape_codes = np.full(len(self.shape_vertices), Path.LINETO,
170173
dtype=Path.code_type)
171174
self.shape_codes[0] = Path.MOVETO
172-
Shapes.__init__(self, hatch, density)
175+
super().__init__(hatch, density)
173176

174177
_hatch_types = [
175178
HorizontalHatch,

lib/matplotlib/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ def set_interpolation(self, s):
11041104
if s is not None and s not in ('nearest', 'bilinear'):
11051105
raise NotImplementedError('Only nearest neighbor and '
11061106
'bilinear interpolations are supported')
1107-
AxesImage.set_interpolation(self, s)
1107+
super().set_interpolation(s)
11081108

11091109
def get_extent(self):
11101110
if self._A is None:

0 commit comments

Comments
 (0)