From a78721b017c1f29063dcbb3be45291ca5395ac2f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 23 Jul 2020 00:51:08 -0400 Subject: [PATCH 1/3] Use `super()` in tool manager. --- lib/matplotlib/backend_tools.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/matplotlib/backend_tools.py b/lib/matplotlib/backend_tools.py index e4bf0ec68729..d4dbf321f211 100644 --- a/lib/matplotlib/backend_tools.py +++ b/lib/matplotlib/backend_tools.py @@ -187,7 +187,7 @@ class ToolToggleBase(ToolBase): def __init__(self, *args, **kwargs): self._toggled = kwargs.pop('toggled', self.default_toggled) - ToolBase.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) def trigger(self, sender, event, data=None): """Calls `enable` or `disable` based on `toggled` value.""" @@ -235,7 +235,7 @@ def set_figure(self, figure): # if no figure the internal state is not changed # we change it here so next call to trigger will change it back self._toggled = False - ToolBase.set_figure(self, figure) + super().set_figure(figure) if toggled: if figure: self.trigger(self, None) @@ -253,7 +253,7 @@ class SetCursorBase(ToolBase): `set_cursor` when a tool gets triggered. """ def __init__(self, *args, **kwargs): - ToolBase.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) self._id_drag = None self._cursor = None self._default_cursor = cursors.POINTER @@ -268,7 +268,7 @@ def __init__(self, *args, **kwargs): def set_figure(self, figure): if self._id_drag: self.canvas.mpl_disconnect(self._id_drag) - ToolBase.set_figure(self, figure) + super().set_figure(figure) if figure: self._id_drag = self.canvas.mpl_connect( 'motion_notify_event', self._set_cursor_cbk) @@ -324,12 +324,12 @@ class ToolCursorPosition(ToolBase): """ def __init__(self, *args, **kwargs): self._id_drag = None - ToolBase.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) def set_figure(self, figure): if self._id_drag: self.canvas.mpl_disconnect(self._id_drag) - ToolBase.set_figure(self, figure) + super().set_figure(figure) if figure: self._id_drag = self.canvas.mpl_connect( 'motion_notify_event', self.send_message) @@ -473,7 +473,7 @@ class AxisScaleBase(ToolToggleBase): def trigger(self, sender, event, data=None): if event.inaxes is None: return - ToolToggleBase.trigger(self, sender, event, data) + super().trigger(sender, event, data) def enable(self, event): self.set_scale(event.inaxes, 'log') @@ -522,7 +522,7 @@ def __init__(self, *args, **kwargs): self.views = WeakKeyDictionary() self.positions = WeakKeyDictionary() self.home_views = WeakKeyDictionary() - ToolBase.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) def add_figure(self, figure): """Add the current figure to the stack of views and positions.""" @@ -719,7 +719,7 @@ class SaveFigureBase(ToolBase): class ZoomPanBase(ToolToggleBase): """Base class for `ToolZoom` and `ToolPan`.""" def __init__(self, *args): - ToolToggleBase.__init__(self, *args) + super().__init__(*args) self._button_pressed = None self._xypress = None self._idPress = None @@ -749,7 +749,7 @@ def disable(self, event): def trigger(self, sender, event, data=None): self.toolmanager.get_tool(_views_positions).add_figure(self.figure) - ToolToggleBase.trigger(self, sender, event, data) + super().trigger(sender, event, data) def scroll_zoom(self, event): # https://gist.github.com/tacaswell/3144287 @@ -790,7 +790,7 @@ class ToolZoom(ZoomPanBase): radio_group = 'default' def __init__(self, *args): - ZoomPanBase.__init__(self, *args) + super().__init__(*args) self._ids_zoom = [] def _cancel_action(self): @@ -916,7 +916,7 @@ class ToolPan(ZoomPanBase): radio_group = 'default' def __init__(self, *args): - ZoomPanBase.__init__(self, *args) + super().__init__(*args) self._id_drag = None def _cancel_action(self): From 493400dc4ac6fcbd430bf91cebf3bd55f3893695 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 23 Jul 2020 01:07:22 -0400 Subject: [PATCH 2/3] Use `super()` in blocking input. --- lib/matplotlib/blocking_input.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/matplotlib/blocking_input.py b/lib/matplotlib/blocking_input.py index b9ce7981552e..561fb4520136 100644 --- a/lib/matplotlib/blocking_input.py +++ b/lib/matplotlib/blocking_input.py @@ -115,9 +115,8 @@ def __init__(self, fig, mouse_add=MouseButton.LEFT, mouse_pop=MouseButton.RIGHT, mouse_stop=MouseButton.MIDDLE): - BlockingInput.__init__(self, fig=fig, - eventslist=('button_press_event', - 'key_press_event')) + super().__init__(fig=fig, + eventslist=('button_press_event', 'key_press_event')) self.button_add = mouse_add self.button_pop = mouse_pop self.button_stop = mouse_stop @@ -239,7 +238,7 @@ def pop(self, event, index=-1): Defaults to the last click. """ self.pop_click(event, index) - BlockingInput.pop(self, index) + super().pop(index) def cleanup(self, event=None): """ @@ -255,7 +254,7 @@ def cleanup(self, event=None): self.marks = [] self.fig.canvas.draw() # Call base class to remove callbacks. - BlockingInput.cleanup(self) + super().cleanup() def __call__(self, n=1, timeout=30, show_clicks=True): """ @@ -264,7 +263,7 @@ def __call__(self, n=1, timeout=30, show_clicks=True): self.show_clicks = show_clicks self.clicks = [] self.marks = [] - BlockingInput.__call__(self, n=n, timeout=timeout) + super().__call__(n=n, timeout=timeout) return self.clicks @@ -277,7 +276,7 @@ class BlockingContourLabeler(BlockingMouseInput): def __init__(self, cs): self.cs = cs - BlockingMouseInput.__init__(self, fig=cs.axes.figure) + super().__init__(fig=cs.axes.figure) def add_click(self, event): self.button1(event) @@ -323,8 +322,7 @@ def button3(self, event): def __call__(self, inline, inline_spacing=5, n=-1, timeout=-1): self.inline = inline self.inline_spacing = inline_spacing - BlockingMouseInput.__call__(self, n=n, timeout=timeout, - show_clicks=False) + super().__call__(n=n, timeout=timeout, show_clicks=False) class BlockingKeyMouseInput(BlockingInput): @@ -333,8 +331,8 @@ class BlockingKeyMouseInput(BlockingInput): """ def __init__(self, fig): - BlockingInput.__init__(self, fig=fig, eventslist=( - 'button_press_event', 'key_press_event')) + super().__init__(fig=fig, + eventslist=('button_press_event', 'key_press_event')) def post_event(self): """Determine if it is a key event.""" @@ -351,6 +349,6 @@ def __call__(self, timeout=30): timed out. """ self.keyormouse = None - BlockingInput.__call__(self, n=1, timeout=timeout) + super().__call__(n=1, timeout=timeout) return self.keyormouse From 99619e3861fa6146fa3b13df33a9ebc25e927044 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 23 Jul 2020 01:18:27 -0400 Subject: [PATCH 3/3] Use `super()` in backend classes and examples. --- .../embedding_in_wx2_sgskip.py | 3 +- .../embedding_in_wx3_sgskip.py | 2 +- .../embedding_in_wx4_sgskip.py | 5 ++- .../embedding_in_wx5_sgskip.py | 4 +-- .../user_interfaces/fourier_demo_wx_sgskip.py | 2 +- .../user_interfaces/mathtext_wx_sgskip.py | 2 +- .../user_interfaces/wxcursor_demo_sgskip.py | 2 +- lib/matplotlib/backends/_backend_tk.py | 20 ++++++------ lib/matplotlib/backends/backend_agg.py | 2 +- lib/matplotlib/backends/backend_cairo.py | 8 ++--- lib/matplotlib/backends/backend_gtk3.py | 6 ++-- lib/matplotlib/backends/backend_nbagg.py | 2 +- lib/matplotlib/backends/backend_pdf.py | 4 +-- lib/matplotlib/backends/backend_pgf.py | 2 +- lib/matplotlib/backends/backend_ps.py | 6 ++-- lib/matplotlib/backends/backend_qt5.py | 8 ++--- lib/matplotlib/backends/backend_svg.py | 6 ++-- .../backends/backend_webagg_core.py | 6 ++-- lib/matplotlib/backends/backend_wx.py | 31 +++++++++---------- .../backends/qt_editor/_formlayout.py | 18 +++++------ 20 files changed, 67 insertions(+), 72 deletions(-) diff --git a/examples/user_interfaces/embedding_in_wx2_sgskip.py b/examples/user_interfaces/embedding_in_wx2_sgskip.py index c2bf57102da2..7c29b32b9063 100644 --- a/examples/user_interfaces/embedding_in_wx2_sgskip.py +++ b/examples/user_interfaces/embedding_in_wx2_sgskip.py @@ -20,8 +20,7 @@ class CanvasFrame(wx.Frame): def __init__(self): - wx.Frame.__init__(self, None, -1, - 'CanvasFrame', size=(550, 350)) + super().__init__(None, -1, 'CanvasFrame', size=(550, 350)) self.figure = Figure() self.axes = self.figure.add_subplot(111) diff --git a/examples/user_interfaces/embedding_in_wx3_sgskip.py b/examples/user_interfaces/embedding_in_wx3_sgskip.py index 1dfdc4054d05..c25c9be7aba2 100644 --- a/examples/user_interfaces/embedding_in_wx3_sgskip.py +++ b/examples/user_interfaces/embedding_in_wx3_sgskip.py @@ -37,7 +37,7 @@ class PlotPanel(wx.Panel): def __init__(self, parent): - wx.Panel.__init__(self, parent, -1) + super().__init__(parent, -1) self.fig = Figure((5, 4), 75) self.canvas = FigureCanvas(self, -1, self.fig) diff --git a/examples/user_interfaces/embedding_in_wx4_sgskip.py b/examples/user_interfaces/embedding_in_wx4_sgskip.py index 77dccda3545c..153ca22a0fb4 100644 --- a/examples/user_interfaces/embedding_in_wx4_sgskip.py +++ b/examples/user_interfaces/embedding_in_wx4_sgskip.py @@ -21,7 +21,7 @@ class MyNavigationToolbar(NavigationToolbar): """Extend the default wx toolbar with your own event handlers.""" def __init__(self, canvas): - NavigationToolbar.__init__(self, canvas) + super().__init__(canvas) # We use a stock wx bitmap, but you could also use your own image file. bmp = wx.ArtProvider.GetBitmap(wx.ART_CROSS_MARK, wx.ART_TOOLBAR) tool = self.AddTool(wx.ID_ANY, 'Click me', bmp, @@ -41,8 +41,7 @@ def _on_custom(self, event): class CanvasFrame(wx.Frame): def __init__(self): - wx.Frame.__init__(self, None, -1, - 'CanvasFrame', size=(550, 350)) + super().__init__(None, -1, 'CanvasFrame', size=(550, 350)) self.figure = Figure(figsize=(5, 4), dpi=100) self.axes = self.figure.add_subplot(111) diff --git a/examples/user_interfaces/embedding_in_wx5_sgskip.py b/examples/user_interfaces/embedding_in_wx5_sgskip.py index 32da3c4b987c..2a97089697bc 100644 --- a/examples/user_interfaces/embedding_in_wx5_sgskip.py +++ b/examples/user_interfaces/embedding_in_wx5_sgskip.py @@ -17,7 +17,7 @@ class Plot(wx.Panel): def __init__(self, parent, id=-1, dpi=None, **kwargs): - wx.Panel.__init__(self, parent, id=id, **kwargs) + super().__init__(parent, id=id, **kwargs) self.figure = mpl.figure.Figure(dpi=dpi, figsize=(2, 2)) self.canvas = FigureCanvas(self, -1, self.figure) self.toolbar = NavigationToolbar(self.canvas) @@ -31,7 +31,7 @@ def __init__(self, parent, id=-1, dpi=None, **kwargs): class PlotNotebook(wx.Panel): def __init__(self, parent, id=-1): - wx.Panel.__init__(self, parent, id=id) + super().__init__(parent, id=id) self.nb = aui.AuiNotebook(self) sizer = wx.BoxSizer() sizer.Add(self.nb, 1, wx.EXPAND) diff --git a/examples/user_interfaces/fourier_demo_wx_sgskip.py b/examples/user_interfaces/fourier_demo_wx_sgskip.py index c11814e7ba7b..ba67e925dcd8 100644 --- a/examples/user_interfaces/fourier_demo_wx_sgskip.py +++ b/examples/user_interfaces/fourier_demo_wx_sgskip.py @@ -104,7 +104,7 @@ def setKnob(self, value): class FourierDemoFrame(wx.Frame): def __init__(self, *args, **kwargs): - wx.Frame.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) panel = wx.Panel(self) # create the GUI elements diff --git a/examples/user_interfaces/mathtext_wx_sgskip.py b/examples/user_interfaces/mathtext_wx_sgskip.py index 0b544f96c2a5..eebf57c2925d 100644 --- a/examples/user_interfaces/mathtext_wx_sgskip.py +++ b/examples/user_interfaces/mathtext_wx_sgskip.py @@ -40,7 +40,7 @@ def mathtext_to_wxbitmap(s): class CanvasFrame(wx.Frame): def __init__(self, parent, title): - wx.Frame.__init__(self, parent, -1, title, size=(550, 350)) + super().__init__(parent, -1, title, size=(550, 350)) self.figure = Figure() self.axes = self.figure.add_subplot(111) diff --git a/examples/user_interfaces/wxcursor_demo_sgskip.py b/examples/user_interfaces/wxcursor_demo_sgskip.py index 7269b68159ef..3c8418db298c 100644 --- a/examples/user_interfaces/wxcursor_demo_sgskip.py +++ b/examples/user_interfaces/wxcursor_demo_sgskip.py @@ -16,7 +16,7 @@ class CanvasFrame(wx.Frame): def __init__(self, ): - wx.Frame.__init__(self, None, -1, 'CanvasFrame', size=(550, 350)) + super().__init__(None, -1, 'CanvasFrame', size=(550, 350)) self.figure = Figure() self.axes = self.figure.add_subplot(111) diff --git a/lib/matplotlib/backends/_backend_tk.py b/lib/matplotlib/backends/_backend_tk.py index 2560cce72bed..c646732d24bc 100644 --- a/lib/matplotlib/backends/_backend_tk.py +++ b/lib/matplotlib/backends/_backend_tk.py @@ -77,7 +77,7 @@ class TimerTk(TimerBase): def __init__(self, parent, *args, **kwargs): self._timer = None - TimerBase.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) self.parent = parent def _timer_start(self): @@ -90,7 +90,7 @@ def _timer_stop(self): self._timer = None def _on_timer(self): - TimerBase._on_timer(self) + super()._on_timer() # Tk after() is only a single shot, so we need to add code here to # reset the timer if we're not operating in single shot mode. However, # if _timer is None, this means that _timer_stop has been called; so @@ -263,13 +263,13 @@ def motion_notify_event(self, event): x = event.x # flipy so y=0 is bottom of canvas y = self.figure.bbox.height - event.y - FigureCanvasBase.motion_notify_event(self, x, y, guiEvent=event) + super().motion_notify_event(x, y, guiEvent=event) def enter_notify_event(self, event): x = event.x # flipy so y=0 is bottom of canvas y = self.figure.bbox.height - event.y - FigureCanvasBase.enter_notify_event(self, guiEvent=event, xy=(x, y)) + super().enter_notify_event(guiEvent=event, xy=(x, y)) def button_press_event(self, event, dblclick=False): x = event.x @@ -284,8 +284,8 @@ def button_press_event(self, event, dblclick=False): elif num == 3: num = 2 - FigureCanvasBase.button_press_event( - self, x, y, num, dblclick=dblclick, guiEvent=event) + super().button_press_event(x, y, num, + dblclick=dblclick, guiEvent=event) def button_dblclick_event(self, event): self.button_press_event(event, dblclick=True) @@ -304,14 +304,14 @@ def button_release_event(self, event): elif num == 3: num = 2 - FigureCanvasBase.button_release_event(self, x, y, num, guiEvent=event) + super().button_release_event(x, y, num, guiEvent=event) def scroll_event(self, event): x = event.x y = self.figure.bbox.height - event.y num = getattr(event, 'num', None) step = 1 if num == 4 else -1 if num == 5 else 0 - FigureCanvasBase.scroll_event(self, x, y, step, guiEvent=event) + super().scroll_event(x, y, step, guiEvent=event) def scroll_event_windows(self, event): """MouseWheel event processor""" @@ -399,7 +399,7 @@ class FigureManagerTk(FigureManagerBase): """ def __init__(self, canvas, num, window): - FigureManagerBase.__init__(self, canvas, num) + super().__init__(canvas, num) self.window = window self.window.withdraw() self.set_window_title("Figure %d" % num) @@ -804,7 +804,7 @@ def trigger(self, *args): class ConfigureSubplotsTk(backend_tools.ConfigureSubplotsBase): def __init__(self, *args, **kwargs): - backend_tools.ConfigureSubplotsBase.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) self.window = None def trigger(self, *args): diff --git a/lib/matplotlib/backends/backend_agg.py b/lib/matplotlib/backends/backend_agg.py index 1dfff114d9bb..3e16cd0d39e3 100644 --- a/lib/matplotlib/backends/backend_agg.py +++ b/lib/matplotlib/backends/backend_agg.py @@ -85,7 +85,7 @@ class RendererAgg(RendererBase): lock = threading.RLock() def __init__(self, width, height, dpi): - RendererBase.__init__(self) + super().__init__() self.dpi = dpi self.width = width diff --git a/lib/matplotlib/backends/backend_cairo.py b/lib/matplotlib/backends/backend_cairo.py index 7f06aefdb2e6..5d78b3e6af32 100644 --- a/lib/matplotlib/backends/backend_cairo.py +++ b/lib/matplotlib/backends/backend_cairo.py @@ -131,7 +131,7 @@ def __init__(self, dpi): self.gc = GraphicsContextCairo(renderer=self) self.text_ctx = cairo.Context( cairo.ImageSurface(cairo.FORMAT_ARGB32, 1, 1)) - RendererBase.__init__(self) + super().__init__() @cbook.deprecated("3.4") @property @@ -338,14 +338,14 @@ class GraphicsContextCairo(GraphicsContextBase): } def __init__(self, renderer): - GraphicsContextBase.__init__(self) + super().__init__() self.renderer = renderer def restore(self): self.ctx.restore() def set_alpha(self, alpha): - GraphicsContextBase.set_alpha(self, alpha) + super().set_alpha(alpha) _alpha = self.get_alpha() rgb = self._rgb if self.get_forced_alpha(): @@ -391,7 +391,7 @@ def set_dashes(self, offset, dashes): offset) def set_foreground(self, fg, isRGBA=None): - GraphicsContextBase.set_foreground(self, fg, isRGBA) + super().set_foreground(fg, isRGBA) if len(self._rgb) == 3: self.ctx.set_source_rgb(*self._rgb) else: diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 6743716ee531..9437e5bab95f 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -54,7 +54,7 @@ class TimerGTK3(TimerBase): def __init__(self, *args, **kwargs): self._timer = None - TimerBase.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) def _timer_start(self): # Need to stop it, otherwise we potentially leak a timer id that will @@ -74,7 +74,7 @@ def _timer_set_interval(self): self._timer_start() def _on_timer(self): - TimerBase._on_timer(self) + super()._on_timer() # Gtk timeout_add() requires that the callback returns True if it # is to be called again. @@ -369,7 +369,7 @@ class FigureManagerGTK3(FigureManagerBase): """ def __init__(self, canvas, num): - FigureManagerBase.__init__(self, canvas, num) + super().__init__(canvas, num) self.window = Gtk.Window() self.window.set_wmclass("matplotlib", "Matplotlib") diff --git a/lib/matplotlib/backends/backend_nbagg.py b/lib/matplotlib/backends/backend_nbagg.py index 200ef2c88732..9eb076d9ec44 100644 --- a/lib/matplotlib/backends/backend_nbagg.py +++ b/lib/matplotlib/backends/backend_nbagg.py @@ -75,7 +75,7 @@ class FigureManagerNbAgg(FigureManagerWebAgg): def __init__(self, canvas, num): self._shown = False - FigureManagerWebAgg.__init__(self, canvas, num) + super().__init__(canvas, num) def display_js(self): # XXX How to do this just once? It has to deal with multiple diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index 657d19bc84d8..cf5fc8a03a9c 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -2296,7 +2296,7 @@ def new_gc(self): class GraphicsContextPdf(GraphicsContextBase): def __init__(self, file): - GraphicsContextBase.__init__(self) + super().__init__() self._fillcolor = (0.0, 0.0, 0.0) self._effective_alphas = (1.0, 1.0) self.file = file @@ -2481,7 +2481,7 @@ def copy_properties(self, other): """ Copy properties of other into self. """ - GraphicsContextBase.copy_properties(self, other) + super().copy_properties(other) fillcolor = getattr(other, '_fillcolor', self._fillcolor) effective_alphas = getattr(other, '_effective_alphas', self._effective_alphas) diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index 8da4abca6bba..39b07a8a6bec 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -420,7 +420,7 @@ def __init__(self, figure, fh, dummy=False): File handle for the output of the drawing commands. """ - RendererBase.__init__(self) + super().__init__() self.dpi = figure.dpi self.fh = fh self.figure = figure diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index eb213b334846..0ec81774e4ff 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -761,12 +761,10 @@ def _is_transparent(rgb_or_rgba): class GraphicsContextPS(GraphicsContextBase): def get_capstyle(self): - return {'butt': 0, 'round': 1, 'projecting': 2}[ - GraphicsContextBase.get_capstyle(self)] + return {'butt': 0, 'round': 1, 'projecting': 2}[super().get_capstyle()] def get_joinstyle(self): - return {'miter': 0, 'round': 1, 'bevel': 2}[ - GraphicsContextBase.get_joinstyle(self)] + return {'miter': 0, 'round': 1, 'bevel': 2}[super().get_joinstyle()] class _Orientation(Enum): diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index a674605240a9..06a279fca24e 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -182,7 +182,7 @@ def __init__(self, *args, **kwargs): # _on_timer method. self._timer = QtCore.QTimer() self._timer.timeout.connect(self._on_timer) - TimerBase.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) def __del__(self): # The check for deletedness is needed to avoid an error at animation @@ -516,7 +516,7 @@ class MainWindow(QtWidgets.QMainWindow): def closeEvent(self, event): self.closing.emit() - QtWidgets.QMainWindow.closeEvent(self, event) + super().closeEvent(event) class FigureManagerQT(FigureManagerBase): @@ -534,7 +534,7 @@ class FigureManagerQT(FigureManagerBase): """ def __init__(self, canvas, num): - FigureManagerBase.__init__(self, canvas, num) + super().__init__(canvas, num) self.window = MainWindow() self.window.closing.connect(canvas.close_event) self.window.closing.connect(self._widgetclosed) @@ -831,7 +831,7 @@ def set_history_buttons(self): class SubplotToolQt(UiSubplotTool): def __init__(self, targetfig, parent): - UiSubplotTool.__init__(self, None) + super().__init__(None) self._figure = targetfig diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py index dbcbbd225b0c..7de53b880c8c 100644 --- a/lib/matplotlib/backends/backend_svg.py +++ b/lib/matplotlib/backends/backend_svg.py @@ -295,7 +295,7 @@ def __init__(self, width, height, svgwriter, basename=None, image_dpi=72, self._n_gradients = 0 self._fonts = OrderedDict() - RendererBase.__init__(self) + super().__init__() self._glyph_map = dict() str_height = short_float_fmt(height) str_width = short_float_fmt(width) @@ -735,8 +735,8 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms, should_do_optimization = \ len_path + 9 * uses_per_path + 3 < (len_path + 5) * uses_per_path if not should_do_optimization: - return RendererBase.draw_path_collection( - self, gc, master_transform, paths, all_transforms, + return super().draw_path_collection( + gc, master_transform, paths, all_transforms, offsets, offsetTrans, facecolors, edgecolors, linewidths, linestyles, antialiaseds, urls, offset_position) diff --git a/lib/matplotlib/backends/backend_webagg_core.py b/lib/matplotlib/backends/backend_webagg_core.py index 20a5676c4bf1..796026184201 100644 --- a/lib/matplotlib/backends/backend_webagg_core.py +++ b/lib/matplotlib/backends/backend_webagg_core.py @@ -121,7 +121,7 @@ class FigureCanvasWebAggCore(backend_agg.FigureCanvasAgg): supports_blit = False def __init__(self, *args, **kwargs): - backend_agg.FigureCanvasAgg.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) # Set to True when the renderer contains data that is newer # than the PNG buffer. @@ -379,7 +379,7 @@ def draw_rubberband(self, event, x0, y0, x1, y1): "rubberband", x0=x0, y0=y0, x1=x1, y1=y1) def release_zoom(self, event): - backend_bases.NavigationToolbar2.release_zoom(self, event) + super().release_zoom(event) self.canvas.send_event( "rubberband", x0=-1, y0=-1, x1=-1, y1=-1) @@ -406,7 +406,7 @@ class FigureManagerWebAgg(backend_bases.FigureManagerBase): ToolbarCls = NavigationToolbar2WebAgg def __init__(self, canvas, num): - backend_bases.FigureManagerBase.__init__(self, canvas, num) + super().__init__(canvas, num) self.web_sockets = set() diff --git a/lib/matplotlib/backends/backend_wx.py b/lib/matplotlib/backends/backend_wx.py index 2296f2877a7c..6c2ef0cda62d 100644 --- a/lib/matplotlib/backends/backend_wx.py +++ b/lib/matplotlib/backends/backend_wx.py @@ -75,7 +75,7 @@ class TimerWx(TimerBase): def __init__(self, *args, **kwargs): self._timer = wx.Timer() self._timer.Notify = self._on_timer - TimerBase.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) def _timer_start(self): self._timer.Start(self._interval, self._single) @@ -149,7 +149,7 @@ def __init__(self, bitmap, dpi): "2.0", name="wx", obj_type="backend", removal="the future", alternative="wxagg", addendum="See the Matplotlib usage FAQ for " "more info on backends.") - RendererBase.__init__(self) + super().__init__() _log.debug("%s - __init__()", type(self)) self.width = bitmap.GetWidth() self.height = bitmap.GetHeight() @@ -339,7 +339,7 @@ class GraphicsContextWx(GraphicsContextBase): _cache = weakref.WeakKeyDictionary() def __init__(self, bitmap, renderer): - GraphicsContextBase.__init__(self) + super().__init__() # assert self.Ok(), "wxMemoryDC not OK to use" _log.debug("%s - __init__(): %s", type(self), bitmap) @@ -379,7 +379,7 @@ def set_foreground(self, fg, isRGBA=None): # Same goes for text foreground... _log.debug("%s - set_foreground()", type(self)) self.select() - GraphicsContextBase.set_foreground(self, fg, isRGBA) + super().set_foreground(fg, isRGBA) self._pen.SetColour(self.get_wxcolour(self.get_rgb())) self.gfx_ctx.SetPen(self._pen) @@ -392,7 +392,7 @@ def set_linewidth(self, w): self.select() if 0 < w < 1: w = 1 - GraphicsContextBase.set_linewidth(self, w) + super().set_linewidth(w) lw = int(self.renderer.points_to_pixels(self._linewidth)) if lw == 0: lw = 1 @@ -404,7 +404,7 @@ def set_capstyle(self, cs): # docstring inherited _log.debug("%s - set_capstyle()", type(self)) self.select() - GraphicsContextBase.set_capstyle(self, cs) + super().set_capstyle(cs) self._pen.SetCap(GraphicsContextWx._capd[self._capstyle]) self.gfx_ctx.SetPen(self._pen) self.unselect() @@ -413,7 +413,7 @@ def set_joinstyle(self, js): # docstring inherited _log.debug("%s - set_joinstyle()", type(self)) self.select() - GraphicsContextBase.set_joinstyle(self, js) + super().set_joinstyle(js) self._pen.SetJoin(GraphicsContextWx._joind[self._joinstyle]) self.gfx_ctx.SetPen(self._pen) self.unselect() @@ -917,8 +917,7 @@ def __init__(self, num, fig): pos = wx.DefaultPosition else: pos = wx.Point(20, 20) - wx.Frame.__init__(self, parent=None, id=-1, pos=pos, - title="Figure %d" % num) + super().__init__(parent=None, id=-1, pos=pos, title="Figure %d" % num) # Frame will be sized later by the Fit method _log.debug("%s - __init__()", type(self)) self.num = num @@ -1005,7 +1004,7 @@ def Destroy(self, *args, **kwargs): # RuntimeError at exit with e.g. # MPLBACKEND=wxagg python -c 'from pylab import *; plot()'. if self and not self.IsBeingDeleted(): - wx.Frame.Destroy(self, *args, **kwargs) + super().Destroy(*args, **kwargs) if self.toolbar is not None: self.toolbar.Destroy() wxapp = wx.GetApp() @@ -1031,7 +1030,7 @@ class FigureManagerWx(FigureManagerBase): def __init__(self, canvas, num, frame): _log.debug("%s - __init__()", type(self)) - FigureManagerBase.__init__(self, canvas, num) + super().__init__(canvas, num) self.frame = frame self.window = frame @@ -1357,7 +1356,7 @@ class StatusBarWx(wx.StatusBar): """ def __init__(self, parent, *args, **kwargs): - wx.StatusBar.__init__(self, parent, -1) + super().__init__(parent, -1) self.SetFieldsCount(2) def set_function(self, string): @@ -1507,7 +1506,7 @@ def set_cursor(self, cursor): # on most platforms, use overlay class RubberbandWx(backend_tools.RubberbandBase): def __init__(self, *args, **kwargs): - backend_tools.RubberbandBase.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) self._wxoverlay = None def draw_rubberband(self, x0, y0, x1, y1): @@ -1557,7 +1556,7 @@ def remove_rubberband(self): # the workaround is to blit the full image for remove_rubberband class RubberbandWx(backend_tools.RubberbandBase): def __init__(self, *args, **kwargs): - backend_tools.RubberbandBase.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) self._rect = None def draw_rubberband(self, x0, y0, x1, y1): @@ -1596,8 +1595,8 @@ class _HelpDialog(wx.Dialog): widths = [100, 140, 300] def __init__(self, parent, help_entries): - wx.Dialog.__init__(self, parent, title="Help", - style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) + super().__init__(parent, title="Help", + style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) sizer = wx.BoxSizer(wx.VERTICAL) grid_sizer = wx.FlexGridSizer(0, 3, 8, 6) diff --git a/lib/matplotlib/backends/qt_editor/_formlayout.py b/lib/matplotlib/backends/qt_editor/_formlayout.py index be34e19bad42..40722a934899 100644 --- a/lib/matplotlib/backends/qt_editor/_formlayout.py +++ b/lib/matplotlib/backends/qt_editor/_formlayout.py @@ -61,7 +61,7 @@ class ColorButton(QtWidgets.QPushButton): colorChanged = QtCore.Signal(QtGui.QColor) def __init__(self, parent=None): - QtWidgets.QPushButton.__init__(self, parent) + super().__init__(parent) self.setFixedSize(20, 20) self.setIconSize(QtCore.QSize(12, 12)) self.clicked.connect(self.choose_color) @@ -104,7 +104,7 @@ def to_qcolor(color): class ColorLayout(QtWidgets.QHBoxLayout): """Color-specialized QLineEdit layout""" def __init__(self, color, parent=None): - QtWidgets.QHBoxLayout.__init__(self) + super().__init__() assert isinstance(color, QtGui.QColor) self.lineedit = QtWidgets.QLineEdit( mcolors.to_hex(color.getRgbF(), keep_alpha=True), parent) @@ -161,7 +161,7 @@ def qfont_to_tuple(font): class FontLayout(QtWidgets.QGridLayout): """Font selection""" def __init__(self, value, parent=None): - QtWidgets.QGridLayout.__init__(self) + super().__init__() font = tuple_to_qfont(value) assert font is not None @@ -228,7 +228,7 @@ def __init__(self, data, comment="", with_margin=False, parent=None): parent : QWidget or None The parent widget. """ - QtWidgets.QWidget.__init__(self, parent) + super().__init__(parent) self.data = copy.deepcopy(data) self.widgets = [] self.formlayout = QtWidgets.QFormLayout(self) @@ -356,7 +356,7 @@ class FormComboWidget(QtWidgets.QWidget): update_buttons = QtCore.Signal() def __init__(self, datalist, comment="", parent=None): - QtWidgets.QWidget.__init__(self, parent) + super().__init__(parent) layout = QtWidgets.QVBoxLayout() self.setLayout(layout) self.combobox = QtWidgets.QComboBox() @@ -386,7 +386,7 @@ class FormTabWidget(QtWidgets.QWidget): update_buttons = QtCore.Signal() def __init__(self, datalist, comment="", parent=None): - QtWidgets.QWidget.__init__(self, parent) + super().__init__(parent) layout = QtWidgets.QVBoxLayout() self.tabwidget = QtWidgets.QTabWidget() layout.addWidget(self.tabwidget) @@ -415,7 +415,7 @@ class FormDialog(QtWidgets.QDialog): """Form Dialog""" def __init__(self, data, title="", comment="", icon=None, parent=None, apply=None): - QtWidgets.QDialog.__init__(self, parent) + super().__init__(parent) self.apply_callback = apply @@ -471,11 +471,11 @@ def update_buttons(self): def accept(self): self.data = self.formwidget.get() - QtWidgets.QDialog.accept(self) + super().accept() def reject(self): self.data = None - QtWidgets.QDialog.reject(self) + super().reject() def apply(self): self.apply_callback(self.formwidget.get())