|
43 | 43 | from hera.shared._global_config import ( |
44 | 44 | _SCRIPT_ANNOTATIONS_FLAG, |
45 | 45 | _SCRIPT_PYDANTIC_IO_FLAG, |
| 46 | + _SUPPRESS_PARAMETER_DEFAULT_ERROR_FLAG, |
46 | 47 | _flag_enabled, |
47 | 48 | ) |
48 | 49 | from hera.shared._pydantic import _PYDANTIC_VERSION, root_validator, validator |
@@ -511,15 +512,17 @@ class will be used as inputs, rather than the class itself. |
511 | 512 | artifacts.append(new_object) |
512 | 513 | elif isinstance(new_object, Parameter): |
513 | 514 | if new_object.default is not None: |
| 515 | + # TODO: in 5.18 remove the flag check and `warn`, and raise the ValueError directly (minus "flag" text) |
514 | 516 | warnings.warn( |
515 | 517 | "Using the default field for Parameters in Annotations is deprecated since v5.16" |
516 | | - "and will be removed in a future minor version, use a Python default value instead" |
| 518 | + "and will be removed in a future minor version, use a Python default value instead. " |
517 | 519 | ) |
518 | | - # TODO: raise error if override flag not enabled in 5.17: |
519 | | - # if not global_config.experimental_features["..."]: |
520 | | - # raise ValueError( |
521 | | - # "default cannot be set via the Parameter's default, use a Python default value instead" |
522 | | - # ) |
| 520 | + if not global_config.experimental_features[_SUPPRESS_PARAMETER_DEFAULT_ERROR_FLAG]: |
| 521 | + raise ValueError( |
| 522 | + "default cannot be set via the Parameter's default, use a Python default value instead" |
| 523 | + "You can suppress this error by setting " |
| 524 | + f'global_config.experimental_features["{_SUPPRESS_PARAMETER_DEFAULT_ERROR_FLAG}"] = True' |
| 525 | + ) |
523 | 526 | if func_param.default != inspect.Parameter.empty: |
524 | 527 | # TODO: remove this check in 5.18: |
525 | 528 | if new_object.default is not None: |
|
0 commit comments