Skip to content
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
2 changes: 1 addition & 1 deletion lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ def __setitem__(self, key, val):
and val is rcsetup._auto_backend_sentinel
and "backend" in self):
return
valid_key = _api.check_getitem(
valid_key = _api.getitem_checked(
self.validate, rcParam=key, _error_cls=KeyError
)
try:
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def check_shape(shape, /, **kwargs):
)


def check_getitem(mapping, /, _error_cls=ValueError, **kwargs):
def getitem_checked(mapping, /, _error_cls=ValueError, **kwargs):
"""
*kwargs* must consist of a single *key, value* pair. If *key* is in
*mapping*, return ``mapping[value]``; else, raise an appropriate
Expand All @@ -202,10 +202,10 @@ def check_getitem(mapping, /, _error_cls=ValueError, **kwargs):

Examples
--------
>>> _api.check_getitem({"foo": "bar"}, arg=arg)
>>> _api.getitem_checked({"foo": "bar"}, arg=arg)
"""
if len(kwargs) != 1:
raise ValueError("check_getitem takes a single keyword argument")
raise ValueError("getitem_checked takes a single keyword argument")
(k, v), = kwargs.items()
try:
return mapping[v]
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/_api/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def check_in_list(
values: Sequence[Any], /, *, _print_supported_values: bool = ..., **kwargs: Any
) -> None: ...
def check_shape(shape: tuple[int | None, ...], /, **kwargs: NDArray) -> None: ...
def check_getitem(
def getitem_checked(
mapping: Mapping[Any, _T], /, _error_cls: type[Exception], **kwargs: Any
) -> _T: ...
def caching_module_getattr(cls: type) -> Callable[[str], Any]: ...
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/_type1font.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def _decrypt(ciphertext, key, ndiscard=4):
That number of bytes is discarded from the beginning of plaintext.
"""

key = _api.check_getitem({'eexec': 55665, 'charstring': 4330}, key=key)
key = _api.getitem_checked({'eexec': 55665, 'charstring': 4330}, key=key)
plaintext = []
for byte in ciphertext:
plaintext.append(byte ^ (key >> 8))
Expand All @@ -483,7 +483,7 @@ def _encrypt(plaintext, key, ndiscard=4):
cryptanalysis.
"""

key = _api.check_getitem({'eexec': 55665, 'charstring': 4330}, key=key)
key = _api.getitem_checked({'eexec': 55665, 'charstring': 4330}, key=key)
ciphertext = []
for byte in b'\0' * ndiscard + plaintext:
c = byte ^ (key >> 8)
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def get_title(self, loc="center"):
titles = {'left': self._left_title,
'center': self.title,
'right': self._right_title}
title = _api.check_getitem(titles, loc=loc.lower())
title = _api.getitem_checked(titles, loc=loc.lower())
return title.get_text()

def set_title(self, label, fontdict=None, loc=None, pad=None, *, y=None,
Expand Down Expand Up @@ -199,7 +199,7 @@ def set_title(self, label, fontdict=None, loc=None, pad=None, *, y=None,
titles = {'left': self._left_title,
'center': self.title,
'right': self._right_title}
title = _api.check_getitem(titles, loc=loc)
title = _api.getitem_checked(titles, loc=loc)
default = {
'fontsize': mpl.rcParams['axes.titlesize'],
'fontweight': mpl.rcParams['axes.titleweight'],
Expand Down Expand Up @@ -8275,7 +8275,7 @@ def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None,
pad_to=pad_to, sides=sides)
freqs += Fc

yunits = _api.check_getitem(
yunits = _api.getitem_checked(
{None: 'energy', 'default': 'energy', 'linear': 'energy',
'dB': 'dB'},
scale=scale)
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ def _request_autoscale_view(self, axis="all", tight=None):
Either an element of ``self._axis_names``, or "all".
tight : bool or None, default: None
"""
axis_names = _api.check_getitem(
axis_names = _api.getitem_checked(
{**{k: [k] for k in self._axis_names}, "all": self._axis_names},
axis=axis)
for name in axis_names:
Expand Down Expand Up @@ -3426,10 +3426,10 @@ def ticklabel_format(self, *, axis='both', style=None, scilimits=None,
) from err
STYLES = {'sci': True, 'scientific': True, 'plain': False, '': None, None: None}
# The '' option is included for backwards-compatibility.
is_sci_style = _api.check_getitem(STYLES, style=style)
is_sci_style = _api.getitem_checked(STYLES, style=style)
axis_map = {**{k: [v] for k, v in self._axis_map.items()},
'both': list(self._axis_map.values())}
axises = _api.check_getitem(axis_map, axis=axis)
axises = _api.getitem_checked(axis_map, axis=axis)
try:
for axis in axises:
if is_sci_style is not None:
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2451,7 +2451,7 @@ def set_label_position(self, position):
----------
position : {'top', 'bottom'}
"""
self.label.set_verticalalignment(_api.check_getitem({
self.label.set_verticalalignment(_api.getitem_checked({
'top': 'baseline', 'bottom': 'top',
}, position=position))
self.label_position = position
Expand Down Expand Up @@ -2678,7 +2678,7 @@ def set_label_position(self, position):
position : {'left', 'right'}
"""
self.label.set_rotation_mode('anchor')
self.label.set_verticalalignment(_api.check_getitem({
self.label.set_verticalalignment(_api.getitem_checked({
'left': 'bottom', 'right': 'top',
}, position=position))
self.label_position = position
Expand Down Expand Up @@ -2733,7 +2733,7 @@ def set_offset_position(self, position):
position : {'left', 'right'}
"""
x, y = self.offsetText.get_position()
x = _api.check_getitem({'left': 0, 'right': 1}, position=position)
x = _api.getitem_checked({'left': 0, 'right': 1}, position=position)

self.offsetText.set_ha(position)
self.offsetText.set_position((x, y))
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/_backend_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _create_application():


def mpl_to_gtk_cursor_name(mpl_cursor):
return _api.check_getitem({
return _api.getitem_checked({
Cursors.MOVE: "move",
Cursors.HAND: "pointer",
Cursors.POINTER: "default",
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def get_antialiased(self):
return self.ctx.get_antialias()

def set_capstyle(self, cs):
self.ctx.set_line_cap(_api.check_getitem(self._capd, capstyle=cs))
self.ctx.set_line_cap(_api.getitem_checked(self._capd, capstyle=cs))
self._capstyle = cs

def set_clip_rectangle(self, rectangle):
Expand Down Expand Up @@ -385,7 +385,7 @@ def get_rgb(self):
return self.ctx.get_source().get_rgba()[:3]

def set_joinstyle(self, js):
self.ctx.set_line_join(_api.check_getitem(self._joind, joinstyle=js))
self.ctx.set_line_join(_api.getitem_checked(self._joind, joinstyle=js))
self._joinstyle = js

def set_linewidth(self, w):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ def _print_ps(
papertype = papertype.lower()
_api.check_in_list(['figure', *papersize], papertype=papertype)

orientation = _api.check_getitem(
orientation = _api.getitem_checked(
_Orientation, orientation=orientation.lower())

printer = (self._print_figure_tex
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def showEvent(self, event):

def set_cursor(self, cursor):
# docstring inherited
self.setCursor(_api.check_getitem(cursord, cursor=cursor))
self.setCursor(_api.getitem_checked(cursord, cursor=cursor))

def mouseEventCoords(self, pos=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_webagg_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def draw_idle(self):

def set_cursor(self, cursor):
# docstring inherited
cursor = _api.check_getitem({
cursor = _api.getitem_checked({
backend_tools.Cursors.HAND: 'pointer',
backend_tools.Cursors.POINTER: 'default',
backend_tools.Cursors.SELECT_REGION: 'crosshair',
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ def _on_key_up(self, event):

def set_cursor(self, cursor):
# docstring inherited
cursor = wx.Cursor(_api.check_getitem({
cursor = wx.Cursor(_api.getitem_checked({
cursors.MOVE: wx.CURSOR_HAND,
cursors.HAND: wx.CURSOR_HAND,
cursors.POINTER: wx.CURSOR_ARROW,
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(self, cmaps):
self._builtin_cmaps = tuple(cmaps)

def __getitem__(self, item):
cmap = _api.check_getitem(self._cmaps, colormap=item, _error_cls=KeyError)
cmap = _api.getitem_checked(self._cmaps, colormap=item, _error_cls=KeyError)
return cmap.copy()

def __iter__(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -2004,7 +2004,7 @@ def set_orientation(self, orientation):
----------
orientation : {'horizontal', 'vertical'}
"""
is_horizontal = _api.check_getitem(
is_horizontal = _api.getitem_checked(
{"horizontal": True, "vertical": False},
orientation=orientation)
if is_horizontal == self.is_horizontal():
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def __init__(
self.values = values
self.boundaries = boundaries
self.extend = extend
self._inside = _api.check_getitem(
self._inside = _api.getitem_checked(
{'neither': slice(0, None), 'both': slice(1, -1),
'min': slice(1, None), 'max': slice(0, -1)},
extend=extend)
Expand Down Expand Up @@ -1340,7 +1340,7 @@ def drag_pan(self, button, key, x, y):
def _normalize_location_orientation(location, orientation):
if location is None:
location = _get_ticklocation_from_orientation(orientation)
loc_settings = _api.check_getitem({
loc_settings = _api.getitem_checked({
"left": {"location": "left", "anchor": (1.0, 0.5),
"panchor": (0.0, 0.5), "pad": 0.10},
"right": {"location": "right", "anchor": (0.0, 0.5),
Expand All @@ -1358,13 +1358,13 @@ def _normalize_location_orientation(location, orientation):


def _get_orientation_from_location(location):
return _api.check_getitem(
return _api.getitem_checked(
{None: None, "left": "vertical", "right": "vertical",
"top": "horizontal", "bottom": "horizontal"}, location=location)


def _get_ticklocation_from_orientation(orientation):
return _api.check_getitem(
return _api.getitem_checked(
{None: "right", "vertical": "right", "horizontal": "bottom"},
orientation=orientation)

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def _ensure_norm(norm, n_components=1):
if norm is None:
norm = colors.Normalize()
elif isinstance(norm, str):
scale_cls = _api.check_getitem(scale._scale_mapping, norm=norm)
scale_cls = _api.getitem_checked(scale._scale_mapping, norm=norm)
return _auto_norm_from_scale(scale_cls)()
return norm
elif n_components > 1:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3371,7 +3371,7 @@ def __init__(self, norms, vmin=None, vmax=None, clip=None):

def resolve(norm):
if isinstance(norm, str):
scale_cls = _api.check_getitem(scale._scale_mapping, norm=norm)
scale_cls = _api.getitem_checked(scale._scale_mapping, norm=norm)
return mpl.colorizer._auto_norm_from_scale(scale_cls)()
elif isinstance(norm, Normalize):
return norm
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def set_loc(self, loc=None):
locs = locs[::-1]
loc = locs[0] + ' ' + locs[1]
# check that loc is in acceptable strings
loc = _api.check_getitem(self.codes, loc=loc)
loc = _api.getitem_checked(self.codes, loc=loc)
elif np.iterable(loc):
# coerce iterable into tuple
loc = tuple(loc)
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, output):
Whether to return a `VectorParse` ("path") or a
`RasterParse` ("agg", or its synonym "macosx").
"""
self._output_type = _api.check_getitem(
self._output_type = _api.getitem_checked(
{"path": "vector", "agg": "raster", "macosx": "raster"},
output=output.lower())

Expand Down Expand Up @@ -89,7 +89,7 @@ def parse(self, s, dpi=72, prop=None, *, antialiased=None):
def _parse_cached(self, s, dpi, prop, antialiased, load_glyph_flags):
if prop is None:
prop = FontProperties()
fontset_class = _api.check_getitem(
fontset_class = _api.getitem_checked(
self._font_type_mapping, fontset=prop.get_math_fontfamily())
fontset = fontset_class(prop, load_glyph_flags)
fontsize = prop.get_size_in_points()
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ def __init__(self, loc, *,
self.set_child(child)

if isinstance(loc, str):
loc = _api.check_getitem(self.codes, loc=loc)
loc = _api.getitem_checked(self.codes, loc=loc)

self.loc = loc
self.borderpad = borderpad
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def draw(self, renderer):

def _set_transform(self):
fig = self.Q.axes.get_figure(root=False)
self.set_transform(_api.check_getitem({
self.set_transform(_api.getitem_checked({
"data": self.Q.axes.transData,
"axes": self.Q.axes.transAxes,
"figure": fig.transFigure,
Expand Down Expand Up @@ -614,7 +614,7 @@ def _dots_per_unit(self, units):
"""Return a scale factor for converting from units to pixels."""
bb = self.axes.bbox
vl = self.axes.viewLim
return _api.check_getitem({
return _api.getitem_checked({
'x': bb.width / vl.width,
'y': bb.height / vl.height,
'xy': np.hypot(*bb.size) / np.hypot(*vl.size),
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def __init__(self, base, nonpositive='clip'):
if base <= 0 or base == 1:
raise ValueError('The log base cannot be <= 0 or == 1')
self.base = base
self._clip = _api.check_getitem(
self._clip = _api.getitem_checked(
{"clip": True, "mask": False}, nonpositive=nonpositive)

def __str__(self):
Expand Down Expand Up @@ -838,7 +838,7 @@ def scale_factory(scale, axis, **kwargs):
scale : {%(names)s}
axis : `~matplotlib.axis.Axis`
"""
scale_cls = _api.check_getitem(_scale_mapping, scale=scale)
scale_cls = _api.getitem_checked(_scale_mapping, scale=scale)

if _scale_has_axis_parameter[scale]:
return scale_cls(axis, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/testing/jpl_units/UnitDbl.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, value, units):
- value The numeric value of the UnitDbl.
- units The string name of the units the value is in.
"""
data = _api.check_getitem(self.allowed, units=units)
data = _api.getitem_checked(self.allowed, units=units)
self._value = float(value * data[0])
self._units = data[1]

Expand All @@ -69,7 +69,7 @@ def convert(self, units):
"""
if self._units == units:
return self._value
data = _api.check_getitem(self.allowed, units=units)
data = _api.getitem_checked(self.allowed, units=units)
if self._units != data[1]:
raise ValueError(f"Error trying to convert to different units.\n"
f" Invalid conversion requested.\n"
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ def __init__(self, ax, label, initial='', *,
"""
super().__init__(ax)

self._text_position = _api.check_getitem(
self._text_position = _api.getitem_checked(
{"left": 0.05, "center": 0.5, "right": 0.95},
textalignment=textalignment)

Expand Down
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/axes_grid1/axes_divider.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def append_axes(self, position, size, pad=None, *, axes_class=None,
**kwargs
All extra keywords arguments are passed to the created axes.
"""
create_axes, pack_start = _api.check_getitem({
create_axes, pack_start = _api.getitem_checked({
"left": (self.new_horizontal, True),
"right": (self.new_horizontal, False),
"bottom": (self.new_vertical, True),
Expand Down
Loading
Loading