Skip to content
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

Fix traitlet _notify_trait by-ref issue #4412

Merged
merged 2 commits into from Oct 21, 2013

Conversation

jdfreder
Copy link
Member

This fixes a problem with the existing traitlet machinery, where anytrait values get added to the notifiers list every time the _notify_trait function is called.

The bug is that each time the traitlet changes, the anytrait callbacks will each be called N times, where N is the number of times the traitlet has been changed (in the current application instance).

@Carreau
Copy link
Member

Carreau commented Oct 21, 2013

Tests ?

For whatever reason, Travis have decided not to test this PR ...

(Yes, I know I'm the first not to write test)

@jdfreder
Copy link
Member Author

Thanks for the reminder, I was still trying to isolate an example of the problem. This notebook code shows the issue:

IN

from IPython.config import LoggingConfigurable
from IPython.utils.traitlets import Int

class A(LoggingConfigurable):

    listen_to = ['a']

    a = Int(0)
    b = 0

    def __init__(self, **kwargs):
        super(A, self).__init__(**kwargs)
        self.on_trait_change(self.listener1, self.listen_to)

    def listener1(self, name, old, new):
        self.b += 1

class B(A):

    c = 0
    d = 0

    def __init__(self, **kwargs):
        super(B, self).__init__(**kwargs)
        self.on_trait_change(self.listener2)

    def listener2(self, name, old, new):
        self.c += 1

    def _a_changed(self, name, old, new):
        self.d += 1

IN

instance = B()

for i in range(3):
    instance.a += 1
    print "%d should equal %d and %d" % (instance.b, instance.c, instance.d)

OUT

1 should equal 1 and 1
2 should equal 3 and 3
3 should equal 6 and 6

@jdfreder
Copy link
Member Author

Test added

minrk added a commit that referenced this pull request Oct 21, 2013
Fix traitlet _notify_trait by-ref issue

This fixes a problem with the existing traitlet machinery, where anytrait values get added to the notifiers list every time the _notify_trait function is called.

The bug is that each time the traitlet changes, the anytrait callbacks will each be called N times, where N is the number of times the traitlet has been changed (in the current application instance).
@minrk minrk merged commit 4788e78 into ipython:master Oct 21, 2013
@jdfreder jdfreder deleted the traitlet_notify_fix branch March 10, 2014 18:44
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Fix traitlet _notify_trait by-ref issue

This fixes a problem with the existing traitlet machinery, where anytrait values get added to the notifiers list every time the _notify_trait function is called.

The bug is that each time the traitlet changes, the anytrait callbacks will each be called N times, where N is the number of times the traitlet has been changed (in the current application instance).
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.

None yet

3 participants