"Set" classes are not iterable

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

Nobody has claimed this yet.

Assessment

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

Research direction

Start with the Set classes, including tsp.trace_set.TraceSet, and locate the implementations of ExperimentSet, TraceSet, ConfigurationParameterDescriptorSet, ConfigurationSet, ConfigurationSourceSet, and OutputDescriptorSet. Compare their current collection behavior with the access patterns in the issue and the linked example commit. Done means each class can be iterated directly and reports its size with len(), while indexing remains optional.

Written by the indexing model from the issue text.

Description

The Set classes, ExperimentSet, TraceSet, ConfigurationParameterDescriptorSet, ConfigurationSet, ConfigurationSourceSet and OutputDescriptorSet are not usable by themselves as collections.

This gives you access patterns like:

from tsp.trace_set import TraceSet

traces = TraceSet([{"name": "trace0"}, {"name": "trace1"}])

for trace in traces.traces:
    print(t.name)
# trace0
# trace1

print(len(traces.traces))
# 2

This is especially inconvenient when working with experiments, since to loop over traces, you must do:

for t in experiment.traces.traces

We could make the classes easier to work with by making them implement collection interfaces.

This would give you the following access patterns instead:

from tsp.trace_set import TraceSet

traces = TraceSet([{"name": "trace0"}, {"name": "trace1"}])

for trace in traces:
    print(t.name)
# trace0
# trace1

print(len(traces))
# 2

See example in this commit.

__getitem__ could be implemented as well to allow indexing with integers (traces[0]), but it is not implemented for Python sets, so it would make the "Set" classes look less like sets.

If this kind of functionality is wanted, I can help provide patches.

Dominant language
Python
Stars
6
Forks
16
PR merge metrics
No merged PRs in 30d

Getting set up

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.

More from eclipse-cdt-cloud/tsp-python-client

All issues in eclipse-cdt-cloud/tsp-python-client

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.