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

set default value from signature defaults in interact #5136

Merged
merged 5 commits into from Feb 22, 2014

Conversation

minrk
Copy link
Member

@minrk minrk commented Feb 16, 2014

If available, use the default value from the signature for the initial condition, when using range/choice abbreviations.

Not affected:

  • single-value abbreviations (@interact(a=5) sets a=5)
  • explicit Widgets

as proposed in #5134

If available, use the default value from the signature for the initial condition,
when using range/choice abbreviations.

Not affected:

- single-value abbreviations (`@interact(a=5)` sets `a=5`)
- explicit Widgets
@dawehner
Copy link
Contributor

This works perfect for me, thank you!

@takluyver
Copy link
Member

implementation looks sound, and the tests are passing. I'll check again at my desk tomorrow and then merge.

try:
widget.value = default
except TraitError:
# warn?
Copy link
Member

Choose a reason for hiding this comment

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

yes... I think it would be good to have an advice here...

@damianavila
Copy link
Member

LGTM 👍

@ellisonbg
Copy link
Member

We should also handle the case where the abbrev is a dict and add a test for that.

@minrk
Copy link
Member Author

minrk commented Feb 21, 2014

dict case is tested, and a bug revealed in selection widgets is fixed as a result.

before raising

otherwise, invalid values were still accepted
# Now build the widgets from the abbreviations.
kwargs_widgets.extend(_widgets_from_abbreviations(new_kwargs))
kwargs_widgets.extend(_widgets_from_abbreviations(sorted(kwargs.items(), key = lambda x: x[0])))
Copy link
Member

Choose a reason for hiding this comment

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

Why remove the sorting? Is the idea to follow the order of arguments defined in the function itself?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not removing the sorting, it's removing the line altogether. This line did nothing because kwargs is always empty.

Copy link
Member

Choose a reason for hiding this comment

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

OK, great.

@ellisonbg
Copy link
Member

Looks good merging.

ellisonbg added a commit that referenced this pull request Feb 22, 2014
set default value from signature defaults in interact
@ellisonbg ellisonbg merged commit b4fba97 into ipython:master Feb 22, 2014
@minrk minrk deleted the interact-default branch March 31, 2014 23:36
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
set default value from signature defaults in interact
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