Suppress Redundant Configurable Validation#391
Merged
minrk merged 5 commits intoipython:masterfrom May 4, 2017
Merged
Conversation
Member
|
While you're at it, can you make sure there's a test case for what this is supposed to resolve? class C(Configurable):
x = Unicode(config=True)
cfg = Config()
cfg.C.x = 'from config'
c = C(x='from init')
assert c.x == 'from init' |
Contributor
Author
|
@minrk sure. Any thoughts on the test failure I'm getting here? I don't know what's causing it. |
12d5535 to
2137d14
Compare
minrk
reviewed
Apr 11, 2017
Member
minrk
left a comment
There was a problem hiding this comment.
The test is verifying that constructor keyword-args (in this case 'log') are loaded prior to config. This PR explicitly removes that behavior, which isn't quit right.
We have these requirements:
- traits passed to the constructor load before config
- traits passed to the constructor have higher priority than config
This is handled somewhat clumsily in master by loading all traits passed as kwargs twice - before and after config (hence #390). I've updated the PR to only re-initialize those kwargs that are actually overridden by config, which should make it a smaller change and still fix #390.
traitlets/config/configurable.py
Outdated
| msg += u" Did you mean `{matches}`?".format(matches=matches[0]) | ||
| elif len(matches) >= 1: | ||
| msg +=" Did you mean one of: `{matches}`?".format(matches=', '.join(sorted(matches))) | ||
| print(msg) |
…y config avoids *unnecessary* double-validation, but will be double-validated if loaded more than once.
1de4fa8 to
11dc842
Compare
Contributor
Author
|
@minrk creative fix! 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #390
Summary
Configurables currently make a redundant series of
setattrcalls on themselves to override config values with those that have been explicitly hard-coded in the constructor. In the past this was required due to the timing of descriptor initialization viainstance_init, which occurred inHasTraits.__init__. Now though, descriptor initialization occurs inHasTraits.__new__viasetup_instance. Thus we can remove the redundantsetattrinConfigurable.__init__and simply usesuper().__init__(**kwargs)instead.Todo
stderrreceived a call with the exact warning required by the test. This is specific to Python 3 since it requiresTestCase.assertLogs.cc: @jasongrout