Enable easier copying into MutableMapping
- Dominant language
- Python
- Stars
- 9
- Forks
- 1
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 10
Description
From https://github.com/ansys-internal/pyacp/pull/258#discussion_r1295546421
Make it easier to copy children from one object to another. Currently, the `MutableMapping` doesn't support
`__setitem__`, which means e.g. the following doesn't work:
```python
# mg1 and mg2 are Modeling Groups
for ply_id, ply in mg1.modeling_plies.items():
mg2.modeling_plies[ply_id] = ply.clone()
```
We can either implement `__setitem__` [1], or e.g. add a dedicated `clone_from` method.
Consider also whether adding a parameter to the parent object's constructor makes sense (e.g., `modeling_plies` in the `ModelingGroup.__init__`). One maybe non-obvious behavior of this is that the children would then (unless they were previously unstored) have to be _new_ objects, not the passed ones.
[1] the complication being how to ensure (and make it easy-to-use) that the key matches the new ID.
Contributor guide
Research direction
Start by reading the MutableMapping implementation and the ModelingGroup.modeling_plies usage shown in the issue, then review the discussion in pull request 258. Decide whether __setitem__, clone_from, or constructor support best defines the key and new-ID behavior. Done means the reported copy loop has a clear, consistent API and the chosen behavior is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100