labthings / labthings/labthings-fastapi
Mutable datatypes can break observability
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 9
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
Is your feature request related to a problem? Please describe.
A DataProperty typed as a dict may have its value changed without triggering __set__. This leads to the property's value becoming out of sync with observers.
Describe the solution you'd like
DataProperty instances that are typed as a mutable object (e.g. dict, list, or a custom class) should either not be observable, or should raise an error when they are defined (or once the type is resolved).
For mapping or sequence types, I think it would be really nice to have the error message suggest typing them as Mapping or Sequence. Type checked code should then not allow mutation of these objects. We could even use a MappingProxy for dict values to ensure they don't get mutated, or convert list to tuple to achieve the same effect.
I think this merits a bit of discussion. Observability isn't something that's used much at the moment, but I can see it becoming important, for example in efficient client implementations. I would be keen to make sure that it works properly.
Describe alternatives you've considered
I've previously attempted to implement a deep reactive dictionary. This does not seem like a good idea: there are far too many things to go wrong.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the DataProperty implementation and the observability behavior around set. Compare the proposed handling for mutable dict, list, and custom-class types, including Mapping and Sequence annotations. Done requires a decided policy and corresponding validation or non-observable behavior, but the issue does not identify tests or settle which alternative to implement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- observability
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100