You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2023/08/10 22:51:04 UTC

[airflow] branch main updated: Refactor: Simplify code in serialization (#33266)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 63c5df89d9 Refactor: Simplify code in serialization (#33266)
63c5df89d9 is described below

commit 63c5df89d9a6db7c8f3c8a0a252588b98fb0b1a1
Author: Miroslav Šedivý <67...@users.noreply.github.com>
AuthorDate: Thu Aug 10 22:50:55 2023 +0000

    Refactor: Simplify code in serialization (#33266)
---
 airflow/serialization/helpers.py            | 3 ++-
 airflow/serialization/serde.py              | 7 +++----
 airflow/serialization/serialized_objects.py | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/airflow/serialization/helpers.py b/airflow/serialization/helpers.py
index d8e6afdc0a..80f949dee3 100644
--- a/airflow/serialization/helpers.py
+++ b/airflow/serialization/helpers.py
@@ -32,9 +32,10 @@ def serialize_template_field(template_field: Any) -> str | dict | list | int | f
     def is_jsonable(x):
         try:
             json.dumps(x)
-            return True
         except (TypeError, OverflowError):
             return False
+        else:
+            return True
 
     if not is_jsonable(template_field):
         return str(template_field)
diff --git a/airflow/serialization/serde.py b/airflow/serialization/serde.py
index 8d0ed100ac..a9a09d86db 100644
--- a/airflow/serialization/serde.py
+++ b/airflow/serialization/serde.py
@@ -300,14 +300,13 @@ def _stringify(classname: str, version: int, value: T | None) -> str:
 
     s = f"{classname}@version={version}("
     if isinstance(value, _primitives):
-        s += f"{value})"
+        s += f"{value}"
     elif isinstance(value, _builtin_collections):
         # deserialized values can be != str
         s += ",".join(str(deserialize(value, full=False)))
     elif isinstance(value, dict):
-        for k, v in value.items():
-            s += f"{k}={deserialize(v, full=False)},"
-        s = s[:-1] + ")"
+        s += ",".join(f"{k}={deserialize(v, full=False)}" for k, v in value.items())
+    s += ")"
 
     return s
 
diff --git a/airflow/serialization/serialized_objects.py b/airflow/serialization/serialized_objects.py
index 7e403e835c..5feb000edc 100644
--- a/airflow/serialization/serialized_objects.py
+++ b/airflow/serialization/serialized_objects.py
@@ -1182,7 +1182,7 @@ class SerializedBaseOperator(BaseOperator, BaseSerialization):
             #       }
             #   )
 
-            _operator_link_class_path, data = list(_operator_links_source.items())[0]
+            _operator_link_class_path, data = next(iter(_operator_links_source.items()))
             if _operator_link_class_path in get_operator_extra_links():
                 single_op_link_class = import_string(_operator_link_class_path)
             elif _operator_link_class_path in plugins_manager.registered_operator_link_classes: