google-code-export / pyglet

Automatically exported from code.google.com/p/pyglet
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

remove_handler does not remove handler #665

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pyglet

class X(pyglet.event.EventDispatcher):
    def __init__(self):
        self.register_event_type('banana')
        self.set_handler('banana', self.banana)
        self.remove_handler('banana', self.banana)
        self.dispatch_event('banana')

    def banana(self):
        print "doppleganger"

x = X()

Paste in the traceback or error message:

$ ./woota.py
doppleganger
doppleganger

pyglet 1.1 with Python 2.5: Paste in the output of `python -m pyglet.info`
Other: Paste in the output of tools/gl_info.py (included in source distro):

Any additional info (platform/language/hardware) that may be relevant?

around line 315, function remove_handler uses the "is" operator to compare the 
function that should be removed with the functions in the frames. "is" uses 
id(), and that doesnt work: http://codepad.org/eFMRxIuO

Original issue reported on code.google.com by running....@gmail.com on 25 Sep 2013 at 10:59

GoogleCodeExporter commented 9 years ago
Confirmed with Python 2.7.

Original comment by useboxnet on 26 Sep 2013 at 5:18

GoogleCodeExporter commented 9 years ago
This happens because your `banana` is a bound method, with a function it works 
properly.

frame[name] is handler, frame[name] == handler

In func is True, True, in a bound method is False, True.

Using a static method for your banana you'll get the desired effect (it's just 
a function).

I can't see a good reason to use "is" instead of "==".

Original comment by useboxnet on 26 Sep 2013 at 5:31

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 6c4ce5fb7198.

Original comment by useboxnet on 26 Sep 2013 at 5:35