File tree Expand file tree Collapse file tree 2 files changed +12
-10
lines changed
Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -180,7 +180,8 @@ def fields(
180180 | type [pydantic .BaseModel ]
181181 | type [PydanticV1BaseModel ],
182182) -> tuple [Field , ...]:
183- if hasattr (type (obj ), "model_fields" ) or hasattr (obj , "__pydantic_fields__" ):
183+ cls = obj if isinstance (obj , type ) else type (obj )
184+ if hasattr (cls , "model_fields" ) or hasattr (obj , "__pydantic_fields__" ):
184185 obj = cast ("pydantic.BaseModel | type[pydantic.BaseModel]" , obj )
185186 return tuple (_fields_v2 (obj ))
186187 if hasattr (obj , "__pydantic_model__" ):
Original file line number Diff line number Diff line change @@ -22,12 +22,13 @@ class M(BaseModel):
2222 e : e_constr = "abc" # type: ignore
2323 f : str = f_field
2424
25- for f in fields (M ):
26- assert f .constraints
27- if f .name in {"e" , "f" }:
28- assert f .constraints .pattern == PATTERN
29- else :
30- assert f .constraints .ge == 42
31- assert f .constraints .le == 100
32- assert f .default == 50
33- assert f .default == 50
25+ for obj in (M , M ()):
26+ for f in fields (obj ):
27+ assert f .constraints
28+ if f .name in {"e" , "f" }:
29+ assert f .constraints .pattern == PATTERN
30+ else :
31+ assert f .constraints .ge == 42
32+ assert f .constraints .le == 100
33+ assert f .default == 50
34+ assert f .default == 50
You can’t perform that action at this time.
0 commit comments