BasPH commented on a change in pull request #5990: [AIRFLOW-5390] Remove provide context URL: https://github.com/apache/airflow/pull/5990#discussion_r322675368
########## File path: airflow/operators/python_operator.py ########## @@ -91,23 +86,58 @@ def __init__( self.python_callable = python_callable self.op_args = op_args or [] self.op_kwargs = op_kwargs or {} - self.provide_context = provide_context self.templates_dict = templates_dict if templates_exts: self.template_ext = templates_exts - def execute(self, context): + @staticmethod + def determine_op_kwargs(python_callable: Callable, + context: Dict, + num_op_args: int = 0) -> Dict: + """ + Function that will inspect the signature of a python_callable to determine which + values need to be passed to the function. + + :param python_callable: The function that you want to invoke + :param context: The context provided by the execute method of the Operator/Sensor + :param num_op_args: The number of op_args provided, so we know how many to skip + :return: The op_args dictionary which contains the values that are compatible with the Callable + """ + context_keys = context.keys() + sig = signature(python_callable).parameters.items() + op_args_names = islice(sig, num_op_args) + for name, _ in op_args_names: + # Check if it part of the context + if name in context_keys: + # Raise an exception to let the user know that the keyword is reserved + raise ValueError( + "The key {} in the op_args is part of the context, and therefore reserved".format(name) + ) + + if any(str(param).startswith("**") for _, param in sig): + # If there is a **kwargs, **context or **_ then just dump everything. Review comment: ```suggestion # If there is a ** argument then just dump everything. ``` ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services