Skip to content

Conversation

@AtR1an
Copy link
Contributor

@AtR1an AtR1an commented Jan 2, 2026

Allows to dynamically filter which enum values are displayed.

Allows to dynamically filter which enum values are displayed.
@AtR1an AtR1an requested a review from a team as a code owner January 2, 2026 13:54
Copilot AI review requested due to automatic review settings January 2, 2026 13:54
Copy link
Contributor

Copilot AI left a 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_choices callable parameter to filter displayed enum options based on DialogCreationContext
  • Enhanced EnumParameter to accept enum members directly as default_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

Comment on lines +1519 to +1525
Parameters
----------
docstring : str
The parameter docstring
visible_members : list, optional
List of member names to include. If None, all members are included.
Copy link

Copilot AI Jan 2, 2026

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.

Suggested change
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.

Copilot uses AI. Check for mistakes.
Comment on lines +1766 to +1777
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 []
Copy link

Copilot AI Jan 2, 2026

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.

Suggested change
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 []

Copilot uses AI. Check for mistakes.
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.
Copy link

Copilot AI Jan 2, 2026

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.

Suggested change
in the description.
in the description.
Returns
-------
str
A formatted description string containing the available options,
optionally restricted to the provided ``visible_options``.

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 2, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants