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

Skip to content

Commit c1e4831

Browse files
authored
Merge pull request #31082 from timhoffm/getitem_checked
MNT: Rename check_getitem to getitem_checked
2 parents 607d2c3 + 325a0dd commit c1e4831

31 files changed

Lines changed: 51 additions & 51 deletions

lib/matplotlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ def __setitem__(self, key, val):
748748
and val is rcsetup._auto_backend_sentinel
749749
and "backend" in self):
750750
return
751-
valid_key = _api.check_getitem(
751+
valid_key = _api.getitem_checked(
752752
self.validate, rcParam=key, _error_cls=KeyError
753753
)
754754
try:

lib/matplotlib/_api/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def check_shape(shape, /, **kwargs):
189189
)
190190

191191

192-
def check_getitem(mapping, /, _error_cls=ValueError, **kwargs):
192+
def getitem_checked(mapping, /, _error_cls=ValueError, **kwargs):
193193
"""
194194
*kwargs* must consist of a single *key, value* pair. If *key* is in
195195
*mapping*, return ``mapping[value]``; else, raise an appropriate
@@ -202,10 +202,10 @@ def check_getitem(mapping, /, _error_cls=ValueError, **kwargs):
202202
203203
Examples
204204
--------
205-
>>> _api.check_getitem({"foo": "bar"}, arg=arg)
205+
>>> _api.getitem_checked({"foo": "bar"}, arg=arg)
206206
"""
207207
if len(kwargs) != 1:
208-
raise ValueError("check_getitem takes a single keyword argument")
208+
raise ValueError("getitem_checked takes a single keyword argument")
209209
(k, v), = kwargs.items()
210210
try:
211211
return mapping[v]

