8000 Add missing super __init__ in subclasses by QuLogic · Pull Request #20436 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add missing super __init__ in subclasses #20436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,9 +1272,8 @@ def __init__(self, vcenter, vmin=None, vmax=None):
array([0., 0.25, 0.5, 0.625, 0.75, 0.875, 1.0])
"""

super().__init__(vmin=vmin, vmax=vmax)
self.vcenter = vcenter
self.vmin = vmin
self.vmax = vmax
if vcenter is not None and vmax is not None and vcenter >= vmax:
raise ValueError('vmin, vcenter, and vmax must be in '
'ascending order')
Expand Down Expand Up @@ -1353,12 +1352,10 @@ def __init__(self, vcenter=0, halfrange=None, clip=False):
>>> norm(data)
array([0.25, 0.5 , 1. ])
"""
super().__init__(vmin=None, vmax=None, clip=clip)
self._vcenter = vcenter
self.vmin = None
self.vmax = None
# calling the halfrange setter to set vmin and vmax
self.halfrange = halfrange
self.clip = clip

def _set_vmin_vmax(self):
"""
Expand Down Expand Up @@ -1696,9 +1693,7 @@ def __init__(self, boundaries, ncolors, clip=False, *, extend='neither'):
"""
if clip and extend != 'neither':
raise ValueError("'clip=True' is not compatible with 'extend'")
self.clip = clip
self.vmin = boundaries[0]
self.vmax = boundaries[-1]
super().__init__(vmin=boundaries[0], vmax=boundaries[-1], clip=clip)
self.boundaries = np.asarray(boundaries)
self.N = len(self.boundaries)
if self.N < 2:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1668,9 +1668,9 @@ def __init__(self, interval=1, tz=None):
example, if ``interval=2``, mark every second microsecond.

"""
super().__init__(tz=tz)
self._interval = interval
self._wrapped_locator = ticker.MultipleLocator(interval)
self.tz = tz

def set_axis(self, axis):
self._wrapped_locator.set_axis(axis)
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class MathtextBackendPs(MathtextBackend):
"_PSResult", "width height depth pswriter used_characters")

def __init__(self):
super().__init__()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are none of these really ever tested? Maybe beyond this PR, but they should be if they aren't...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're almost all unused, which I guess is why they're deprecated. For the ones that are used, I assume they all get .set_canvas_size called first, which sets the things that were missed in the super __init__.

self.pswriter = StringIO()
self.lastfont = None

Expand Down Expand Up @@ -230,6 +231,7 @@ class MathtextBackendPdf(MathtextBackend):
"_PDFResult", "width height depth glyphs rects used_characters")

def __init__(self):
super().__init__()
self.glyphs = []
self.rects = []

Expand Down Expand Up @@ -260,6 +262,7 @@ class MathtextBackendSvg(MathtextBackend):
backend.
"""
def __init__(self):
super().__init__()
self.svg_glyphs = []
self.svg_rects = []

Expand Down Expand Up @@ -293,6 +296,7 @@ class MathtextBackendPath(MathtextBackend):
_Result = namedtuple("_Result", "width height depth glyphs rects")

def __init__(self):
super().__init__()
self.glyphs = []
self.rects = []

Expand Down Expand Up @@ -320,6 +324,7 @@ class MathtextBackendCairo(MathtextBackend):
"""

def __init__(self):
super().__init__()
self.glyphs = []
self.rects = []

Expand Down
11 changes: 6 additions & 5 deletions lib/matplotlib/textpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import numpy as np

from matplotlib import _text_helpers, dviread, font_manager, rcParams
from matplotlib import _text_helpers, dviread, font_manager
from matplotlib.font_manager import FontProperties, get_font
from matplotlib.ft2font import LOAD_NO_HINTING, LOAD_TARGET_LIGHT
from matplotlib.mathtext import MathTextParser
Expand Down Expand Up @@ -385,11 +385,11 @@ def __init__(self, xy, s, size=None, prop=None,

self._cached_vertices = None
s, ismath = Text(usetex=usetex)._preprocess_math(s)
self._vertices, self._codes = text_to_path.get_text_path(
prop, s, ismath=ismath)
super().__init__(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps rather use fast_from_codes_and_verts for speed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a class method / constructor, though?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes. Oh well, I guess this isn't a bottleneck...

*text_to_path.get_text_path(prop, s, ismath=ismath),
_interpolation_steps=_interpolation_steps,
readonly=True)
self._should_simplify = False
self._simplify_threshold = rcParams['path.simplify_threshold']
self._interpolation_steps = _interpolation_steps

def set_size(self, size):
"""Set the text size."""
Expand Down Expand Up @@ -427,4 +427,5 @@ def _revalidate_path(self):
.scale(self._size / text_to_path.FONT_SCALE)
.translate(*self._xy))
self._cached_vertices = tr.transform(self._vertices)
self._cached_vertices.flags.writeable = False
self._invalid = False
0