()
| 170 | |
| 171 | @pytest.mark.skipif(sys.version_info < (3, 10), reason=&class="cm">#x27;repr different on older versions') |
| 172 | def test_annotated_alias() -> None: |
| 173 | class="cm"># https://github.com/pydantic/pydantic/issues/2971 |
| 174 | |
| 175 | StrAlias = Annotated[str, Field(max_length=3)] |
| 176 | IntAlias = Annotated[int, Field(default_factory=lambda: 2)] |
| 177 | |
| 178 | Nested = Annotated[list[StrAlias], Field(description=&class="cm">#x27;foo')] |
| 179 | |
| 180 | class MyModel(BaseModel): |
| 181 | a: StrAlias = &class="cm">#x27;abc' |
| 182 | b: StrAlias |
| 183 | c: IntAlias |
| 184 | d: IntAlias |
| 185 | e: Nested |
| 186 | |
| 187 | fields_repr = {k: repr(v) for k, v in MyModel.model_fields.items()} |
| 188 | assert fields_repr == { |
| 189 | &class="cm">#x27;aclass="st">': "FieldInfo(annotation=str, required=False, default='abc', metadata=[MaxLen(max_length=3)])", |
| 190 | &class="cm">#x27;bclass="st">': 'FieldInfo(annotation=str, required=True, metadata=[MaxLen(max_length=3)])', |
| 191 | &class="cm">#x27;cclass="st">': 'FieldInfo(annotation=int, required=False, default_factory=<lambda>)', |
| 192 | &class="cm">#x27;dclass="st">': 'FieldInfo(annotation=int, required=False, default_factory=<lambda>)', |
| 193 | &class="cm">#x27;eclass="st">': "FieldInfo(annotation=list[Annotated[str, FieldInfo(annotation=NoneType, required=True, metadata=[MaxLen(max_length=3)])]], required=True, description='foo')", |
| 194 | } |
| 195 | assert MyModel(b=&class="cm">#x27;defclass="st">', e=['xyzclass="st">']).model_dump() == dict(a='abcclass="st">', b='defclass="st">', c=2, d=2, e=['xyz']) |
| 196 | |
| 197 | |
| 198 | def test_modify_get_schema_annotated() -> None: |
nothing calls this directly
no test coverage detected