lib/matplotlib/_api/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def check_in_list(
4242
values: Sequence[Any], /, *, _print_supported_values: bool = ..., **kwargs: Any
4343
) -> None: ...
4444
def check_shape(shape: tuple[int | None, ...], /, **kwargs: NDArray) -> None: ...
45-
def check_getitem(
45+
def getitem_checked(
4646
mapping: Mapping[Any, _T], /, _error_cls: type[Exception], **kwargs: Any
4747
) -> _T: ...
4848
def caching_module_getattr(cls: type) -> Callable[[str], Any]: ...

lib/matplotlib/_type1font.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def _decrypt(ciphertext, key, ndiscard=4):
458458
That number of bytes is discarded from the beginning of plaintext.
459459
"""
460460

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

486-
key = _api.check_getitem({'eexec': 55665, 'charstring': 4330}, key=key)
486+
key = _api.getitem_checked({'eexec': 55665, 'charstring': 4330}, key=key)
487487
ciphertext = []
488488
for byte in b'\0' * ndiscard + plaintext:
489489
c = byte ^ (key >> 8)

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def get_title(self, loc="center"):
132132
titles = {'left': self._left_title,
133133
'center': self.title,
134134
'right': self._right_title}
135-
title = _api.check_getitem(titles, loc=loc.lower())
135+
title = _api.getitem_checked(titles, loc=loc.lower())
136136
return title.get_text()
137137

138138
def set_title(self, label, fontdict=None, loc=None, pad=None, *, y=None,
@@ -199,7 +199,7 @@ def set_title(self, label, fontdict=None, loc=None, pad=None, *, y=None,
199199
titles = {'left': self._left_title,
200200
'center': self.title,
201201
'right': self._right_title}
202-
title = _api.check_getitem(titles, loc=loc)
202+
title = _api.getitem_checked(titles, loc=loc)
203203
default = {
204204
'fontsize': mpl.rcParams['axes.titlesize'],
205205
'fontweight': mpl.rcParams['axes.titleweight'],
@@ -8275,7 +8275,7 @@ def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None,
82758275
pad_to=pad_to, sides=sides)
82768276
freqs += Fc
82778277

8278-
yunits = _api.check_getitem(
8278+
yunits = _api.getitem_checked(
82798279
{None: 'energy', 'default': 'energy', 'linear': 'energy',
82808280
'dB': 'dB'},
82818281
scale=scale)

lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ def _request_autoscale_view(self, axis="all", tight=None):
904904
Either an element of ``self._axis_names``, or "all".
905905
tight : bool or None, default: None
906906
"""
907-
axis_names = _api.check_getitem(
907+
axis_names = _api.getitem_checked(
908908
{**{k: [k] for k in self._axis_names}, "all": self._axis_names},
909909
axis=axis)
910910
for name in axis_names:
@@ -3426,10 +3426,10 @@ def ticklabel_format(self, *, axis='both', style=None, scilimits=None,
34263426
) from err
34273427
STYLES = {'sci': True, 'scientific': True, 'plain': False, '': None, None: None}
34283428
# The '' option is included for backwards-compatibility.
3429-
is_sci_style = _api.check_getitem(STYLES, style=style)
3429+
is_sci_style = _api.getitem_checked(STYLES, style=style)
34303430
axis_map = {**{k: [v] for k, v in self._axis_map.items()},
34313431
'both': list(self._axis_map.values())}
3432-
axises = _api.check_getitem(axis_map, axis=axis)
3432+
axises = _api.getitem_checked(axis_map, axis=axis)
34333433
try:
34343434
for axis in axises:
34353435
if is_sci_style is not None:

lib/matplotlib/axis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,7 +2451,7 @@ def set_label_position(self, position):
24512451
----------
24522452
position : {'top', 'bottom'}
24532453
"""
2454-
self.label.set_verticalalignment(_api.check_getitem({
2454+
self.label.set_verticalalignment(_api.getitem_checked({
24552455
'top': 'baseline', 'bottom': 'top',
24562456
}, position=position))
24572457
self.label_position = position
@@ -2678,7 +2678,7 @@ def set_label_position(self, position):
26782678
position : {'left', 'right'}
26792679
"""
26802680
self.label.set_rotation_mode('anchor')
2681-
self.label.set_verticalalignment(_api.check_getitem({
2681+
self.label.set_verticalalignment(_api.getitem_checked({
26822682
'left': 'bottom', 'right': 'top',
26832683
}, position=position))
26842684
self.label_position = position
@@ -2733,7 +2733,7 @@ def set_offset_position(self, position):
27332733
position : {'left', 'right'}
27342734
"""
27352735
x, y = self.offsetText.get_position()
2736-
x = _api.check_getitem({'left': 0, 'right': 1}, position=position)
2736+
x = _api.getitem_checked({'left': 0, 'right': 1}, position=position)
27372737

27382738
self.offsetText.set_ha(position)
27392739
self.offsetText.set_position((x, y))

lib/matplotlib/backends/_backend_gtk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _create_application():
6767

6868

6969
def mpl_to_gtk_cursor_name(mpl_cursor):
70-
return _api.check_getitem({
70+
return _api.getitem_checked({
7171
Cursors.MOVE: "move",
7272
Cursors.HAND: "pointer",
7373
Cursors.POINTER: "default",

lib/matplotlib/backends/backend_cairo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def get_antialiased(self):
342342
return self.ctx.get_antialias()
343343

344344
def set_capstyle(self, cs):
345-
self.ctx.set_line_cap(_api.check_getitem(self._capd, capstyle=cs))
345+
self.ctx.set_line_cap(_api.getitem_checked(self._capd, capstyle=cs))
346346
self._capstyle = cs
347347

348348
def set_clip_rectangle(self, rectangle):
@@ -385,7 +385,7 @@ def get_rgb(self):
385385
return self.ctx.get_source().get_rgba()[:3]
386386

387387
def set_joinstyle(self, js):
388-
self.ctx.set_line_join(_api.check_getitem(self._joind, joinstyle=js))
388+
self.ctx.set_line_join(_api.getitem_checked(self._joind, joinstyle=js))
389389
self._joinstyle = js
390390

391391
def set_linewidth(self, w):

lib/matplotlib/backends/backend_ps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ def _print_ps(
989989
papertype = papertype.lower()
990990
_api.check_in_list(['figure', *papersize], papertype=papertype)
991991

992-
orientation = _api.check_getitem(
992+
orientation = _api.getitem_checked(
993993
_Orientation, orientation=orientation.lower())
994994

995995
printer = (self._print_figure_tex

0 commit comments

Comments
 (0)