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


##########
airflow/serialization/serde.py:
##########
@@ -134,19 +134,25 @@ def serialize(o: object, depth: int = 0) -> U | None:
 
     cls = type(o)
     qn = qualname(o)
+    classname = None

Review Comment:
   This is not required. Please remove it.



##########
airflow/serialization/serde.py:
##########
@@ -134,19 +134,25 @@ def serialize(o: object, depth: int = 0) -> U | None:
 
     cls = type(o)
     qn = qualname(o)
+    classname = None
+
+    # serialize namedtuple like tuples
+    if _is_namedtuple(o):
+        qn = "builtins.tuple"
+        classname = qn

Review Comment:
   It does not need to set the classname. Just the qualified name.



##########
airflow/serialization/serde.py:
##########
@@ -337,6 +343,15 @@ 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.
+
+    Checking is done by attributes as it is significantly faster than
+    using isinstance.
+    """
+    return hasattr(cls, "_asdict") and hasattr(cls, "_fields") and 
hasattr(cls, "_field_defaults")

Review Comment:
   Awesome.



##########
airflow/serialization/serde.py:
##########
@@ -134,19 +134,25 @@ def serialize(o: object, depth: int = 0) -> U | None:
 
     cls = type(o)
     qn = qualname(o)
+    classname = None
+
+    # serialize namedtuple like tuples
+    if _is_namedtuple(o):
+        qn = "builtins.tuple"
+        classname = qn
+
+    # if there is a builtin serializer available use that

Review Comment:
   Keep this below. Do not move it.



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