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

TraitType -> BaseDescriptor, and replace call to set_default_value with instance_init #26

Conversation

SylvainCorlay
Copy link
Member

  • Missed a replacement of TraitType by BaseDescriptor.
  • add_trait should call instance_init, not set_default_value. Then there is no remaining call to set_default_value, which I remove.

@SylvainCorlay SylvainCorlay changed the title TraitType -> BaseDescriptor TraitType -> BaseDescriptor, and replace call to set_default_value with instance_init Jun 4, 2015
@SylvainCorlay
Copy link
Member Author

Ping @minrk, @takluyver ? this one is quite trivial.

@minrk
Copy link
Member

minrk commented Jun 4, 2015

It's surprising to me that simply removing the call to set_default_value has has no effect. instance_init doesn't appear to set the default value, so functionality does seem to be removed. Can you explain that a little bit?

@SylvainCorlay
Copy link
Member Author

  • instance_init should clearly be called in add_trait. (e.g. for setting name and this_class of sub-traits)
  • The last call to the set_default_value method was in add_trait. It is actually not needed.

Other calls were removed by earlier PRs. A call was removed when we decided to wait to see if a value was provided in a keyword argument of the constructor of the HasTraits instance. Another call was removed when Thomas introduced the _set_default_value_at_instance_init method.

  • Example after this PR:
from traitlets import *
class Foo(HasTraits):
    pass
foo = Foo()
foo.add_trait('bar', Int(1)) 
print(foo.bar )  # prints 1 as expected because self.init_default_value is called in `__get__`.

@minrk
Copy link
Member

minrk commented Jun 4, 2015

ok. That seems fine, then.

minrk added a commit that referenced this pull request Jun 4, 2015
…pe_2_BaseDescriptor

TraitType -> BaseDescriptor, and replace call to set_default_value with instance_init
@minrk minrk merged commit 02d1ccc into ipython:master Jun 4, 2015
@minrk minrk added this to the 4.0 milestone Jun 4, 2015
@SylvainCorlay SylvainCorlay deleted the missing_replacement_TraitType_2_BaseDescriptor branch June 5, 2015 03:15
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

2 participants