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



##########
File path: python/src/iceberg/types.py
##########
@@ -15,61 +15,84 @@
 # specific language governing permissions and limitations
 # under the License.
 """Data types used in describing Iceberg schemas
-
 This module implements the data types described in the Iceberg specification 
for Iceberg schemas. To
 describe an Iceberg table schema, these classes can be used in the 
construction of a StructType instance.
-
 Example:
     >>> StructType(
         [
             NestedField(True, 1, "required_field", StringType()),
             NestedField(False, 2, "optional_field", IntegerType()),
         ]
     )
-
 Notes:
   - https://iceberg.apache.org/#spec/#primitive-types
 """
 
-from typing import Optional
+from typing import Any, Dict, List, Optional, Tuple
 
 
-class Type:
-    def __init__(self, type_string: str, repr_string: str, is_primitive=False):
-        self._type_string = type_string
-        self._repr_string = repr_string
-        self._is_primitive = is_primitive
+class IcebergType:
+
+    _implemented: Dict[Tuple[str, Tuple[Any]], "IcebergType"] = {}
+
+    def __new__(cls, *args, **kwargs):
+        init_func = cls.__dict__.get("__init__")
+        names = init_func.__code__.co_varnames[1:] if init_func else []
+        defaults = init_func and init_func.__defaults__ or []
+        args = {**dict(zip(names[::-1], defaults[::-1])), **dict(zip(names, 
args))}
+        args = {**args, **kwargs}
+        args = tuple(
+            (k, tuple(args[k]) if isinstance(args[k], list) else args[k]) for 
k in names
+        )
+        key = (cls.__name__, args)
+        if key in cls._implemented:
+            return cls._implemented[key]
+        else:
+            ret = object.__new__(cls)
+            ret._args = args
+            cls._implemented[key] = ret
+            return ret
 
     def __repr__(self):
-        return self._repr_string
+        base = f"{type(self).__name__}("

Review comment:
       just to explain how this change started: to get `__new__` to work I back 
up to `object`'s `__new__` and can't feed it any arguments so using the 
`__init__` for this as it was I don't think is so easy to get working, so I can 
change it back especially with how your comment about me changing 
`fixed[8]->fixed<8>` is shaking out




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