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

Skip to content

Commit 22eade6

Browse files
authored
Merge pull request #17394 from anntzer/update_keymap
Deprecate passing keys to update_keymap as single comma-separated string
2 parents 8bddf0a + 6e6fe87 commit 22eade6

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

doc/api/api_changes_3.3/deprecations.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,7 @@ in which they are given. This only affects the interaction between the
555555
properties: the *color* property now needs to be passed first in order not to
556556
override the other properties. This is consistent with e.g. `.Artist.update`,
557557
which did not reorder the properties passed to it.
558+
559+
Passing multiple keys as a single comma-separated string or multiple arguments to `.ToolManager.update_keymap`
560+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
561+
This is deprecated; pass keys as a list of strings instead.

lib/matplotlib/backend_managers.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,25 +183,32 @@ def _remove_keys(self, name):
183183
for k in self.get_tool_keymap(name):
184184
del self._keys[k]
185185

186-
def update_keymap(self, name, *keys):
186+
@cbook._delete_parameter("3.3", "args")
187+
def update_keymap(self, name, key, *args):
187188
"""
188189
Set the keymap to associate with the specified tool.
189190
190191
Parameters
191192
----------
192193
name : str
193194
Name of the Tool.
194-
keys : list of str
195+
keys : str or list of str
195196
Keys to associate with the tool.
196197
"""
197-
198198
if name not in self._tools:
199199
raise KeyError('%s not in Tools' % name)
200-
201200
self._remove_keys(name)
202-
203-
for key in keys:
204-
for k in validate_stringlist(key):
201+
for key in [key, *args]:
202+
if isinstance(key, str) and validate_stringlist(key) != [key]:
203+
cbook.warn_deprecated(
204+
"3.3", message="Passing a list of keys as a single "
205+
"comma-separated string is deprecated since %(since)s and "
206+
"support will be removed %(removal)s; pass keys as a list "
207+
"of strings instead.")
208+
key = validate_stringlist(key)
209+
if isinstance(key, str):
210+
key = [key]
211+
for k in key:
205212
if k in self._keys:
206213
cbook._warn_external('Key %s changed from %s to %s' %
207214
(k, self._keys[k], name))

0 commit comments

Comments
 (0)