marshmallow-code / marshmallow-code/marshmallow
Suggestion: Refactor builtin fields to expose validators for re-use
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 738
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 7
Description
For my use case, I want to have a custom field-getter using `fields.Function()` but the value it gets will be a UUID. I'd like to be able to have the same validation as the builtin `fields.UUID()`. However, that doesn't seem to be [available in the `validate` module.](https://github.com/marshmallow-code/marshmallow/blob/dev/marshmallow/validate.py)
My suggestion is to refactor all the builtin field types so that they call validators in `validate`. That way, the same validators would also be exposed for reuse in custom user-defined fields.
As I'm imagining this, it would be a fully backwards-compatible change and the only difference to the public interface would be documenting/exposing new validators.
If that sounds like a good idea to the maintainers, I'm happy to take a crack at this and open a PR.
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 with marshmallow/validate.py and the implementations of fields.Function() and fields.UUID(), then compare how builtin field types currently perform validation. Define the reusable-validator scope and check that builtin behavior remains unchanged while validators are exposed for custom fields; confirm the public interface and documentation reflect the new exports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100