diff --git a/doc/api/api_changes_3.3/deprecations.rst b/doc/api/api_changes_3.3/deprecations.rst index 5635c5f73c86..06b454a44a0a 100644 --- a/doc/api/api_changes_3.3/deprecations.rst +++ b/doc/api/api_changes_3.3/deprecations.rst @@ -554,3 +554,7 @@ in which they are given. This only affects the interaction between the properties: the *color* property now needs to be passed first in order not to override the other properties. This is consistent with e.g. `.Artist.update`, which did not reorder the properties passed to it. + +Passing multiple keys as a single comma-separated string or multiple arguments to `.ToolManager.update_keymap` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +This is deprecated; pass keys as a list of strings instead. diff --git a/lib/matplotlib/backend_managers.py b/lib/matplotlib/backend_managers.py index 375182d2efdf..c59c3c65ec06 100644 --- a/lib/matplotlib/backend_managers.py +++ b/lib/matplotlib/backend_managers.py @@ -183,7 +183,8 @@ def _remove_keys(self, name): for k in self.get_tool_keymap(name): del self._keys[k] - def update_keymap(self, name, *keys): + @cbook._delete_parameter("3.3", "args") + def update_keymap(self, name, key, *args): """ Set the keymap to associate with the specified tool. @@ -191,17 +192,23 @@ def update_keymap(self, name, *keys): ---------- name : str Name of the Tool. - keys : list of str + keys : str or list of str Keys to associate with the tool. """ - if name not in self._tools: raise KeyError('%s not in Tools' % name) - self._remove_keys(name) - - for key in keys: - for k in validate_stringlist(key): + for key in [key, *args]: + if isinstance(key, str) and validate_stringlist(key) != [key]: + cbook.warn_deprecated( + "3.3", message="Passing a list of keys as a single " + "comma-separated string is deprecated since %(since)s and " + "support will be removed %(removal)s; pass keys as a list " + "of strings instead.") + key = validate_stringlist(key) + if isinstance(key, str): + key = [key] + for k in key: if k in self._keys: cbook._warn_external('Key %s changed from %s to %s' % (k, self._keys[k], name))