Support typing.annotated
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 97
- PR merge metrics
- No merged PRs in 30d
Description
# Feature request
### Context
This works:
```py
class ClassicMemberItem(Model):
id2: str = Field(default_factory=lambda: 'm1id')
m1 = ClassicMemberItem() # id=ObjectId('6a13e2017c4eef33beb24616') id2='m1id'
```
This does not work:
```py
from typing import Annotated
class ClassicMemberItem2(Model):
id2: Annotated[str, Field(default_factory=lambda: 'm2id')]
m2 = ClassicMemberItem2() # ValidationError: 1 validation error for ClassicMemberItem2
```
However, `typing.annotated` is supported by Pydantic.
Contributor guide
Research direction
Start by reproducing the two ClassicMemberItem examples and inspect how Model processes Field metadata from annotations. Compare the working assignment form with typing.Annotated handling, then verify that the Annotated form constructs successfully and applies the default_factory value without a validation error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100