dstandish commented on a change in pull request #20184:
URL: https://github.com/apache/airflow/pull/20184#discussion_r766207478
##########
File path: airflow/utils/helpers.py
##########
@@ -244,3 +244,18 @@ def build_airflow_url_with_query(query: Dict[str, Any]) ->
str:
view = conf.get('webserver', 'dag_default_view').lower()
url = url_for(f"Airflow.{view}")
return f"{url}?{parse.urlencode(query)}"
+
+
+def exactly_one(*args):
+ """
+ Returns True if exactly one of *args is "truthy", and False otherwise.
+ :param args:
+ :return:
+ """
+ has_one = False
+ for arg in args:
+ if arg and has_one:
+ return False
+ elif arg:
+ has_one = True
+ return has_one
Review comment:
exploring that thought...
```python
def exactly_one(*args, func=bool):
"""
Returns True if exactly one of *args is "truthy", and False otherwise.
:param args:
:return:
"""
return sum(map(func, args)) == 1
exactly_one(a, b, c, func=lambda x: x != NOTSET)
```
Given that you could achieve the same result, with the simpler function in
this way:
```python
exactly_one(*map(lambda x: x !=NOTSET, vals))
```
I think maybe keeping the function simpler is better?
--
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]