CircArgs commented on a change in pull request #3601:
URL: https://github.com/apache/iceberg/pull/3601#discussion_r756394549
##########
File path: python/src/iceberg/types.py
##########
@@ -15,157 +15,1219 @@
# specific language governing permissions and limitations
# under the License.
-from typing import Optional
+import decimal
+import math
+import struct
+from base64 import b64encode
+from datetime import date, datetime, time
+from decimal import Decimal as PythonDecimal
+from typing import Any, Dict
+from typing import List as PythonList
+from typing import Optional, Tuple, Type, Union
Review comment:
Thanks. It's odd - not sure where that came from. I swear I put them in
one!
##########
File path: python/src/iceberg/types.py
##########
@@ -15,157 +15,1219 @@
# specific language governing permissions and limitations
# under the License.
-from typing import Optional
+import decimal
+import math
+import struct
+from base64 import b64encode
+from datetime import date, datetime, time
+from decimal import Decimal as PythonDecimal
+from typing import Any, Dict
+from typing import List as PythonList
+from typing import Optional, Tuple, Type, Union
+from uuid import UUID as PythonUUID
+import mmh3
+from numpy import float32, float64, isinf, isnan
-class Type(object):
- 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
- def __repr__(self):
- return self._repr_string
+# intended for use inside this module only
+class IcebergMetaType(type):
+ """
+ MetaClass to:
+ Generate a str for an `IcebergType`
+ Generate a repr for an `IcebergType`
+ Freeze attributes that define a generic `IcebergType`
- def __str__(self):
- return self._type_string
+ Note: for internal iceberg use only
+ """
- @property
- def is_primitive(self) -> bool:
- return self._is_primitive
+ _always_frozen = {"_strname", "_frozen_attrs", "_always_frozen"}
+ # freeze setting of generic attributes
+ def __setattr__(cls, key, value):
+ if key in getattr(cls, "_frozen_attrs", set()) or key in
cls._always_frozen:
+ raise AttributeError(f"{key} may not be altered on type {cls}")
+ type.__setattr__(cls, key, value)
+ # freeze deleting of generic attributes
+ def __delattr__(cls, key):
+ if key in getattr(cls, "_frozen_attrs", set()) or key in
cls._always_frozen:
+ raise AttributeError(f"{key} may not be deleted on type {cls}")
+ type.__delattr__(cls, key)
-class FixedType(Type):
- def __init__(self, length: int):
- super().__init__(
- f"fixed[{length}]", f"FixedType(length={length})",
is_primitive=True
- )
- self._length = length
+ def __getitem__(cls, key):
+ return cls._get_generic(cls, key)
+
+ def __subclasscheck__(cls, other):
+ """custom subclass check for when checking `issubclass` on an
IcebergType to ensure covariance on generics"""
+ if cls == other:
+ return True
+ if generic_class.is_generic_type(
+ cls, True, True
+ ) and generic_class.is_generic_type(other, True, True):
+
+ unspecified_generic =
generic_class.get_unspecified_generic_type(cls)
+ generic_names = [
+ g[1]
+ for g in generic_class.generics.values()
+ if g[0] == unspecified_generic
+ ][0]
+ return all(
+ issubclass(sv, tv)
+ for sv, tv in [
+ (type.__getattribute__(other, a),
type.__getattribute__(cls, a))
+ for a in generic_names
+ ]
+ )
+ try:
+ return _is_subclass(other, cls)
Review comment:
I think I need to handle a possible exception in case something like an
instance is given which wouldn't have an mro
--
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]