From 0a2bef4966147dff55c8055fe0b649a20bd3a209 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Tue, 11 May 2021 15:33:48 -0700 Subject: [PATCH 1/4] include message about api version targeted on changelog --- sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md index 77f71857398c..f64b4cc88f08 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md +++ b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md @@ -2,6 +2,8 @@ ## 3.1.0 (Unreleased) +This version of the SDK defaults to the latest supported API version, which currently is v2.1. + Note: this version will be the last to officially support Python 3.5, future versions will require Python 2.7 or Python 3.6+ **Breaking Changes** From 9d1cf2a96694e5911ab24f681f5fc801d6448bcc Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Tue, 11 May 2021 16:31:12 -0700 Subject: [PATCH 2/4] add type hints, docstrings to from_dict/to_dict and rename param d -> data --- .../azure/ai/formrecognizer/_models.py | 559 +++++++++++++----- 1 file changed, 416 insertions(+), 143 deletions(-) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py index 7ec1f0b1a638..754e66072825 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py @@ -140,11 +140,24 @@ def __new__(cls, x, y): return super(Point, cls).__new__(cls, x, y) def to_dict(self): + # type: () -> dict + """Returns a dict representation of Point. + + :return: dict + :rtype: dict + """ return {"x": self.x, "y": self.y} @classmethod - def from_dict(cls, d): - return cls(x=d.get("x", None), y=d.get("y", None)) + def from_dict(cls, data): + # type: (dict) -> Point + """Converts a dict in the shape of a Point to the model itself. + + :param dict data: A dictionary in the shape of Point. + :return: Point + :rtype: Point + """ + return cls(x=data.get("x", None), y=data.get("y", None)) class FormPageRange(namedtuple("FormPageRange", "first_page_number last_page_number")): @@ -162,16 +175,29 @@ def __new__(cls, first_page_number, last_page_number): ) def to_dict(self): + # type: () -> dict + """Returns a dict representation of FormPageRange. + + :return: dict + :rtype: dict + """ return { "first_page_number": self.first_page_number, "last_page_number": self.last_page_number, } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> FormPageRange + """Converts a dict in the shape of a FormPageRange to the model itself. + + :param dict data: A dictionary in the shape of FormPageRange. + :return: FormPageRange + :rtype: FormPageRange + """ return cls( - first_page_number=d.get("first_page_number", None), - last_page_number=d.get("last_page_number", None), + first_page_number=data.get("first_page_number", None), + last_page_number=data.get("last_page_number", None), ) @@ -199,6 +225,12 @@ def __init__(self, **kwargs): self.kind = kwargs.get("kind", None) def to_dict(self): + # type: () -> dict + """Returns a dict representation of FormElement. + + :return: dict + :rtype: dict + """ return { "text": self.text, "bounding_box": [f.to_dict() for f in self.bounding_box] if self.bounding_box else [], @@ -207,13 +239,20 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> FormElement + """Converts a dict in the shape of a FormElement to the model itself. + + :param dict data: A dictionary in the shape of FormElement. + :return: FormElement + :rtype: FormElement + """ return cls( - text=d.get("text", None), - page_number=d.get("page_number", None), - kind=d.get("kind", None), - bounding_box=[Point.from_dict(f) for f in d.get("bounding_box")] - if len(d.get("bounding_box", [])) > 0 + text=data.get("text", None), + page_number=data.get("page_number", None), + kind=data.get("kind", None), + bounding_box=[Point.from_dict(f) for f in data.get("bounding_box")] + if len(data.get("bounding_box", [])) > 0 else [], ) @@ -269,6 +308,12 @@ def __repr__(self): ) def to_dict(self): + # type: () -> dict + """Returns a dict representation of RecognizedForm. + + :return: dict + :rtype: dict + """ return { "fields": {k: v.to_dict() for k, v in self.fields.items()} if self.fields @@ -281,17 +326,24 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> RecognizedForm + """Converts a dict in the shape of a RecognizedForm to the model itself. + + :param dict data: A dictionary in the shape of RecognizedForm. + :return: RecognizedForm + :rtype: RecognizedForm + """ return cls( - fields={k: FormField.from_dict(v) for k, v in d.get("fields").items()} if d.get("fields") else {}, - form_type=d.get("form_type", None), - pages=[FormPage.from_dict(v) for v in d.get("pages")] - if len(d.get("pages", [])) > 0 + fields={k: FormField.from_dict(v) for k, v in data.get("fields").items()} if data.get("fields") else {}, + form_type=data.get("form_type", None), + pages=[FormPage.from_dict(v) for v in data.get("pages")] + if len(data.get("pages", [])) > 0 else [], - model_id=d.get("model_id", None), - form_type_confidence=d.get("form_type_confidence", None), - page_range=FormPageRange.from_dict(d.get("page_range")) - if d.get("page_range") + model_id=data.get("model_id", None), + form_type_confidence=data.get("form_type_confidence", None), + page_range=FormPageRange.from_dict(data.get("page_range")) + if data.get("page_range") else None, ) @@ -367,6 +419,12 @@ def __repr__(self): ] def to_dict(self): + # type: () -> dict + """Returns a dict representation of FormField. + + :return: dict + :rtype: dict + """ value = self.value if isinstance(self.value, dict): value = {k: v.to_dict() for k, v in self.value.items()} @@ -382,23 +440,30 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): - value = d.get("value", None) - if isinstance(d.get("value"), dict): - value = {k: FormField.from_dict(v) for k, v in d.get("value").items()} - elif isinstance(d.get("value"), list): - value = [FormField.from_dict(v) for v in d.get("value")] + def from_dict(cls, data): + # type: (dict) -> FormField + """Converts a dict in the shape of a FormField to the model itself. + + :param dict data: A dictionary in the shape of FormField. + :return: FormField + :rtype: FormField + """ + value = data.get("value", None) + if isinstance(data.get("value"), dict): + value = {k: FormField.from_dict(v) for k, v in data.get("value").items()} + elif isinstance(data.get("value"), list): + value = [FormField.from_dict(v) for v in data.get("value")] return cls( - value_type=d.get("value_type", None), - name=d.get("name", None), + value_type=data.get("value_type", None), + name=data.get("name", None), value=value, - confidence=d.get("confidence", None), - label_data=FieldData.from_dict(d.get("label_data")) - if d.get("label_data") + confidence=data.get("confidence", None), + label_data=FieldData.from_dict(data.get("label_data")) + if data.get("label_data") else None, - value_data=FieldData.from_dict(d.get("value_data")) - if d.get("value_data") + value_data=FieldData.from_dict(data.get("value_data")) + if data.get("value_data") else None, ) @@ -472,6 +537,12 @@ def __repr__(self): ] def to_dict(self): + # type: () -> dict + """Returns a dict representation of FieldData. + + :return: dict + :rtype: dict + """ return { "text": self.text, "bounding_box": [f.to_dict() for f in self.bounding_box] if self.bounding_box else [], @@ -480,9 +551,16 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> FieldData + """Converts a dict in the shape of a FieldData to the model itself. + + :param dict data: A dictionary in the shape of FieldData. + :return: FieldData + :rtype: FieldData + """ field_elements = [] - for v in d.get("field_elements"): + for v in data.get("field_elements"): if v.get("kind") == "word": field_elements.append(FormWord.from_dict(v)) elif v.get("kind") == "line": @@ -493,10 +571,10 @@ def from_dict(cls, d): field_elements.append(FormElement.from_dict(v)) return cls( - text=d.get("text", None), - page_number=d.get("page_number", None), - bounding_box=[Point.from_dict(f) for f in d.get("bounding_box")] - if len(d.get("bounding_box", [])) > 0 + text=data.get("text", None), + page_number=data.get("page_number", None), + bounding_box=[Point.from_dict(f) for f in data.get("bounding_box")] + if len(data.get("bounding_box", [])) > 0 else [], field_elements=field_elements, ) @@ -561,6 +639,12 @@ def __repr__(self): ) def to_dict(self): + # type: () -> dict + """Returns a dict representation of FormPage. + + :return: dict + :rtype: dict + """ return { "page_number": self.page_number, "text_angle": self.text_angle, @@ -573,23 +657,30 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> FormPage + """Converts a dict in the shape of a FormPage to the model itself. + + :param dict data: A dictionary in the shape of FormPage. + :return: FormPage + :rtype: FormPage + """ return cls( - text_angle=d.get("text_angle", None), - width=d.get("width", None), - height=d.get("height", None), - unit=d.get("unit", None), - page_number=d.get("page_number", None), - tables=[FormTable.from_dict(v) for v in d.get("tables")] - if len(d.get("tables", [])) > 0 + text_angle=data.get("text_angle", None), + width=data.get("width", None), + height=data.get("height", None), + unit=data.get("unit", None), + page_number=data.get("page_number", None), + tables=[FormTable.from_dict(v) for v in data.get("tables")] + if len(data.get("tables", [])) > 0 else [], - lines=[FormLine.from_dict(v) for v in d.get("lines")] - if len(d.get("lines", [])) > 0 + lines=[FormLine.from_dict(v) for v in data.get("lines")] + if len(data.get("lines", [])) > 0 else [], selection_marks=[ - FormSelectionMark.from_dict(v) for v in d.get("selection_marks") + FormSelectionMark.from_dict(v) for v in data.get("selection_marks") ] - if len(d.get("selection_marks", [])) > 0 + if len(data.get("selection_marks", [])) > 0 else [], ) @@ -650,6 +741,12 @@ def __repr__(self): ] def to_dict(self): + # type: () -> dict + """Returns a dict representation of FormLine. + + :return: dict + :rtype: dict + """ return { "text": self.text, "bounding_box": [f.to_dict() for f in self.bounding_box] if self.bounding_box else [], @@ -660,18 +757,25 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> FormLine + """Converts a dict in the shape of a FormLine to the model itself. + + :param dict data: A dictionary in the shape of FormLine. + :return: FormLine + :rtype: FormLine + """ return cls( - text=d.get("text", None), - page_number=d.get("page_number", None), - bounding_box=[Point.from_dict(v) for v in d.get("bounding_box")] - if len(d.get("bounding_box", [])) > 0 + text=data.get("text", None), + page_number=data.get("page_number", None), + bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] + if len(data.get("bounding_box", [])) > 0 else [], - words=[FormWord.from_dict(v) for v in d.get("words")] - if len(d.get("words", [])) > 0 + words=[FormWord.from_dict(v) for v in data.get("words")] + if len(data.get("words", [])) > 0 else [], - appearance=TextAppearance.from_dict(d.get("appearance")) - if d.get("appearance") + appearance=TextAppearance.from_dict(data.get("appearance")) + if data.get("appearance") else None, ) @@ -713,6 +817,12 @@ def __repr__(self): ] def to_dict(self): + # type: () -> dict + """Returns a dict representation of FormWord. + + :return: dict + :rtype: dict + """ return { "text": self.text, "bounding_box": [f.to_dict() for f in self.bounding_box] if self.bounding_box else [], @@ -722,14 +832,21 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> FormWord + """Converts a dict in the shape of a FormWord to the model itself. + + :param dict data: A dictionary in the shape of FormWord. + :return: FormWord + :rtype: FormWord + """ return cls( - text=d.get("text", None), - page_number=d.get("page_number", None), - bounding_box=[Point.from_dict(v) for v in d.get("bounding_box")] - if len(d.get("bounding_box", [])) > 0 + text=data.get("text", None), + page_number=data.get("page_number", None), + bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] + if len(data.get("bounding_box", [])) > 0 else [], - confidence=d.get("confidence", None), + confidence=data.get("confidence", None), ) @@ -773,6 +890,12 @@ def __repr__(self): ] def to_dict(self): + # type: () -> dict + """Returns a dict representation of FormSelectionMark. + + :return: dict + :rtype: dict + """ return { "text": self.text, "bounding_box": [f.to_dict() for f in self.bounding_box] if self.bounding_box else [], @@ -783,15 +906,22 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> FormSelectionMark + """Converts a dict in the shape of a FormSelectionMark to the model itself. + + :param dict data: A dictionary in the shape of FormSelectionMark. + :return: FormSelectionMark + :rtype: FormSelectionMark + """ return cls( - text=d.get("text", None), - page_number=d.get("page_number", None), - bounding_box=[Point.from_dict(v) for v in d.get("bounding_box")] - if len(d.get("bounding_box", [])) > 0 + text=data.get("text", None), + page_number=data.get("page_number", None), + bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] + if len(data.get("bounding_box", [])) > 0 else [], - confidence=d.get("confidence", None), - state=d.get("state", None), + confidence=data.get("confidence", None), + state=data.get("state", None), ) @@ -835,6 +965,12 @@ def __repr__(self): ] def to_dict(self): + # type: () -> dict + """Returns a dict representation of FormTable. + + :return: dict + :rtype: dict + """ return { "page_number": self.page_number, "row_count": self.row_count, @@ -844,16 +980,23 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> FormTable + """Converts a dict in the shape of a FormTable to the model itself. + + :param dict data: A dictionary in the shape of FormTable. + :return: FormTable + :rtype: FormTable + """ return cls( - row_count=d.get("row_count", None), - page_number=d.get("page_number", None), - column_count=d.get("column_count", None), - bounding_box=[Point.from_dict(v) for v in d.get("bounding_box")] - if len(d.get("bounding_box", [])) > 0 + row_count=data.get("row_count", None), + page_number=data.get("page_number", None), + column_count=data.get("column_count", None), + bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] + if len(data.get("bounding_box", [])) > 0 else [], - cells=[FormTableCell.from_dict(v) for v in d.get("cells")] - if len(d.get("cells", [])) > 0 + cells=[FormTableCell.from_dict(v) for v in data.get("cells")] + if len(data.get("cells", [])) > 0 else [], ) @@ -943,6 +1086,12 @@ def __repr__(self): ) def to_dict(self): + # type: () -> dict + """Returns a dict representation of FormTableCell. + + :return: dict + :rtype: dict + """ return { "text": self.text, "row_index": self.row_index, @@ -959,9 +1108,16 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> FormTableCell + """Converts a dict in the shape of a FormTableCell to the model itself. + + :param dict data: A dictionary in the shape of FormTableCell. + :return: FormTableCell + :rtype: FormTableCell + """ field_elements = [] - for v in d.get("field_elements"): + for v in data.get("field_elements"): if v.get("kind") == "word": field_elements.append(FormWord.from_dict(v)) elif v.get("kind") == "line": @@ -972,17 +1128,17 @@ def from_dict(cls, d): field_elements.append(FormElement.from_dict(v)) return cls( - text=d.get("text", None), - row_index=d.get("row_index", None), - column_index=d.get("column_index", None), - row_span=d.get("row_span", None), - column_span=d.get("column_span", None), - confidence=d.get("confidence", None), - is_header=d.get("is_header", None), - is_footer=d.get("is_footer", None), - page_number=d.get("page_number", None), - bounding_box=[Point.from_dict(v) for v in d.get("bounding_box")] - if len(d.get("bounding_box", [])) > 0 + text=data.get("text", None), + row_index=data.get("row_index", None), + column_index=data.get("column_index", None), + row_span=data.get("row_span", None), + column_span=data.get("column_span", None), + confidence=data.get("confidence", None), + is_header=data.get("is_header", None), + is_footer=data.get("is_footer", None), + page_number=data.get("page_number", None), + bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] + if len(data.get("bounding_box", [])) > 0 else [], field_elements=field_elements, ) @@ -1090,6 +1246,12 @@ def __repr__(self): ) def to_dict(self): + # type: () -> dict + """Returns a dict representation of CustomFormModel. + + :return: dict + :rtype: dict + """ return { "model_id": self.model_id, "status": self.status, @@ -1103,26 +1265,33 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> CustomFormModel + """Converts a dict in the shape of a CustomFormModel to the model itself. + + :param dict data: A dictionary in the shape of CustomFormModel. + :return: CustomFormModel + :rtype: CustomFormModel + """ return cls( - model_id=d.get("model_id", None), - status=d.get("status", None), - training_started_on=d.get("training_started_on", None), - training_completed_on=d.get("training_completed_on", None), - submodels=[CustomFormSubmodel.from_dict(v) for v in d.get("submodels")] - if len(d.get("submodels", [])) > 0 + model_id=data.get("model_id", None), + status=data.get("status", None), + training_started_on=data.get("training_started_on", None), + training_completed_on=data.get("training_completed_on", None), + submodels=[CustomFormSubmodel.from_dict(v) for v in data.get("submodels")] + if len(data.get("submodels", [])) > 0 else [], - errors=[FormRecognizerError.from_dict(v) for v in d.get("errors")] - if len(d.get("errors", [])) > 0 + errors=[FormRecognizerError.from_dict(v) for v in data.get("errors")] + if len(data.get("errors", [])) > 0 else [], training_documents=[ - TrainingDocumentInfo.from_dict(v) for v in d.get("training_documents") + TrainingDocumentInfo.from_dict(v) for v in data.get("training_documents") ] - if len(d.get("training_documents", [])) > 0 + if len(data.get("training_documents", [])) > 0 else [], - model_name=d.get("model_name", None), - properties=CustomFormModelProperties.from_dict(d.get("properties")) - if d.get("properties") + model_name=data.get("model_name", None), + properties=CustomFormModelProperties.from_dict(data.get("properties")) + if data.get("properties") else None, ) @@ -1221,6 +1390,12 @@ def __repr__(self): ] def to_dict(self): + # type: () -> dict + """Returns a dict representation of CustomFormSubmodel. + + :return: dict + :rtype: dict + """ return { "model_id": self.model_id, "accuracy": self.accuracy, @@ -1229,13 +1404,20 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> CustomFormSubmodel + """Converts a dict in the shape of a CustomFormSubmodel to the model itself. + + :param dict data: A dictionary in the shape of CustomFormSubmodel. + :return: CustomFormSubmodel + :rtype: CustomFormSubmodel + """ return cls( - model_id=d.get("model_id", None), - accuracy=d.get("accuracy", None), - fields={k: CustomFormModelField.from_dict(v) for k, v in d.get("fields").items()} - if d.get("fields") else {}, - form_type=d.get("form_type", None), + model_id=data.get("model_id", None), + accuracy=data.get("accuracy", None), + fields={k: CustomFormModelField.from_dict(v) for k, v in data.get("fields").items()} + if data.get("fields") else {}, + form_type=data.get("form_type", None), ) @@ -1272,6 +1454,12 @@ def __repr__(self): )[:1024] def to_dict(self): + # type: () -> dict + """Returns a dict representation of CustomFormModelField. + + :return: dict + :rtype: dict + """ return { "label": self.label, "accuracy": self.accuracy, @@ -1279,11 +1467,18 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> CustomFormModelField + """Converts a dict in the shape of a CustomFormModelField to the model itself. + + :param dict data: A dictionary in the shape of CustomFormModelField. + :return: CustomFormModelField + :rtype: CustomFormModelField + """ return cls( - label=d.get("label", None), - accuracy=d.get("accuracy", None), - name=d.get("name", None), + label=data.get("label", None), + accuracy=data.get("accuracy", None), + name=data.get("name", None), ) @@ -1358,6 +1553,12 @@ def __repr__(self): ] def to_dict(self): + # type: () -> dict + """Returns a dict representation of TrainingDocumentInfo. + + :return: dict + :rtype: dict + """ return { "name": self.name, "status": self.status, @@ -1367,15 +1568,22 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> TrainingDocumentInfo + """Converts a dict in the shape of a TrainingDocumentInfo to the model itself. + + :param dict data: A dictionary in the shape of TrainingDocumentInfo. + :return: TrainingDocumentInfo + :rtype: TrainingDocumentInfo + """ return cls( - name=d.get("name", None), - status=d.get("status", None), - page_count=d.get("page_count", None), + name=data.get("name", None), + status=data.get("status", None), + page_count=data.get("page_count", None), errors=[ - FormRecognizerError.from_dict(v) for v in d.get("errors") + FormRecognizerError.from_dict(v) for v in data.get("errors") ], - model_id=d.get("model_id", None), + model_id=data.get("model_id", None), ) @@ -1404,16 +1612,29 @@ def __repr__(self): )[:1024] def to_dict(self): + # type: () -> dict + """Returns a dict representation of FormRecognizerError. + + :return: dict + :rtype: dict + """ return { "code": self.code, "message": self.message } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> FormRecognizerError + """Converts a dict in the shape of a FormRecognizerError to the model itself. + + :param dict data: A dictionary in the shape of FormRecognizerError. + :return: FormRecognizerError + :rtype: FormRecognizerError + """ return cls( - code=d.get("code", None), - message=d.get("message", None), + code=data.get("code", None), + message=data.get("message", None), ) @@ -1482,6 +1703,12 @@ def __repr__(self): ) def to_dict(self): + # type: () -> dict + """Returns a dict representation of CustomFormModelInfo. + + :return: dict + :rtype: dict + """ return { "model_id": self.model_id, "status": self.status, @@ -1492,15 +1719,22 @@ def to_dict(self): } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> CustomFormModelInfo + """Converts a dict in the shape of a CustomFormModelInfo to the model itself. + + :param dict data: A dictionary in the shape of CustomFormModelInfo. + :return: CustomFormModelInfo + :rtype: CustomFormModelInfo + """ return cls( - model_id=d.get("model_id", None), - status=d.get("status", None), - training_started_on=d.get("training_started_on", None), - training_completed_on=d.get("training_completed_on", None), - model_name=d.get("model_name", None), - properties=CustomFormModelProperties.from_dict(d.get("properties")) - if d.get("properties") + model_id=data.get("model_id", None), + status=data.get("status", None), + training_started_on=data.get("training_started_on", None), + training_completed_on=data.get("training_completed_on", None), + model_name=data.get("model_name", None), + properties=CustomFormModelProperties.from_dict(data.get("properties")) + if data.get("properties") else None, ) @@ -1529,16 +1763,29 @@ def __repr__(self): )[:1024] def to_dict(self): + # type: () -> dict + """Returns a dict representation of AccountProperties. + + :return: dict + :rtype: dict + """ return { "custom_model_count": self.custom_model_count, "custom_model_limit": self.custom_model_limit } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> AccountProperties + """Converts a dict in the shape of a AccountProperties to the model itself. + + :param dict data: A dictionary in the shape of AccountProperties. + :return: AccountProperties + :rtype: AccountProperties + """ return cls( - custom_model_count=d.get("custom_model_count", None), - custom_model_limit=d.get("custom_model_limit", None), + custom_model_count=data.get("custom_model_count", None), + custom_model_limit=data.get("custom_model_limit", None), ) @@ -1563,14 +1810,27 @@ def __repr__(self): ) def to_dict(self): + # type: () -> dict + """Returns a dict representation of CustomFormModelProperties. + + :return: dict + :rtype: dict + """ return { "is_composed_model": self.is_composed_model } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> CustomFormModelProperties + """Converts a dict in the shape of a CustomFormModelProperties to the model itself. + + :param dict data: A dictionary in the shape of CustomFormModelProperties. + :return: CustomFormModelProperties + :rtype: CustomFormModelProperties + """ return cls( - is_composed_model=d.get("is_composed_model", None), + is_composed_model=data.get("is_composed_model", None), ) @@ -1599,14 +1859,27 @@ def __repr__(self): return "TextAppearance(style_name={}, style_confidence={})".format(self.style_name, self.style_confidence) def to_dict(self): + # type: () -> dict + """Returns a dict representation of TextAppearance. + + :return: dict + :rtype: dict + """ return { "style_name": self.style_name, "style_confidence": self.style_confidence } @classmethod - def from_dict(cls, d): + def from_dict(cls, data): + # type: (dict) -> TextAppearance + """Converts a dict in the shape of a TextAppearance to the model itself. + + :param dict data: A dictionary in the shape of TextAppearance. + :return: TextAppearance + :rtype: TextAppearance + """ return cls( - style_name=d.get("style_name", None), - style_confidence=d.get("style_confidence", None), + style_name=data.get("style_name", None), + style_confidence=data.get("style_confidence", None), ) From d32293fc5eb10851c9b18cfddbc60476f1f10860 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Tue, 11 May 2021 16:31:53 -0700 Subject: [PATCH 3/4] remove period at end of sentence --- sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md index f64b4cc88f08..459f22edab0f 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md +++ b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md @@ -2,7 +2,7 @@ ## 3.1.0 (Unreleased) -This version of the SDK defaults to the latest supported API version, which currently is v2.1. +This version of the SDK defaults to the latest supported API version, which currently is v2.1 Note: this version will be the last to officially support Python 3.5, future versions will require Python 2.7 or Python 3.6+ From 01d1e71189d503f4b9b8247237adaffc1b24468a Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Tue, 11 May 2021 17:06:25 -0700 Subject: [PATCH 4/4] mypy --- .../azure/ai/formrecognizer/_models.py | 73 ++++++++++--------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py index 754e66072825..7f4d74dd78eb 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py @@ -251,7 +251,7 @@ def from_dict(cls, data): text=data.get("text", None), page_number=data.get("page_number", None), kind=data.get("kind", None), - bounding_box=[Point.from_dict(f) for f in data.get("bounding_box")] + bounding_box=[Point.from_dict(f) for f in data.get("bounding_box")] # type: ignore if len(data.get("bounding_box", [])) > 0 else [], ) @@ -335,14 +335,15 @@ def from_dict(cls, data): :rtype: RecognizedForm """ return cls( - fields={k: FormField.from_dict(v) for k, v in data.get("fields").items()} if data.get("fields") else {}, + fields={k: FormField.from_dict(v) for k, v in data.get("fields").items()} # type: ignore + if data.get("fields") else {}, form_type=data.get("form_type", None), - pages=[FormPage.from_dict(v) for v in data.get("pages")] + pages=[FormPage.from_dict(v) for v in data.get("pages")] # type: ignore if len(data.get("pages", [])) > 0 else [], model_id=data.get("model_id", None), form_type_confidence=data.get("form_type_confidence", None), - page_range=FormPageRange.from_dict(data.get("page_range")) + page_range=FormPageRange.from_dict(data.get("page_range")) # type: ignore if data.get("page_range") else None, ) @@ -450,19 +451,19 @@ def from_dict(cls, data): """ value = data.get("value", None) if isinstance(data.get("value"), dict): - value = {k: FormField.from_dict(v) for k, v in data.get("value").items()} + value = {k: FormField.from_dict(v) for k, v in data.get("value").items()} # type: ignore elif isinstance(data.get("value"), list): - value = [FormField.from_dict(v) for v in data.get("value")] + value = [FormField.from_dict(v) for v in data.get("value")] # type: ignore return cls( value_type=data.get("value_type", None), name=data.get("name", None), value=value, confidence=data.get("confidence", None), - label_data=FieldData.from_dict(data.get("label_data")) + label_data=FieldData.from_dict(data.get("label_data")) # type: ignore if data.get("label_data") else None, - value_data=FieldData.from_dict(data.get("value_data")) + value_data=FieldData.from_dict(data.get("value_data")) # type: ignore if data.get("value_data") else None, ) @@ -560,20 +561,20 @@ def from_dict(cls, data): :rtype: FieldData """ field_elements = [] - for v in data.get("field_elements"): + for v in data.get("field_elements"): # type: ignore if v.get("kind") == "word": field_elements.append(FormWord.from_dict(v)) elif v.get("kind") == "line": - field_elements.append(FormLine.from_dict(v)) + field_elements.append(FormLine.from_dict(v)) # type: ignore elif v.get("kind") == "selectionMark": - field_elements.append(FormSelectionMark.from_dict(v)) + field_elements.append(FormSelectionMark.from_dict(v)) # type: ignore else: - field_elements.append(FormElement.from_dict(v)) + field_elements.append(FormElement.from_dict(v)) # type: ignore return cls( text=data.get("text", None), page_number=data.get("page_number", None), - bounding_box=[Point.from_dict(f) for f in data.get("bounding_box")] + bounding_box=[Point.from_dict(f) for f in data.get("bounding_box")] # type: ignore if len(data.get("bounding_box", [])) > 0 else [], field_elements=field_elements, @@ -671,14 +672,14 @@ def from_dict(cls, data): height=data.get("height", None), unit=data.get("unit", None), page_number=data.get("page_number", None), - tables=[FormTable.from_dict(v) for v in data.get("tables")] + tables=[FormTable.from_dict(v) for v in data.get("tables")] # type: ignore if len(data.get("tables", [])) > 0 else [], - lines=[FormLine.from_dict(v) for v in data.get("lines")] + lines=[FormLine.from_dict(v) for v in data.get("lines")] # type: ignore if len(data.get("lines", [])) > 0 else [], selection_marks=[ - FormSelectionMark.from_dict(v) for v in data.get("selection_marks") + FormSelectionMark.from_dict(v) for v in data.get("selection_marks") # type: ignore ] if len(data.get("selection_marks", [])) > 0 else [], @@ -768,13 +769,13 @@ def from_dict(cls, data): return cls( text=data.get("text", None), page_number=data.get("page_number", None), - bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] + bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] # type: ignore if len(data.get("bounding_box", [])) > 0 else [], - words=[FormWord.from_dict(v) for v in data.get("words")] + words=[FormWord.from_dict(v) for v in data.get("words")] # type: ignore if len(data.get("words", [])) > 0 else [], - appearance=TextAppearance.from_dict(data.get("appearance")) + appearance=TextAppearance.from_dict(data.get("appearance")) # type: ignore if data.get("appearance") else None, ) @@ -843,7 +844,7 @@ def from_dict(cls, data): return cls( text=data.get("text", None), page_number=data.get("page_number", None), - bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] + bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] # type: ignore if len(data.get("bounding_box", [])) > 0 else [], confidence=data.get("confidence", None), @@ -917,7 +918,7 @@ def from_dict(cls, data): return cls( text=data.get("text", None), page_number=data.get("page_number", None), - bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] + bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] # type: ignore if len(data.get("bounding_box", [])) > 0 else [], confidence=data.get("confidence", None), @@ -992,10 +993,10 @@ def from_dict(cls, data): row_count=data.get("row_count", None), page_number=data.get("page_number", None), column_count=data.get("column_count", None), - bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] + bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] # type: ignore if len(data.get("bounding_box", [])) > 0 else [], - cells=[FormTableCell.from_dict(v) for v in data.get("cells")] + cells=[FormTableCell.from_dict(v) for v in data.get("cells")] # type: ignore if len(data.get("cells", [])) > 0 else [], ) @@ -1117,15 +1118,15 @@ def from_dict(cls, data): :rtype: FormTableCell """ field_elements = [] - for v in data.get("field_elements"): + for v in data.get("field_elements"): # type: ignore if v.get("kind") == "word": - field_elements.append(FormWord.from_dict(v)) + field_elements.append(FormWord.from_dict(v)) # type: ignore elif v.get("kind") == "line": - field_elements.append(FormLine.from_dict(v)) + field_elements.append(FormLine.from_dict(v)) # type: ignore elif v.get("kind") == "selectionMark": - field_elements.append(FormSelectionMark.from_dict(v)) + field_elements.append(FormSelectionMark.from_dict(v)) # type: ignore else: - field_elements.append(FormElement.from_dict(v)) + field_elements.append(FormElement.from_dict(v)) # type: ignore return cls( text=data.get("text", None), @@ -1137,7 +1138,7 @@ def from_dict(cls, data): is_header=data.get("is_header", None), is_footer=data.get("is_footer", None), page_number=data.get("page_number", None), - bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] + bounding_box=[Point.from_dict(v) for v in data.get("bounding_box")] # type: ignore if len(data.get("bounding_box", [])) > 0 else [], field_elements=field_elements, @@ -1278,19 +1279,19 @@ def from_dict(cls, data): status=data.get("status", None), training_started_on=data.get("training_started_on", None), training_completed_on=data.get("training_completed_on", None), - submodels=[CustomFormSubmodel.from_dict(v) for v in data.get("submodels")] + submodels=[CustomFormSubmodel.from_dict(v) for v in data.get("submodels")] # type: ignore if len(data.get("submodels", [])) > 0 else [], - errors=[FormRecognizerError.from_dict(v) for v in data.get("errors")] + errors=[FormRecognizerError.from_dict(v) for v in data.get("errors")] # type: ignore if len(data.get("errors", [])) > 0 else [], training_documents=[ - TrainingDocumentInfo.from_dict(v) for v in data.get("training_documents") + TrainingDocumentInfo.from_dict(v) for v in data.get("training_documents") # type: ignore ] if len(data.get("training_documents", [])) > 0 else [], model_name=data.get("model_name", None), - properties=CustomFormModelProperties.from_dict(data.get("properties")) + properties=CustomFormModelProperties.from_dict(data.get("properties")) # type: ignore if data.get("properties") else None, ) @@ -1415,7 +1416,7 @@ def from_dict(cls, data): return cls( model_id=data.get("model_id", None), accuracy=data.get("accuracy", None), - fields={k: CustomFormModelField.from_dict(v) for k, v in data.get("fields").items()} + fields={k: CustomFormModelField.from_dict(v) for k, v in data.get("fields").items()} # type: ignore if data.get("fields") else {}, form_type=data.get("form_type", None), ) @@ -1581,7 +1582,7 @@ def from_dict(cls, data): status=data.get("status", None), page_count=data.get("page_count", None), errors=[ - FormRecognizerError.from_dict(v) for v in data.get("errors") + FormRecognizerError.from_dict(v) for v in data.get("errors") # type: ignore ], model_id=data.get("model_id", None), ) @@ -1733,7 +1734,7 @@ def from_dict(cls, data): training_started_on=data.get("training_started_on", None), training_completed_on=data.get("training_completed_on", None), model_name=data.get("model_name", None), - properties=CustomFormModelProperties.from_dict(data.get("properties")) + properties=CustomFormModelProperties.from_dict(data.get("properties")) # type: ignore if data.get("properties") else None, )