You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/12/09 22:26:17 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #20184: Add and use `exactly_one` helper

uranusjr commented on a change in pull request #20184:
URL: https://github.com/apache/airflow/pull/20184#discussion_r766202344



##########
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:
       This can be problematic if the argument is of a type that can accept a falsy value, or if the default is not falsy (e.g. `NOTSET`). This should Can accept an optional `check_default=` keyword argument and check for default-ness with that instead (the default would be e.g. `functools.partial(operator.is_not, None)`).




-- 
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-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org