Skip to content

Commit be35141

Browse files
Joan FontanalsJohannesMessner
andcommitted
docs: apply suggestions from code review
Co-authored-by: Johannes Messner <[email protected]> Signed-off-by: Joan Fontanals <[email protected]> Signed-off-by: Joan Fontanals Martinez <[email protected]>
1 parent f39cadb commit be35141

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

docarray/utils/create.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ def create_new_model_cast_doclist_to_list(model: Any) -> BaseDoc:
88
"""
99
Take a Pydantic model and cast DocList fields into List fields.
1010
11-
This can be needed because of this limitation of Pydantic:
11+
This may be necessary due to limitations in Pydantic:
1212
13-
(https://docs.pydantic.dev/latest/blog/pydantic-v2/)
13+
https://github.com/docarray/docarray/issues/1521
14+
https://github.com/pydantic/pydantic/issues/1457
1415
1516
---
1617
@@ -30,7 +31,7 @@ class MyDoc(BaseDoc):
3031
3132
---
3233
:param model: The input model
33-
:return: A BaseDoc class dynamically created with List instead of DocList in the schema.
34+
:return: A new subclass of BaseDoc, where every DocList type in the schema is replaced by List.
3435
"""
3536
fields: Dict[str, Any] = {}
3637
for field_name, field in model.__annotations__.items():
@@ -48,12 +49,12 @@ class MyDoc(BaseDoc):
4849

4950

5051
def _get_field_type_from_schema(
51-
field_schema: Dict[str, Any],
52-
field_name: str,
53-
root_schema: Dict[str, Any],
54-
cached_models: Dict[str, Any],
55-
is_tensor: bool = False,
56-
num_recursions: int = 0,
52+
field_schema: Dict[str, Any],
53+
field_name: str,
54+
root_schema: Dict[str, Any],
55+
cached_models: Dict[str, Any],
56+
is_tensor: bool = False,
57+
num_recursions: int = 0,
5758
) -> type:
5859
"""
5960
Private method used to extract the corresponding field type from the schema.
@@ -179,16 +180,17 @@ def _get_field_type_from_schema(
179180

180181

181182
def create_base_doc_from_schema(
182-
schema: Dict[str, Any], base_doc_name: str, cached_models: Optional[Dict] = None
183+
schema: Dict[str, Any], base_doc_name: str, cached_models: Optional[Dict] = None
183184
) -> Type:
184185
"""
185-
Dynamically create a `BaseDoc` class from a `schema` of another `BaseDoc`.
186+
Dynamically create a `BaseDoc` subclass from a `schema` of another `BaseDoc`.
187+
186188
This method is intended to dynamically create a `BaseDoc` compatible with the schema
187-
of another BaseDoc that is not available in the context. For instance, you may have stored the schema
188-
as a JSON, or sent it to another service, etc ...
189+
of another BaseDoc. This is useful when that other `BaseDoc` is not available in the current scope. For instance, you may have stored the schema
190+
as a JSON, or sent it to another service, etc.
189191
190-
Due to this Pydantic limitation (https://docs.pydantic.dev/latest/blog/pydantic-v2/), we need to make sure that the
191-
input schema uses `List` and not `DocList`, therefore this is recommended to be used in combination with `create_new_model_cast_doclist_to_list`
192+
Due to this Pydantic limitation (https://github.com/docarray/docarray/issues/1521, https://github.com/pydantic/pydantic/issues/1457), we need to make sure that the
193+
input schema uses `List` and not `DocList`. Therefore this is recommended to be used in combination with `create_new_model_cast_doclist_to_list`
192194
to make sure that `DocLists` in schema are converted to `List`.
193195
194196
---

0 commit comments

Comments
 (0)