Skip to content

Commit 617a690

Browse files
committed
Cleanup
1 parent 2845d13 commit 617a690

File tree

1 file changed

+17
-37
lines changed

1 file changed

+17
-37
lines changed

src/mdio/schemas/core.py

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,24 @@
1010
from pydantic.alias_generators import to_camel
1111
from pydantic import Field
1212

13-
14-
# def model_fields(model: type[BaseModel]) -> dict[str, tuple[Any, Any]]:
15-
# """Extract Pydantic BaseModel fields.
16-
17-
# Args:
18-
# model: (Type) The model object for which the fields will be extracted.
19-
20-
# Returns:
21-
# A dictionary containing the fields of the model along with
22-
# their corresponding types and default values.
23-
24-
# Example:
25-
# >>> class MyModel(BaseModel):
26-
# ... name: str
27-
# ... age: int = 0
28-
# ...
29-
# >>> model_fields(MyModel)
30-
# {'name': (str, <default_value>), 'age': (int, 0)}
31-
# """
32-
# annotations = get_type_hints(model)
33-
34-
# fields = {}
35-
# for field_name, field in model.model_fields.items():
36-
# fields[field_name] = (annotations[field_name], field)
37-
38-
# return fields
39-
40-
# def model_fields(model: type[BaseModel]) -> dict[str, tuple[Any, Any]]:
41-
# """Return fields suitable for use in create_model with correct types and defaults."""
42-
# fields = {}
43-
# for field_name, field_info in model.model_fields.items():
44-
# annotated_type = field_info.annotation
45-
# default = field_info.default if field_info.default is not None else ...
46-
# fields[field_name] = (annotated_type, Field(default, description=field_info.description))
47-
# return fields
48-
4913
def model_fields(model: type[BaseModel]) -> dict[str, tuple[Any, Any]]:
50-
"""Safely extract fields for create_model, preserving optionality and default behavior."""
14+
"""Extract Pydantic BaseModel fields.
15+
16+
Args:
17+
model: (Type) The model object for which the fields will be extracted.
18+
19+
Returns:
20+
A dictionary containing the fields of the model along with
21+
their corresponding types and default values.
22+
23+
Example:
24+
>>> class MyModel(BaseModel):
25+
... name: str
26+
... age: int = 0
27+
...
28+
>>> model_fields(MyModel)
29+
{'name': (str, <default_value>), 'age': (int, 0)}
30+
"""
5131
fields = {}
5232
for field_name, field_info in model.model_fields.items():
5333
annotated_type = field_info.annotation

0 commit comments

Comments
 (0)