Skip to content

Commit

Permalink
Sets the default ion_type when an IonPy* is constructed (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuruvilu committed Oct 26, 2021
1 parent 90f5b5d commit 3de5c14
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions amazon/ion/simple_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,11 @@ def to_event(self, event_type, field_name=None, in_struct=False, depth=None):
annotations=self.ion_annotations, depth=depth)


def _ion_type_for(name, base_cls):
def _ion_type_for(name, base_cls, ion_type=None):
class IonPyValueType(base_cls, _IonNature):
def __init__(self, *args, **kwargs):
super(IonPyValueType, self).__init__(*args, **kwargs)
self.ion_type = ion_type

IonPyValueType.__name__ = name
IonPyValueType.__qualname__ = name
Expand All @@ -157,15 +158,16 @@ def __init__(self, *args, **kwargs):


IonPyBool = IonPyInt
IonPyFloat = _ion_type_for('IonPyFloat', float)
IonPyDecimal = _ion_type_for('IonPyDecimal', Decimal)
IonPyFloat = _ion_type_for('IonPyFloat', float, IonType.FLOAT)
IonPyDecimal = _ion_type_for('IonPyDecimal', Decimal, IonType.DECIMAL)
IonPyText = _ion_type_for('IonPyText', six.text_type)
IonPyBytes = _ion_type_for('IonPyBytes', six.binary_type)


class IonPySymbol(SymbolToken, _IonNature):
def __init__(self, *args, **kwargs):
super(IonPySymbol, self).__init__(*args, **kwargs)
self.ion_type = IonType.SYMBOL

@staticmethod
def _to_constructor_args(st):
Expand All @@ -180,6 +182,7 @@ def _to_constructor_args(st):
class IonPyTimestamp(Timestamp, _IonNature):
def __init__(self, *args, **kwargs):
super(IonPyTimestamp, self).__init__(*args, **kwargs)
self.ion_type = IonType.TIMESTAMP

@staticmethod
def _to_constructor_args(ts):
Expand Down Expand Up @@ -222,5 +225,4 @@ def is_null(value):


IonPyList = _ion_type_for('IonPyList', list)
IonPyDict = _ion_type_for('IonPyDict', Multimap)

IonPyDict = _ion_type_for('IonPyDict', Multimap, IonType.STRUCT)

0 comments on commit 3de5c14

Please sign in to comment.