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

Skip to content

Deprecate passing keys to update_keymap as single comma-separated string #17394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2020
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
4 changes: 4 additions & 0 deletions doc/api/api_changes_3.3/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This is deprecated; pass keys as a list of strings instead.
This is deprecated; pass keys as a single string or a list of strings instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought "single string" was too confusing (as it used to be a single string before too... I guess it should be "single string if you're only passing a single key", but heh) and just documenting "list of strings" here was good enough (even though we support the single string option too).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, since this is just the deprecation notice and not the reference docstring, the imprecision is tolerable 😄 .

21 changes: 14 additions & 7 deletions lib/matplotlib/backend_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,32 @@ 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.

Parameters
----------
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))
Expand Down