-
Notifications
You must be signed in to change notification settings - Fork 38
AP-25288: Add visible_choices for EnumParameter #37
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
base: master
Are you sure you want to change the base?
Conversation
Allows to dynamically filter which enum values are displayed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds dynamic filtering capabilities to EnumParameter through a new visible_choices parameter. This allows enum options to be filtered based on runtime context (e.g., input data specifications) while maintaining backward compatibility for saved workflows.
Key changes:
- Added
visible_choicescallable parameter to filter displayed enum options based onDialogCreationContext - Enhanced
EnumParameterto accept enum members directly asdefault_value(not just strings) - Implemented caching (LRU with size 2) for the filtering callable to optimize performance
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| org.knime.python3.nodes/src/main/python/knime/extension/parameter.py | Core implementation: added visible_choices parameter, filtering logic with validation/warnings, caching, and comprehensive docstring examples |
| org.knime.python3.nodes.tests/src/test/python/unittest/test_knime_parameter.py | Comprehensive test suite covering filtering scenarios, edge cases (empty/invalid results), caching behavior, and description generation |
| Parameters | ||
| ---------- | ||
| docstring : str | ||
| The parameter docstring | ||
| visible_members : list, optional | ||
| List of member names to include. If None, all members are included. |
Copilot
AI
Jan 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring format is inconsistent with the method's return value. The docstring should include a Returns section describing that it returns a string containing the formatted options description.
| Parameters | |
| ---------- | |
| docstring : str | |
| The parameter docstring | |
| visible_members : list, optional | |
| List of member names to include. If None, all members are included. | |
| Parameters | |
| ---------- | |
| docstring : str | |
| The parameter docstring. | |
| visible_members : list, optional | |
| List of member names to include. If None, all members are included. | |
| Returns | |
| ------- | |
| str | |
| The formatted options description including the available options. |
| LOGGER.warning( | ||
| f"visible_choices for parameter '{self._label}' returned an empty list. " | ||
| f"Showing empty options." | ||
| ) | ||
| return [] | ||
| else: | ||
| # All members were invalid - already warned above | ||
| LOGGER.warning( | ||
| f"visible_choices for parameter '{self._label}' returned no valid members. " | ||
| f"Showing empty options." | ||
| ) | ||
| return [] |
Copilot
AI
Jan 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both branches of this conditional return the same value (empty list) and log similar warnings. The code can be simplified by removing the nested conditional since both cases should be handled identically - check if validated_members is empty, log an appropriate warning mentioning whether it was originally empty or had only invalid members, and return an empty list.
| LOGGER.warning( | |
| f"visible_choices for parameter '{self._label}' returned an empty list. " | |
| f"Showing empty options." | |
| ) | |
| return [] | |
| else: | |
| # All members were invalid - already warned above | |
| LOGGER.warning( | |
| f"visible_choices for parameter '{self._label}' returned no valid members. " | |
| f"Showing empty options." | |
| ) | |
| return [] | |
| warning_msg = ( | |
| f"visible_choices for parameter '{self._label}' returned an empty list. " | |
| f"Showing empty options." | |
| ) | |
| else: | |
| # All members were invalid - already warned above | |
| warning_msg = ( | |
| f"visible_choices for parameter '{self._label}' returned no valid members. " | |
| f"Showing empty options." | |
| ) | |
| LOGGER.warning(warning_msg) | |
| return [] |
| visible_options : list of EnumParameterOptions, optional | ||
| List of enum members to include in description. If None, all members | ||
| from self._enum are included. If provided, only these members appear | ||
| in the description. |
Copilot
AI
Jan 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring is missing a Returns section. It should document that the method returns a string containing the formatted description with available options.
| in the description. | |
| in the description. | |
| Returns | |
| ------- | |
| str | |
| A formatted description string containing the available options, | |
| optionally restricted to the provided ``visible_options``. |
|



Allows to dynamically filter which enum values are displayed.