Generate a real Python 'set' for the Conjure set<T> type
iamdanfox opened this issue · 0 comments
iamdanfox commented
What's happening
Given the Conjure definition:
SetExample:
fields:
items: set<string>
doubleItems: set<double>
conjure-python 3.9.0 doesn't actually enforce uniqueness of the items
field because it generates a list:
class SetExample(ConjureBeanType):
@classmethod
def _fields(cls):
# type: () -> Dict[str, ConjureFieldDefinition]
return {
'items': ConjureFieldDefinition('items', ListType(str)),
'double_items': ConjureFieldDefinition('doubleItems', ListType(float))
}
_items = None # type: List[str]
_double_items = None # type: List[float]
def __init__(self, double_items, items):
# type: (List[float], List[str]) -> None
self._items = items
self._double_items = double_items
@property
def items(self):
# type: () -> List[str]
return self._items
@property
def double_items(self):
# type: () -> List[float]
return self._double_items
What should happen
We should codegen a python type that actually enforces uniqueness, e.g. set
or frozenset
: https://docs.python.org/2/library/stdtypes.html#set