Skip to content

Commit 9152039

Browse files
committed
Automatically determine whether to suggest options
1 parent a0b131d commit 9152039

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed

lib/matplotlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ def __setitem__(self, key, val):
741741
and "backend" in self):
742742
return
743743
valid_key = _api.check_getitem(
744-
self.validate, rcParam=key, _suggest_close_matches=True, _error_cls=KeyError
744+
self.validate, rcParam=key, _error_cls=KeyError
745745
)
746746
try:
747747
cval = valid_key(val)

lib/matplotlib/_api/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def check_shape(shape, /, **kwargs):
176176

177177

178178
def check_getitem(
179-
mapping, /, _suggest_close_matches=False, _error_cls=ValueError, **kwargs
179+
mapping, /, _error_cls=ValueError, **kwargs
180180
):
181181
"""
182182
*kwargs* must consist of a single *key, value* pair. If *key* is in
@@ -185,8 +185,6 @@ def check_getitem(
185185
186186
Parameters
187187
----------
188-
_suggest_close_matches :
189-
If True, suggest only close matches instead of all valid values.
190188
_error_cls :
191189
Class of error to raise.
192190
@@ -200,7 +198,7 @@ def check_getitem(
200198
try:
201199
return mapping[v]
202200
except KeyError:
203-
if _suggest_close_matches:
201+
if len(mapping) > 5:
204202
if len(best := difflib.get_close_matches(v, mapping.keys(), cutoff=0.5)):
205203
suggestion = f"Did you mean one of {best}?"
206204
else:

lib/matplotlib/_api/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def check_in_list(
4343
) -> None: ...
4444
def check_shape(shape: tuple[int | None, ...], /, **kwargs: NDArray) -> None: ...
4545
def check_getitem(
46-
mapping: Mapping[Any, _T], /, _suggest_close_matches: bool, _error_cls: Type[Exception], **kwargs: Any
46+
mapping: Mapping[Any, _T], /, _error_cls: Type[Exception], **kwargs: Any
4747
) -> _T: ...
4848
def caching_module_getattr(cls: type) -> Callable[[str], Any]: ...
4949
@overload

lib/matplotlib/cm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def __init__(self, cmaps):
9393

9494
def __getitem__(self, item):
9595
cmap = _api.check_getitem(
96-
self._cmaps, colormap=item, _suggest_close_matches=True, _error_cls=KeyError
96+
self._cmaps, colormap=item, _error_cls=KeyError
9797
)
9898
return cmap.copy()
9999

0 commit comments

Comments
 (0)