Allow extensions to register custom Click parameter types for Runner API#3005
Allow extensions to register custom Click parameter types for Runner API#3005
Conversation
Move click_to_python_types mapping from click_api.py into a get_click_to_python_types() function in metaflow_config.py. Extensions can provide their own get_click_to_python_types to add custom type mappings (e.g. S3Type, TableType) which get merged with the base types. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR refactors the hardcoded Key changes:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant CA as click_api.py
participant MC as metaflow_config.py
participant EXT as Extension module
Note over MC: Module-level: define JSON type alias
Note over MC: Define get_click_to_python_types()
MC->>EXT: Load extension config modules
EXT-->>MC: Provide get_click_to_python_types()
Note over MC: Wrap into _new_get_click_to_python_types<br/>merging base + extension dicts (d1.update(d2))
Note over MC: globals()[get_click_to_python_types] = wrapped fn
CA->>MC: from metaflow_config import JSON, get_click_to_python_types
MC-->>CA: Returns merged get_click_to_python_types (and JSON)
Note over CA: click_to_python_types = get_click_to_python_types()
Note over CA: Dict frozen at import time with all type mappings
CA->>CA: get_annotation(param) uses click_to_python_types
CA->>CA: _method_sanity_check() uses JSON for equality check
|
…imports Move JSON type alias to module-level in metaflow_config.py so it is defined in one place. Import it in click_api.py instead of redefining. Add comment explaining why get_click_to_python_types uses local imports (circular dependency: metaflow_config -> includefile -> ... -> debug -> metaflow_config). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| def _new_get_click_to_python_types(f1=globals()[n], f2=o): | ||
| d1 = f1() | ||
| d2 = f2() | ||
| d1.update(d2) | ||
| return d1 | ||
|
|
||
| globals()[n] = _new_get_click_to_python_types |
There was a problem hiding this comment.
Extension types silently shadow base type mappings
The merge uses d1.update(d2), meaning extension-provided mappings unconditionally overwrite base mappings. If an extension accidentally re-maps an existing Click type (e.g. StringParamType) to a different Python type, it will silently change behaviour with no warning.
For comparison, the get_pinned_conda_libs merge at least concatenates conflicting version strings rather than performing a silent overwrite. Consider logging or warning when an extension key collides with a base key, to make such overrides visible and intentional.
| ) | ||
| from metaflow.parameters import flow_context | ||
| from metaflow.user_configs.config_options import ( | ||
| ConfigValue, |
There was a problem hiding this comment.
Is the ConfigValue needed now in this file? Otherwise LGTM
Summary
click_to_python_typesdict fromclick_api.pyinto aget_click_to_python_types()function inmetaflow_config.pyget_click_to_python_typesto add custom type mappings (e.g. S3Type, TableType, DateType) which get merged with the base typesTest plan
get_click_to_python_typeshave their types merged correctly🤖 Generated with Claude Code