Skip to content

Commit

Permalink
update typing and add __str__ for currency (Azure#25224)
Browse files Browse the repository at this point in the history
  • Loading branch information
catalinaperalta authored Jul 15, 2022
1 parent d0c5385 commit 8535cf2
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1972,7 +1972,7 @@ def from_dict(cls, data: dict) -> "TextAppearance":
class BoundingRegion:
"""The bounding region corresponding to a page.
:ivar list[~azure.ai.formrecognizer.Point] polygon:
:ivar Optional[list[~azure.ai.formrecognizer.Point]] polygon:
A list of points representing the bounding polygon
that outlines the document component. The points are listed in
clockwise order relative to the document component orientation
Expand Down Expand Up @@ -2029,22 +2029,22 @@ class AddressValue:
"""An address field value.
:ivar house_number: House or building number.
:vartype house_number: str
:vartype house_number: Optional[str]
:ivar po_box: Post office box number.
:vartype po_box: str
:vartype po_box: Optional[str]
:ivar road: Street name.
:vartype road: str
:vartype road: Optional[str]
:ivar city: Name of city, town, village, etc.
:vartype city: str
:vartype city: Optional[str]
:ivar state: First-level administrative division.
:vartype state: str
:vartype state: Optional[str]
:ivar postal_code: Postal code used for mail sorting.
:vartype postal_code: str
:vartype postal_code: Optional[str]
:ivar country_region: Country/region.
:vartype country_region: str
:vartype country_region: Optional[str]
:ivar street_address: Street-level address, excluding city, state, countryRegion, and
postalCode.
:vartype street_address: str
:vartype street_address: Optional[str]
"""

def __init__(self, **kwargs):
Expand Down Expand Up @@ -2120,7 +2120,7 @@ class CurrencyValue:
:ivar amount: The currency amount.
:vartype: float
:ivar symbol: The currency symbol, if found.
:vartype: str
:vartype: Optional[str]
"""

def __init__(self, **kwargs):
Expand All @@ -2134,6 +2134,11 @@ def _from_generated(cls, data):
symbol=data.currency_symbol,
)

def __str__(self):
if self.symbol is not None:
return f"{self.symbol}{self.amount}"
return f"{self.amount}"

def __repr__(self):
return f"CurrencyValue(amount={self.amount}, symbol={self.symbol})"

