Skip to content

Commit 89ad246

Browse files
committed
refactor: simplify docstrings in pydantic_utils.py for clarity
1 parent 619f25b commit 89ad246

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

backend/pyspur/utils/pydantic_utils.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55

66
def get_nested_field(field_name_with_dots: str, model: BaseModel) -> Any:
7-
"""
8-
Get the value of a nested field from a Pydantic model.
9-
"""
7+
"""Get the value of a nested field from a Pydantic model."""
108
field_names = field_name_with_dots.split(".")
119
value = model
1210
for field_name in field_names:
@@ -18,9 +16,7 @@ def get_nested_field(field_name_with_dots: str, model: BaseModel) -> Any:
1816

1917

2018
def get_jinja_template_for_model(model: BaseModel) -> str:
21-
"""
22-
Generate a Jinja template for a Pydantic model.
23-
"""
19+
"""Generate a Jinja template for a Pydantic model."""
2420
template = "{\n"
2521
for field_name, _field in model.model_fields.items():
2622
template += f'"{field_name}": {{{{field_name}}}},\n'
@@ -33,16 +29,17 @@ def json_schema_to_model(
3329
model_class_name: str = "Output",
3430
base_class: Type[BaseModel] = BaseModel,
3531
) -> Type[BaseModel]:
36-
"""
37-
Converts a JSON schema to a Pydantic BaseModel class.
32+
"""Convert a JSON schema to a Pydantic BaseModel class.
3833
3934
Args:
4035
json_schema: The JSON schema to convert.
36+
model_class_name: The name of the model class to create.
37+
base_class: The base class for the model (default is BaseModel).
4138
4239
Returns:
4340
A Pydantic BaseModel class.
44-
"""
4541
42+
"""
4643
# Extract the model name from the schema title.
4744
model_name = model_class_name
4845

@@ -59,17 +56,17 @@ def json_schema_to_model(
5956
def json_schema_to_pydantic_field(
6057
name: str, json_schema: Dict[str, Any], required: List[str]
6158
) -> Any:
62-
"""
63-
Converts a JSON schema property to a Pydantic field definition.
59+
"""Convert a JSON schema property to a Pydantic field definition.
6460
6561
Args:
6662
name: The field name.
6763
json_schema: The JSON schema property.
64+
required: A list of required fields.
6865
6966
Returns:
7067
A Pydantic field definition.
71-
"""
7268
69+
"""
7370
# Get the field type.
7471
type_ = json_schema_to_pydantic_type(json_schema)
7572

@@ -92,16 +89,15 @@ def json_schema_to_pydantic_field(
9289

9390

9491
def json_schema_to_pydantic_type(json_schema: Dict[str, Any]) -> Any:
95-
"""
96-
Converts a JSON schema type to a Pydantic type.
92+
"""Convert a JSON schema type to a Pydantic type.
9793
9894
Args:
9995
json_schema: The JSON schema to convert.
10096
10197
Returns:
10298
A Pydantic type.
103-
"""
10499
100+
"""
105101
type_ = json_schema.get("type")
106102

107103
if type_ == "string":
@@ -134,14 +130,14 @@ def json_schema_to_pydantic_type(json_schema: Dict[str, Any]) -> Any:
134130

135131

136132
def json_schema_to_simple_schema(json_schema: Dict[str, Any]) -> Dict[str, str]:
137-
"""
138-
Converts a JSON schema to a simple schema.
133+
"""Convert a JSON schema to a simple schema.
139134
140135
Args:
141136
json_schema: The JSON schema to convert.
142137
143138
Returns:
144139
A simple schema.
140+
145141
"""
146142
simple_schema: Dict[str, str] = {}
147143

0 commit comments

Comments
 (0)