rdblue commented on a change in pull request #4016:
URL: https://github.com/apache/iceberg/pull/4016#discussion_r807058828



##########
File path: python/src/iceberg/types.py
##########
@@ -93,21 +121,37 @@ def precision(self) -> int:
     def scale(self) -> int:
         return self._scale
 
-    def __eq__(self, other):
-        if type(self) is type(other):
-            return self.precision == other.precision and self.scale == 
other.scale
-        return False
 
+class NestedField(IcebergType):
+    """This represents a field of a struct, a map key, a map value, or a list 
element. This is where field IDs, names, docs, and nullability are tracked."""
+
+    _instances: Dict[Tuple[bool, int, str, IcebergType, Optional[str]], 
"NestedField"] = {}
+
+    def __new__(
+        cls,
+        is_optional: bool,
+        field_id: int,
+        name: str,
+        field_type: IcebergType,
+        doc: Optional[str] = None,
+    ):
+        key = (is_optional, field_id, name, field_type, doc)
+        cls._instances[key] = cls._instances.get(key) or object.__new__(cls)
+        return cls._instances[key]
 
-class NestedField:
     def __init__(
         self,
         is_optional: bool,
         field_id: int,
         name: str,
-        field_type: Type,
+        field_type: IcebergType,
         doc: Optional[str] = None,
     ):
+        super().__init__(
+            (f"{field_id}: {name}: {'optional' if is_optional else 'required'} 
{field_type}" "" if doc is None else f" ({doc})"),
+            f"NestedField(is_optional={is_optional}, field_id={field_id}, "
+            f"name={repr(name)}, field_type={repr(field_type)}, 
doc={repr(doc)})",

Review comment:
       Can we omit doc if it is None? In the repr string, I see `doc=None`.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to