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

always perform requested trait assignments #2311

Merged
merged 2 commits into from Sep 11, 2012
Merged

Conversation

minrk
Copy link
Member

@minrk minrk commented Aug 16, 2012

Some assignments do not change value, but do change the object,
and these should not be ignored.

For instance, container objects are currently impossible to assign
if they evaluate as equal, even if their types don't match
(e.g. assigning an empty defaultdict to a Dict trait)

@travisbot
Copy link

This pull request passes (merged 16123c3c into 289fc01).

@takluyver
Copy link
Member

We're unlikely to break it again, but do you think we should have a test for that?

Also, some unrelated javascript changes have appeared - going by the commit message, I guess they're not meant to be here.

@minrk
Copy link
Member Author

minrk commented Aug 16, 2012

oops, js is just me failing to properly stash what I was fiddling with at the time, I will remove it.

I will add a test, might as well.

Some assignments do not change *value*, but do change the object,
and these should not be ignored.

For instance, container objects are currently impossible to assign
if they evaluate as equal.
@minrk
Copy link
Member Author

minrk commented Aug 16, 2012

test added

@travisbot
Copy link

This pull request passes (merged 58fa955 into 289fc01).

@minrk
Copy link
Member Author

minrk commented Aug 16, 2012

Test results for commit 58fa955 merged into master (289fc01)
Platform: darwin

  • python2.6: OK (libraries not available: azure cython matplotlib oct2py pygments pymongo qt rpy2 tornado wx wx.aui)
  • python2.7: OK (libraries not available: azure oct2py wx wx.aui)
  • python3.2: OK (libraries not available: azure cython matplotlib oct2py pygments pymongo qt rpy2 wx wx.aui)

Not available for testing:

if old_value != new_value:
obj._trait_values[self.name] = new_value
obj._notify_trait(self.name, old_value, new_value)
Copy link
Member

Choose a reason for hiding this comment

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

We still only do the change notification if the new value doesn't compare equal. Does that make sense? Do we have any traits for mutable types that trigger notifications?

Copy link
Contributor

Choose a reason for hiding this comment

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

There are a number of situations where it helps end notification cycles. traits proper lets you configure this on a per-trait basis, but this is not used especially often.

Copy link
Member Author

Choose a reason for hiding this comment

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

I could change it to an is check.

Copy link
Member

Choose a reason for hiding this comment

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

An is check intuitively makes more sense to me, but I haven't looked for
possible side effects.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just worry about infinite loops with an is check, in case there is some
casting operator involved in the trait.

Copy link
Member Author

Choose a reason for hiding this comment

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

With an is check, infinite recursion is easy to trigger with a copy:

class C(HasTraits):

    d = Dict()
    def _d_changed(self, name, old, new):
        self.d = new.copy()

So that doesn't seem like a good choice. Maybe it should be left as it is?

Copy link
Member

Choose a reason for hiding this comment

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

OK, that's fine, I just wanted to make sure we'd thought about what API
we'd expect, as this creates the possibility that a trait can be changed
without the notifications being fired.

@takluyver
Copy link
Member

@minrk I think you can merge this unless you want to leave it for later.

minrk added a commit that referenced this pull request Sep 11, 2012
always perform requested trait assignments

Some assignments do not change value, but do change the object,
and these should not be ignored.

For instance, container objects are currently impossible to assign
if they evaluate as equal, even if their types don't match
(e.g. assigning an empty defaultdict to a Dict trait, which prompted this PR).
@minrk minrk merged commit 8284282 into ipython:master Sep 11, 2012
@minrk minrk deleted the trait_change branch March 31, 2014 23:36
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
always perform requested trait assignments

Some assignments do not change value, but do change the object,
and these should not be ignored.

For instance, container objects are currently impossible to assign
if they evaluate as equal, even if their types don't match
(e.g. assigning an empty defaultdict to a Dict trait, which prompted this PR).
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

5 participants