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

"Set" classes are not iterable

未关闭
#65 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
6
派生
16
PR 合并指标
30 天内没有已合并 PR

描述

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

This gives you access patterns like:
```python3
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:
```python3
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:
```python3
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](https://github.com/awendelin-work/tsp-python-client/commit/025576dccb9c7239e343c872153fe160973c9425).

`__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.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。