tatiana commented on a change in pull request #9847:
URL: https://github.com/apache/airflow/pull/9847#discussion_r457150260



##########
File path: airflow/serialization/json.py
##########
@@ -0,0 +1,125 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from typing import Any
+
+from airflow.serialization.enums import DagAttributeTypes as DAT, Encoding
+
+
+def encode(value: Any, type_: Any) -> dict:
+    """Encode value and type into a JSON-friendly dict."""
+    return {Encoding.VAR: value, Encoding.TYPE: type_}
+
+
+_return_primitive = lambda value: value

Review comment:
       Yes, those were a way of treating parsing as a method in all cases...! 
From one hand, it allows us to have a smaller piece of code, using a dictionary 
opposed to several "ifs". On the other hand, it does add the overhead of a 
function call. If you prefer, I could keep the initial strategy of having 
"primitive_types" defined as a set and to check the values against those 
primitive types - falling back to a function just in case it isn't a primitive 
type.




----------------------------------------------------------------
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:
[email protected]


Reply via email to