Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

adding str to force string in format #5514

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
Nov 19, 2015

Conversation

fariza
Copy link
Member

@fariza fariza commented Nov 19, 2015

When running the example toolmanager with python 3.5 and using the option m to list the shortcuts

The following error appears.

Traceback (most recent call last):
  File "/home/fede/workspace/matplotlib/lib/matplotlib/backends/backend_gtk3.py", line 253, in key_press_event
    FigureCanvasBase.key_press_event(self, key, guiEvent=event)
  File "/home/fede/workspace/matplotlib/lib/matplotlib/backend_bases.py", line 1847, in key_press_event
    self.callbacks.process(s, event)
  File "/home/fede/workspace/matplotlib/lib/matplotlib/cbook.py", line 549, in process
    proxy(*args, **kwargs)
  File "/home/fede/workspace/matplotlib/lib/matplotlib/cbook.py", line 416, in __call__
    return mtd(*args, **kwargs)
  File "/home/fede/workspace/matplotlib/lib/matplotlib/backend_managers.py", line 369, in _key_press
    self.trigger_tool(name, canvasevent=event)
  File "/home/fede/workspace/matplotlib/lib/matplotlib/backend_managers.py", line 341, in trigger_tool
    self._trigger_tool(name, sender, canvasevent, data)
  File "/home/fede/workspace/matplotlib/lib/matplotlib/backend_managers.py", line 360, in _trigger_tool
    tool.trigger(sender, canvasevent, data)
  File "examples/user_interfaces/toolmanager.py", line 44, in trigger
    print("{0:12} {1:45}".format(group, active))
TypeError: non-empty format string passed to object.__format__

This PR corrects this problem by forcing a string casting on the key value to be displayed

@mdboom mdboom added this to the Critical bugfix release (1.5.1) milestone Nov 19, 2015
@WeatherGod
Copy link
Member

wouldn't it make more sense for the objects to properly format themselves?

@fariza
Copy link
Member Author

fariza commented Nov 19, 2015

The active_toggle dict can contain None: set() as key and value.

As I can see, the only way to avoid that is to add a __format__ method to the object, and I don't see an easy way of doing it.

@WeatherGod
Copy link
Member

Ah, right... drats. Would it make sense to test if the object has a
__format__ method before casting as string? Or even to test that the key
is None ans special-case that? Or maybe we should decide if the only valid
keys should be either None or a string? If we decide that, then it makes
sense to force-cast the None to a string here.

On Thu, Nov 19, 2015 at 2:22 PM, Federico Ariza notifications@github.com
wrote:

The active_toggle dict can contain None: set() as key and value.

As I can see, the only way to avoid that is to add a format method to
the object, and I don't see an easy way of doing it.


Reply to this email directly or view it on GitHub
#5514 (comment)
.

@fariza
Copy link
Member Author

fariza commented Nov 19, 2015

That would make the example more complex than it is, and it is not relevant for what we are trying to show.

My idea was to use this example as starting point to create a "F1" or something like that, containing all the shortcuts. If we get to that point, there we can make all those exceptions, but here it seems overkill.

@WeatherGod
Copy link
Member

Ah, right... I am definitely overthinking this. Merging...

WeatherGod added a commit that referenced this pull request Nov 19, 2015
adding str to force string in format
@WeatherGod WeatherGod merged commit 9413188 into matplotlib:master Nov 19, 2015
@fariza fariza deleted the string-format-example branch May 17, 2016 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.