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

Update FileSelector parameters when setting path #476

Merged
merged 8 commits into from
May 31, 2021

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented May 13, 2021

Adds an _on_set method to all Parameters, this allows Parameters to trigger actions when one of its attributes changes. This is used to update the list of valid paths when (Multi)FileSelector.path is set.

Fixes #412

@philippjfr philippjfr changed the title Update FileSelector when setting path Refactor parameter attribute validation May 14, 2021
@philippjfr philippjfr force-pushed the fileselector_path_update branch 4 times, most recently from 01aff6b to 179a885 Compare May 14, 2021 11:04
@jlstevens
Copy link
Contributor

My main question is whether this mechanism might be better used to generate warnings instead of errors?

@philippjfr philippjfr changed the title Refactor parameter attribute validation Update FileSelector parameters when setting path May 31, 2021
@philippjfr
Copy link
Member Author

Reverted any changes to validation on setting but still factored out separate validation methods for different attributes which should make it straightforward to readd the validation later.

@jlstevens
Copy link
Contributor

Makes sense. Ready for review?

@philippjfr
Copy link
Member Author

Yes, note this PR also continues some style and exception cleanup. Should have kept that separate sorry.

@@ -750,46 +750,37 @@ class Number(Dynamic):

"""

__slots__ = ['bounds','_softbounds','inclusive_bounds','set_hook', 'step']
__slots__ = ['bounds', 'softbounds', 'inclusive_bounds', 'set_hook', 'step']
Copy link
Contributor

Choose a reason for hiding this comment

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

Getting rid of the underscore makes sense as the properties didn't really do anything, but couldn't this have backward compatibility implications?

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose stateful things like pickling shouldn't touch slots directly and the API is the same as it was when properties were used. It should be ok but I am always wary when messing with slots in param.


def _validate(self, val):
Copy link
Contributor

Choose a reason for hiding this comment

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

Good to see the types of validation performed laid out like this!


return val

def _validate_bounds(self, val, bounds, inclusive_bounds):
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this: more general than _checkBounds and makes the input explicit using arguments instead of self.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this is also in preparation to supporting validate methods on the class itself which could be useful for composite parameters.


def _validate(self, val):
assert len(val) == len(self.attribs),"Compound parameter '%s' got the wrong number of values (needed %d, but got %d)." % (self.name,len(self.attribs),len(val))
Copy link
Contributor

Choose a reason for hiding this comment

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

Guess I've never seen this assert raise an exception so I guess it is safe to remove...

Copy link
Member Author

Choose a reason for hiding this comment

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

Not removed, just moved to _validate_attribs as a proper ValueError

raise ValueError(
"Parameter '%s' must be a subclass of %s, not '%s'" %
(val.__name__, class_name, val.__class__.__name__))
"%s parameter %r must be a subclass of %s, not %r." %
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this improvement to the exception message...

@jlstevens
Copy link
Contributor

Reviewing with PR was a little tricky with all the formatting changes but every code change looks like an improvement to me. Happy to see this merged!

@philippjfr philippjfr merged commit bf3d324 into master May 31, 2021
@maximlt maximlt deleted the fileselector_path_update branch July 12, 2023 23:39
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.

FileSelector: modify path via ObjectSelector - dropdown list does not change
2 participants