bolkedebruin commented on code in PR #37168:
URL: https://github.com/apache/airflow/pull/37168#discussion_r1478045494


##########
airflow/serialization/serde.py:
##########
@@ -147,6 +147,13 @@ def serialize(o: object, depth: int = 0) -> U | None:
         if is_serialized:
             return encode(classname, version, serialize(data, depth + 1))
 
+    # serialize namedtuple like tuples
+    if _is_namedtuple(o):
+        qn = "builtins.tuple"
+        data, _, version, is_serialized = _serializers[qn].serialize(o)

Review Comment:
   This is redundant. Setting qn to "builtins.tuple" and move this check higher 
is sufficient.



##########
airflow/serialization/serde.py:
##########
@@ -337,6 +344,11 @@ def _is_pydantic(cls: Any) -> bool:
     return hasattr(cls, "model_config") and hasattr(cls, "model_fields") and 
hasattr(cls, "model_fields_set")
 
 
+def _is_namedtuple(cls: Any) -> bool:
+    """Return True if the class is a namedtuple."""
+    return isinstance(cls, tuple) and hasattr(cls, "_asdict") and hasattr(cls, 
"_fields")

Review Comment:
   isinstance is slow. Is it possible to just check on attributes?



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

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

Reply via email to