potiuk commented on a change in pull request #20722:
URL: https://github.com/apache/airflow/pull/20722#discussion_r783382420



##########
File path: airflow/configuration.py
##########
@@ -493,6 +493,32 @@ def getimport(self, section, key, **kwargs):
                 f'Current value: "{full_qualified_path}".'
             )
 
+    def getjson(self, section, key, fallback=_UNSET, **kwargs) -> Union[dict, 
list, str, int, float, None]:
+        """
+        Return a config value parsed from a JSON string.
+
+        ``fallback`` is *not* JSON parsed but used verbatim when no config 
value is given.
+        """
+        # get always returns the fallback value as a string, so for this if
+        # someone gives us an object we want to keep that
+        default = _UNSET
+        if fallback is not _UNSET:
+            default = fallback
+            fallback = _UNSET
+
+        try:
+            data = self.get(section=section, key=key, fallback=fallback, 
**kwargs)
+        except (NoSectionError, NoOptionError):
+            return default
+
+        if len(data) == 0:

Review comment:
       @andriisoldatenko -> I also prefer explicit len check in such cases. 
Firs of all you'd have to write `if not data`. Negation in condition requires 
one more mental hoop to understand what it does and secondly len expresses the 
intention much more explcitely (if not data is also true when data is None). 
   
   Shorter does not always mean more readable.




-- 
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]


Reply via email to