Expand Down Expand Up @@ -2168,7 +2173,7 @@ class DocumentContentElement:
:ivar content: Text content of the document content element.
:vartype content: str
:ivar polygon: Bounding polygon of the document content element.
:vartype polygon: list[~azure.ai.formrecognizer.Point]
:vartype polygon: Optional[list[~azure.ai.formrecognizer.Point]]
:ivar span: Location of the element in the full document content.
:vartype span: ~azure.ai.formrecognizer.DocumentSpan
:ivar confidence: Confidence of accurately extracting the document content element.
Expand Down Expand Up @@ -2292,11 +2297,11 @@ class AnalyzedDocument:
:ivar doc_type: The type of document that was analyzed.
:vartype doc_type: str
:ivar bounding_regions: Bounding regions covering the document.
:vartype bounding_regions: list[~azure.ai.formrecognizer.BoundingRegion]
:vartype bounding_regions: Optional[list[~azure.ai.formrecognizer.BoundingRegion]]
:ivar spans: The location of the document in the reading order concatenated content.
:vartype spans: list[~azure.ai.formrecognizer.DocumentSpan]
:ivar fields: A dictionary of named field values.
:vartype fields: dict[str, ~azure.ai.formrecognizer.DocumentField]
:vartype fields: Optional[dict[str, ~azure.ai.formrecognizer.DocumentField]]
:ivar confidence: Confidence of correctly extracting the document.
:vartype confidence: float
"""
Expand Down Expand Up @@ -2387,11 +2392,11 @@ class DocumentField:
dict[str, :class:`~azure.ai.formrecognizer.DocumentField`],
or list[:class:`~azure.ai.formrecognizer.DocumentField`]
:ivar content: The field's content.
:vartype content: str
:vartype content: Optional[str]
:ivar bounding_regions: Bounding regions covering the field.
:vartype bounding_regions: list[~azure.ai.formrecognizer.BoundingRegion]
:vartype bounding_regions: Optional[list[~azure.ai.formrecognizer.BoundingRegion]]
:ivar spans: Location of the field in the reading order concatenated content.
:vartype spans: list[~azure.ai.formrecognizer.DocumentSpan]
:vartype spans: Optional[list[~azure.ai.formrecognizer.DocumentSpan]]
:ivar confidence: The confidence of correctly extracting the field.
:vartype confidence: float
"""
Expand Down Expand Up @@ -2515,7 +2520,7 @@ class DocumentKeyValueElement:
:ivar content: Concatenated content of the key-value element in reading order.
:vartype content: str
:ivar bounding_regions: Bounding regions covering the key-value element.
:vartype bounding_regions: list[~azure.ai.formrecognizer.BoundingRegion]
:vartype bounding_regions: Optional[list[~azure.ai.formrecognizer.BoundingRegion]]
:ivar spans: Location of the key-value element in the reading order of the concatenated
content.
:vartype spans: list[~azure.ai.formrecognizer.DocumentSpan]
Expand Down Expand Up @@ -2653,7 +2658,7 @@ class DocumentLine:
:ivar content: Concatenated content of the contained elements in reading order.
:vartype content: str
:ivar polygon: Bounding polygon of the line.
:vartype polygon: list[~azure.ai.formrecognizer.Point]
:vartype polygon: Optional[list[~azure.ai.formrecognizer.Point]]
:ivar spans: Location of the line in the reading order concatenated content.
:vartype spans: list[~azure.ai.formrecognizer.DocumentSpan]
"""
Expand Down Expand Up @@ -2733,11 +2738,11 @@ class DocumentParagraph:
:ivar role: Semantic role of the paragraph. Known values are: "pageHeader", "pageFooter",
"pageNumber", "title", "sectionHeading", "footnote".
:vartype role: str
:vartype role: Optional[str]
:ivar content: Concatenated content of the paragraph in reading order.
:vartype content: str
:ivar bounding_regions: Bounding regions covering the paragraph.
:vartype bounding_regions: list[~azure.ai.formrecognizer.BoundingRegion]
:vartype bounding_regions: Optional[list[~azure.ai.formrecognizer.BoundingRegion]]
:ivar spans: Location of the paragraph in the reading order concatenated content.
:vartype spans: list[~azure.ai.formrecognizer.DocumentSpan]
"""
Expand Down Expand Up @@ -2810,25 +2815,25 @@ class DocumentPage:
:vartype page_number: int
:ivar angle: The general orientation of the content in clockwise direction, measured
in degrees between (-180, 180].
:vartype angle: float
:vartype angle: Optional[float]
:ivar width: The width of the image/PDF in pixels/inches, respectively.
:vartype width: float
:vartype width: Optional[float]
:ivar height: The height of the image/PDF in pixels/inches, respectively.
:vartype height: float
:vartype height: Optional[float]
:ivar unit: The unit used by the width, height, and bounding box properties. For
images, the unit is "pixel". For PDF, the unit is "inch". Possible values include: "pixel",
"inch".
:vartype unit: str
:vartype unit: Optional[str]
:ivar spans: Location of the page in the reading order concatenated content.
:vartype spans: list[~azure.ai.formrecognizer.DocumentSpan]
:ivar words: Extracted words from the page.
:vartype words: list[~azure.ai.formrecognizer.DocumentWord]
:vartype words: Optional[list[~azure.ai.formrecognizer.DocumentWord]]
:ivar selection_marks: Extracted selection marks from the page.
:vartype selection_marks:
list[~azure.ai.formrecognizer.DocumentSelectionMark]
Optional[list[~azure.ai.formrecognizer.DocumentSelectionMark]]
:ivar lines: Extracted lines from the page, potentially containing both textual and
visual elements.
:vartype lines: list[~azure.ai.formrecognizer.DocumentLine]
:vartype lines: Optional[list[~azure.ai.formrecognizer.DocumentLine]]
"""

def __init__(self, **kwargs):
Expand Down Expand Up @@ -2942,7 +2947,7 @@ class DocumentSelectionMark(DocumentContentElement):
:ivar content: The text content - not returned for DocumentSelectionMark.
:vartype content: str
:ivar polygon: Bounding polygon of the selection mark.
:vartype polygon: list[~azure.ai.formrecognizer.Point]
:vartype polygon: Optional[list[~azure.ai.formrecognizer.Point]]
:ivar span: Location of the selection mark in the reading order concatenated
content.
:vartype span: ~azure.ai.formrecognizer.DocumentSpan
Expand Down Expand Up @@ -3012,7 +3017,7 @@ class DocumentStyle:
"""An object representing observed text styles.
:ivar is_handwritten: Is content handwritten?.
:vartype is_handwritten: bool
:vartype is_handwritten: Optional[bool]
:ivar spans: Location of the text elements in the concatenated content the style
applies to.
:vartype spans: list[~azure.ai.formrecognizer.DocumentSpan]
Expand Down Expand Up @@ -3082,7 +3087,7 @@ class DocumentTable:
:ivar cells: Cells contained within the table.
:vartype cells: list[~azure.ai.formrecognizer.DocumentTableCell]
:ivar bounding_regions: Bounding regions covering the table.
:vartype bounding_regions: list[~azure.ai.formrecognizer.BoundingRegion]
:vartype bounding_regions: Optional[list[~azure.ai.formrecognizer.BoundingRegion]]
:ivar spans: Location of the table in the reading order concatenated content.
:vartype spans: list[~azure.ai.formrecognizer.DocumentSpan]
"""
Expand Down Expand Up @@ -3161,19 +3166,19 @@ class DocumentTableCell:
:ivar kind: Table cell kind. Possible values include: "content", "rowHeader", "columnHeader",
"stubHead", "description". Default value: "content".
:vartype kind: str
:vartype kind: Optional[str]
:ivar row_index: Row index of the cell.
:vartype row_index: int
:ivar column_index: Column index of the cell.
:vartype column_index: int
:ivar row_span: Number of rows spanned by this cell.
:vartype row_span: int
:vartype row_span: Optional[int]
:ivar column_span: Number of columns spanned by this cell.
:vartype column_span: int
:vartype column_span: Optional[int]
:ivar content: Concatenated content of the table cell in reading order.
:vartype content: str
:ivar bounding_regions: Bounding regions covering the table cell.
:vartype bounding_regions: list[~azure.ai.formrecognizer.BoundingRegion]
:vartype bounding_regions: Optional[list[~azure.ai.formrecognizer.BoundingRegion]]
:ivar spans: Location of the table cell in the reading order concatenated content.
:vartype spans: list[~azure.ai.formrecognizer.DocumentSpan]
"""
Expand Down Expand Up @@ -3275,7 +3280,7 @@ class ModelOperationInfo:
"failed", "succeeded", "canceled".
:vartype status: str
:ivar percent_completed: Operation progress (0-100).
:vartype percent_completed: int
:vartype percent_completed: Optional[int]
:ivar created_on: Date and time (UTC) when the operation was created.
:vartype created_on: ~datetime.datetime
:ivar last_updated_on: Date and time (UTC) when the operation was last updated.
Expand All @@ -3286,9 +3291,9 @@ class ModelOperationInfo:
:ivar resource_location: URL of the resource targeted by this operation.
:vartype resource_location: str
:ivar api_version: API version used to create this operation.
:vartype api_version: str
:vartype api_version: Optional[str]
:ivar tags: List of user defined key-value tag attributes associated with the model.
:vartype tags: dict[str, str]
:vartype tags: Optional[dict[str, str]]
.. versionadded:: v2022-01-30-preview
The *api_version* and *tags* properties
Expand Down Expand Up @@ -3391,15 +3396,15 @@ class ModelOperation(ModelOperationInfo):
:vartype resource_location: str
:ivar error: Encountered error, includes the error code, message, and details for why
the operation failed.
:vartype error: ~azure.ai.formrecognizer.DocumentAnalysisError
:vartype error: Optional[~azure.ai.formrecognizer.DocumentAnalysisError]
:ivar result: Operation result upon success. Returns a DocumentModelInfo which contains
all information about the model including the doc types
and fields it can analyze from documents.
:vartype result: ~azure.ai.formrecognizer.DocumentModelInfo
:vartype result: Optional[~azure.ai.formrecognizer.DocumentModelInfo]
:ivar api_version: API version used to create this operation.
:vartype api_version: str
:vartype api_version: Optional[str]
:ivar tags: List of user defined key-value tag attributes associated with the model.
:vartype tags: dict[str, str]
:vartype tags: Optional[dict[str, str]]
.. versionadded:: v2022-01-30-preview
The *api_version* and *tags* properties
Expand Down Expand Up @@ -3488,7 +3493,7 @@ class DocumentWord(DocumentContentElement):
:ivar content: Text content of the word.
:vartype content: str
:ivar polygon: Bounding polygon of the word.
:vartype polygon: list[~azure.ai.formrecognizer.Point]
:vartype polygon: Optional[list[~azure.ai.formrecognizer.Point]]
:ivar span: Location of the word in the reading order concatenated content.
:vartype span: ~azure.ai.formrecognizer.DocumentSpan
:ivar confidence: Confidence of correctly extracting the word.
Expand Down Expand Up @@ -3561,21 +3566,21 @@ class AnalyzeResult: # pylint: disable=too-many-instance-attributes
:ivar content: Concatenate string representation of all textual and visual elements
in reading order.
:vartype content: str
:ivar languages: Detected languages in the document.
:vartype languages: list[~azure.ai.formrecognizer.DocumentLanguage]
:ivar pages: Analyzed pages.
:vartype pages: list[~azure.ai.formrecognizer.DocumentPage]
:ivar languages: Detected languages in the document.
:vartype languages: Optional[list[~azure.ai.formrecognizer.DocumentLanguage]]
:ivar paragraphs: Extracted paragraphs.
:vartype paragraphs: list[~azure.ai.formrecognizer.DocumentParagraph]
:vartype paragraphs: Optional[list[~azure.ai.formrecognizer.DocumentParagraph]]
:ivar tables: Extracted tables.
:vartype tables: list[~azure.ai.formrecognizer.DocumentTable]
:vartype tables: Optional[list[~azure.ai.formrecognizer.DocumentTable]]
:ivar key_value_pairs: Extracted key-value pairs.
:vartype key_value_pairs:
list[~azure.ai.formrecognizer.DocumentKeyValuePair]
Optional[list[~azure.ai.formrecognizer.DocumentKeyValuePair]]
:ivar styles: Extracted font styles.
:vartype styles: list[~azure.ai.formrecognizer.DocumentStyle]
:vartype styles: Optional[list[~azure.ai.formrecognizer.DocumentStyle]]
:ivar documents: Extracted documents.
:vartype documents: list[~azure.ai.formrecognizer.AnalyzedDocument]
:vartype documents: Optional[list[~azure.ai.formrecognizer.AnalyzedDocument]]
.. versionadded:: v2022-01-30-preview
The *languages* property
Expand Down Expand Up @@ -3711,13 +3716,13 @@ class DocumentModelSummary:
its description, and when the model was created.
:ivar str model_id: Unique model id.
:ivar str description: A description for the model.
:ivar Optional[str] description: A description for the model.
:ivar created_on: Date and time (UTC) when the model was created.
:vartype created_on: ~datetime.datetime
:ivar api_version: API version used to create this model.
:vartype api_version: str
:vartype api_version: Optional[str]
:ivar tags: List of user defined key-value tag attributes associated with the model.
:vartype tags: dict[str, str]
:vartype tags: Optional[dict[str, str]]
.. versionadded:: v2022-01-30-preview
The *api_version* and *tags* properties
Expand Down Expand Up @@ -3784,15 +3789,15 @@ class DocumentModelInfo(DocumentModelSummary):
"""Document model information. Includes the doc types that the model can analyze.
:ivar str model_id: Unique model id.
:ivar str description: A description for the model.
:ivar Optional[str] description: A description for the model.
:ivar created_on: Date and time (UTC) when the model was created.
:vartype created_on: ~datetime.datetime
:ivar api_version: API version used to create this model.
:vartype api_version: str
:vartype api_version: Optional[str]
:ivar tags: List of user defined key-value tag attributes associated with the model.
:vartype tags: dict[str, str]
:vartype tags: Optional[dict[str, str]]
:ivar doc_types: Supported document types, including the fields for each document and their types.
:vartype doc_types: dict[str, ~azure.ai.formrecognizer.DocTypeInfo]
:vartype doc_types: Optional[dict[str, ~azure.ai.formrecognizer.DocTypeInfo]]
.. versionadded:: v2022-01-30-preview
The *api_version* and *tags* properties
Expand Down Expand Up @@ -3863,14 +3868,14 @@ class DocTypeInfo:
"""DocTypeInfo represents a document type that a model can recognize, including its
fields and types, and the confidence for those fields.
:ivar str description: A description for the model.
:ivar Optional[str] description: A description for the model.
:ivar build_mode: The build mode used when building the custom model.
Possible values include: "template", "neural".
:vartype build_mode: str
:vartype build_mode: Optional[str]
:ivar field_schema: Description of the document semantic schema.
:vartype field_schema: dict[str, Any]
:ivar field_confidence: Estimated confidence for each field.
:vartype field_confidence: dict[str, float]
:vartype field_confidence: Optional[dict[str, float]]
.. versionadded:: v2022-01-30-preview
The *build_mode* property
Expand Down Expand Up @@ -3991,11 +3996,11 @@ class DocumentAnalysisError:
:ivar message: Error message.
:vartype message: str
:ivar target: Target of the error.
:vartype target: str
:vartype target: Optional[str]
:ivar details: List of detailed errors.
:vartype details: list[~azure.ai.formrecognizer.DocumentAnalysisError]
:vartype details: Optional[list[~azure.ai.formrecognizer.DocumentAnalysisError]]
:ivar innererror: Detailed error.
:vartype innererror: ~azure.ai.formrecognizer.DocumentAnalysisInnerError
:vartype innererror: Optional[~azure.ai.formrecognizer.DocumentAnalysisInnerError]
"""

def __init__(
Expand Down Expand Up @@ -4062,9 +4067,9 @@ class DocumentAnalysisInnerError:
:ivar code: Error code.
:vartype code: str
:ivar message: Error message.
:ivar Optional[str] message: Error message.
:ivar innererror: Detailed error.
:vartype innererror: ~azure.ai.formrecognizer.DocumentAnalysisInnerError
:vartype innererror: Optional[~azure.ai.formrecognizer.DocumentAnalysisInnerError]
"""

def __init__(
Expand Down
12 changes: 12 additions & 0 deletions sdk/formrecognizer/azure-ai-formrecognizer/tests/test_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,3 +621,15 @@ def test_currency_value(self):
"$",
)
assert repr(model) == model_repr

def test_currency_value_str(self):
model = _models.CurrencyValue(
amount=10.5,
symbol="$",
)
assert str(model) == "$10.5"

model = _models.CurrencyValue(
amount=10.5,
)
assert str(model) == "10.5"

0 comments on commit 8535cf2

Please sign in to comment.