palantir / palantir/conjure-python

Generate a real Python 'set' for the Conjure set<T> type

Open
#27 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
27
Forks
19
Avg merge
12h 22m
Merged PRs (30d)
15

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the generator that emits the shown SetExample fields and ListType annotations. Update the generated representation for set and set to enforce uniqueness, then verify the generated properties and type annotations reflect that set-like behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.