ashb commented on code in PR #53929: URL: https://github.com/apache/airflow/pull/53929#discussion_r2253805553
########## airflow-core/src/airflow/models/mappedoperator.py: ########## @@ -46,6 +46,21 @@ log = structlog.get_logger(__name__) +def _prevent_duplicates(kwargs1: dict[str, Any], kwargs2: Mapping[str, Any], *, fail_reason: str) -> None: + """ + Ensure *kwargs1* and *kwargs2* do not contain common keys. + + :raises TypeError: If common keys are found. + """ + duplicated_keys = set(kwargs1).intersection(kwargs2) + if not duplicated_keys: + return + if len(duplicated_keys) == 1: + raise TypeError(f"{fail_reason} argument: {duplicated_keys.pop()}") + duplicated_keys_display = ", ".join(sorted(duplicated_keys)) + raise TypeError(f"{fail_reason} arguments: {duplicated_keys_display}") Review Comment: This should probably be a ValueError -- they are of the right type (mapping) ########## task-sdk/src/airflow/sdk/definitions/mappedoperator.py: ########## @@ -144,6 +154,21 @@ def is_mappable_value(value: Any) -> TypeGuard[Collection]: return True +def prevent_duplicates(kwargs1: dict[str, Any], kwargs2: Mapping[str, Any], *, fail_reason: str) -> None: + """ + Ensure *kwargs1* and *kwargs2* do not contain common keys. + + :raises TypeError: If common keys are found. + """ + duplicated_keys = set(kwargs1).intersection(kwargs2) + if not duplicated_keys: + return + if len(duplicated_keys) == 1: + raise TypeError(f"{fail_reason} argument: {duplicated_keys.pop()}") + duplicated_keys_display = ", ".join(sorted(duplicated_keys)) + raise TypeError(f"{fail_reason} arguments: {duplicated_keys_display}") Review Comment: Ditto here -- ValueError? (could be separate PR) I also notice the original method from utils is still there -- is there anything else left using that version? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org