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

Skip to content

Commit cc62eba

Browse files
committed
Remove mutable defaults from tool manager functions
This is generally frowned upon (though we don't actually change it, so it's safe), but more importantly, Sphinx tries to put all the values into the docstring, which just looks bad.
1 parent c77a979 commit cc62eba

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

lib/matplotlib/backend_tools.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ def trigger(self, *args, **kwargs):
934934
self.toolmanager.message_event(message, self)
935935

936936

937+
#: The default tools to add to a tool manager.
937938
default_tools = {'home': ToolHome, 'back': ToolBack, 'forward': ToolForward,
938939
'zoom': ToolZoom, 'pan': ToolPan,
939940
'subplots': ConfigureSubplotsBase,
@@ -953,12 +954,13 @@ def trigger(self, *args, **kwargs):
953954
'copy': ToolCopyToClipboardBase,
954955
}
955956

957+
#: The default tools to add to a container.
956958
default_toolbar_tools = [['navigation', ['home', 'back', 'forward']],
957959
['zoompan', ['pan', 'zoom', 'subplots']],
958960
['io', ['save', 'help']]]
959961

960962

961-
def add_tools_to_manager(toolmanager, tools=default_tools):
963+
def add_tools_to_manager(toolmanager, tools=None):
962964
"""
963965
Add multiple tools to a `.ToolManager`.
964966
@@ -968,14 +970,16 @@ def add_tools_to_manager(toolmanager, tools=default_tools):
968970
Manager to which the tools are added.
969971
tools : {str: class_like}, optional
970972
The tools to add in a {name: tool} dict, see
971-
`.backend_managers.ToolManager.add_tool` for more info.
973+
`.backend_managers.ToolManager.add_tool` for more info. If not specified, then
974+
defaults to `.default_tools`.
972975
"""
973-
976+
if tools is None:
977+
tools = default_tools
974978
for name, tool in tools.items():
975979
toolmanager.add_tool(name, tool)
976980

977981

978-
def add_tools_to_container(container, tools=default_toolbar_tools):
982+
def add_tools_to_container(container, tools=None):
979983
"""
980984
Add multiple tools to the container.
981985
@@ -987,9 +991,11 @@ def add_tools_to_container(container, tools=default_toolbar_tools):
987991
tools : list, optional
988992
List in the form ``[[group1, [tool1, tool2 ...]], [group2, [...]]]``
989993
where the tools ``[tool1, tool2, ...]`` will display in group1.
990-
See `.backend_bases.ToolContainerBase.add_tool` for details.
994+
See `.backend_bases.ToolContainerBase.add_tool` for details. If not specified,
995+
then defaults to `.default_toolbar_tools`.
991996
"""
992-
997+
if tools is None:
998+
tools = default_toolbar_tools
993999
for group, grouptools in tools:
9941000
for position, tool in enumerate(grouptools):
9951001
container.add_tool(tool, group, position)

0 commit comments

Comments
 (0)