labthings / labthings/labthings-fastapi
Warn about mutable defaults
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.
If a property is created with a mutable default (e.g. myprop: dict = lt.property(default={"foo":"bar"})) then it's easy for Things to share state unintentionally.
Describe the solution you'd like
If a default value is set to a mutable object (e.g. a dict or list) it should warn about this and suggest using a default factory instead.
Describe alternatives you've considered
Automatically calling deepcopy() would be another potential solution, but I think it exposes us to the possibility of hard-to-debug edge cases, rather than just encouraging accepted best practice (default factories) in downstream code.
Additional context
This caused some head scratching in OFM#750 and OFM#751.
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 property implementation and the code that handles its default value; no specific file or test is named in the issue. Reproduce a property with a dict or list default, then add a warning that recommends a default factory and verify that factory-based defaults do not trigger it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100