You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/05/13 21:51:50 UTC

[GitHub] [iceberg] danielcweeks commented on a diff in pull request #4767: Change types into dataclasses

danielcweeks commented on code in PR #4767:
URL: https://github.com/apache/iceberg/pull/4767#discussion_r872861495


##########
python/src/iceberg/types.py:
##########
@@ -42,57 +42,63 @@ def __new__(cls, *args, **kwargs):
         return cls._instance
 
 
+@dataclass(frozen=True, eq=True, repr=True)
 class IcebergType:
-    """Base type for all Iceberg Types"""
-
-    _initialized = False
+    """Base type for all Iceberg Types
 
-    def __init__(self, type_string: str, repr_string: str):
-        self._type_string = type_string
-        self._repr_string = repr_string
-        self._initialized = True
+    Example:
+        >>> str(IcebergType())
+        'IcebergType()'
+        >>> repr(IcebergType())
+        'IcebergType()'
+    """
 
-    def __repr__(self):
-        return self._repr_string
+    type_string: str = field(init=False, repr=False)
 
     def __str__(self):
-        return self._type_string
+        if hasattr(self, "type_string"):
+            return self.type_string
+        return self.__repr__()
 
     @property
     def is_primitive(self) -> bool:
         return isinstance(self, PrimitiveType)
 
 
+@dataclass(frozen=True, eq=True)
 class PrimitiveType(IcebergType):
-    """Base class for all Iceberg Primitive Types"""
+    """Base class for all Iceberg Primitive Types
 
+    Example:
+        >>> str(PrimitiveType())
+        'PrimitiveType()'
+    """
 
+
+@dataclass(frozen=True, eq=True, repr=True)

Review Comment:
   Aren't defaults for `eq` and `repr` `True`?  Is there a reason to be explicit about those two vs. relying on the defaults?



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org