samredai commented on code in PR #4767:
URL: https://github.com/apache/iceberg/pull/4767#discussion_r873993464
##########
python/src/iceberg/types.py:
##########
@@ -209,25 +192,24 @@ class StructType(IcebergType):
'struct<1: required_field: optional string, 2: optional_field:
optional int>'
"""
- _instances: Dict[Tuple[NestedField, ...], "StructType"] = {}
+ fields: List[NestedField] = field()
+
+ _instances: ClassVar[Dict[Tuple[NestedField, ...], "StructType"]] = {}
- def __new__(cls, *fields: NestedField):
+ def __new__(cls, *fields: NestedField, **kwargs):
+ if "fields" in kwargs:
+ fields = kwargs["fields"]
cls._instances[fields] = cls._instances.get(fields) or
object.__new__(cls)
return cls._instances[fields]
- def __init__(self, *fields: NestedField):
- if not self._initialized:
- super().__init__(
- f"struct<{', '.join(map(str, fields))}>",
- f"StructType{repr(fields)}",
- )
- self._fields = fields
-
- @property
- def fields(self) -> Tuple[NestedField, ...]:
- return self._fields
+ def __init__(self, *fields: NestedField, **kwargs):
+ if "fields" in kwargs:
+ fields = kwargs["fields"]
+ object.__setattr__(self, "fields", fields)
Review Comment:
Ah I see, makes sense!
--
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]