ashb commented on a change in pull request #19965:
URL: https://github.com/apache/airflow/pull/19965#discussion_r778043014
##########
File path: airflow/decorators/task_group.py
##########
@@ -90,20 +88,26 @@ def _make_task_group(self, **kwargs) -> MappedTaskGroup:
return tg
def partial(self, **kwargs) -> "MappedTaskGroupDecorator[R]":
+ if self.partial_kwargs:
+ raise RuntimeError("Already a partial task group")
self.partial_kwargs.update(kwargs)
return self
def map(self, **kwargs) -> R:
- self.mapped_kwargs.update(kwargs)
+ if self.mapped_kwargs:
+ raise RuntimeError("Already a mapped task group")
+ self.mapped_kwargs = kwargs
call_kwargs = self.partial_kwargs.copy()
- call_kwargs.update({k: object() for k in self.mapped_kwargs})
+ duplicated_keys = set(call_kwargs).intersection(kwargs)
+ if duplicated_keys:
+ raise RuntimeError(f"Cannot map partial arguments: {',
'.join(sorted(duplicated_keys))}")
+ call_kwargs.update({k: object() for k in kwargs})
- self._invoked = True
return super().__call__(**call_kwargs)
def __del__(self):
- if not self._invoked:
+ if not self.mapped_kwargs:
Review comment:
Edge case (that I _think_ is fine): This would mean that
`tg.partial(a=2).map()` wouldn't work -- as the mapped_kwargs would be an empty
dict and evaluate to false.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]