Skip to content

Commit 6b1984c

Browse files
author
Yalin Li
authored
[DocumentIntelligence] Generate from the latest typespec with service API 2024-02-29-preview (#34564)
1 parent e0179c5 commit 6b1984c

26 files changed

+1349
-1533
lines changed

sdk/documentintelligence/azure-ai-documentintelligence/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
### Features Added
66

7+
- Added model `AnalyzeResultOperation` and `Warning`.
8+
- Added property `base_classifier_id` to model `BuildDocumentClassifierRequest`.
9+
- Added property `base_classifier_id` and `warnings` to model `DocumentClassifierDetails`.
10+
- Added property `warnings` to model `DocumentModelDetails`.
11+
- Added property `value_selection_group` to model `DocumentField`.
12+
- Added value `selectionGroup` to enum `DocumentFieldType`.
13+
- Added value `completed` to enum `OperationStatus`.
14+
715
### Breaking Changes
816

917
- Changed property name from `items` to `items_property` in model `DocumentFieldSchema` and `DocumentList`.
@@ -13,6 +21,9 @@
1321
### Other Changes
1422

1523
- Changed the default polling interval from 30s to 5s.
24+
- Changed the default service API version to `2024-02-29-preview`.
25+
- Bumped minimum dependency on `azure-core` to `>=1.30.0`.
26+
- Bumped minimum dependency on `typing-extensions` to `>=4.6.0`.
1627
- Python 3.7 is no longer supported. Please use Python version 3.8 or later.
1728

1829
## 1.0.0b1 (2023-11-17)

sdk/documentintelligence/azure-ai-documentintelligence/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,10 @@ print(f"\nModel ID: {my_model.model_id}")
575575
print(f"Description: {my_model.description}")
576576
print(f"Model created on: {my_model.created_date_time}")
577577
print(f"Model expires on: {my_model.expiration_date_time}")
578+
if my_model.warnings:
579+
print("Warnings encountered while building the model:")
580+
for warning in my_model.warnings:
581+
print(f"warning code: {warning.code}, message: {warning.message}, target of the error: {warning.target}")
578582
```
579583

580584
<!-- END SNIPPET -->

sdk/documentintelligence/azure-ai-documentintelligence/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/documentintelligence/azure-ai-documentintelligence",
5-
"Tag": "python/documentintelligence/azure-ai-documentintelligence_3a7d15d3b0"
5+
"Tag": "python/documentintelligence/azure-ai-documentintelligence_a54f07ab98"
66
}

sdk/documentintelligence/azure-ai-documentintelligence/azure/ai/documentintelligence/_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class DocumentIntelligenceClient(
4141
:type credential: ~azure.core.credentials.AzureKeyCredential or
4242
~azure.core.credentials.TokenCredential
4343
:keyword api_version: The API version to use for this operation. Default value is
44-
"2023-10-31-preview". Note that overriding this default value may result in unsupported
44+
"2024-02-29-preview". Note that overriding this default value may result in unsupported
4545
behavior.
4646
:paramtype api_version: str
4747
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
@@ -123,7 +123,7 @@ class DocumentIntelligenceAdministrationClient(
123123
:type credential: ~azure.core.credentials.AzureKeyCredential or
124124
~azure.core.credentials.TokenCredential
125125
:keyword api_version: The API version to use for this operation. Default value is
126-
"2023-10-31-preview". Note that overriding this default value may result in unsupported
126+
"2024-02-29-preview". Note that overriding this default value may result in unsupported
127127
behavior.
128128
:paramtype api_version: str
129129
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no

sdk/documentintelligence/azure-ai-documentintelligence/azure/ai/documentintelligence/_configuration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ class DocumentIntelligenceClientConfiguration: # pylint: disable=too-many-insta
3131
:type credential: ~azure.core.credentials.AzureKeyCredential or
3232
~azure.core.credentials.TokenCredential
3333
:keyword api_version: The API version to use for this operation. Default value is
34-
"2023-10-31-preview". Note that overriding this default value may result in unsupported
34+
"2024-02-29-preview". Note that overriding this default value may result in unsupported
3535
behavior.
3636
:paramtype api_version: str
3737
"""
3838

3939
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
40-
api_version: str = kwargs.pop("api_version", "2023-10-31-preview")
40+
api_version: str = kwargs.pop("api_version", "2024-02-29-preview")
4141

4242
if endpoint is None:
4343
raise ValueError("Parameter 'endpoint' must not be None.")
@@ -86,13 +86,13 @@ class DocumentIntelligenceAdministrationClientConfiguration: # pylint: disable=
8686
:type credential: ~azure.core.credentials.AzureKeyCredential or
8787
~azure.core.credentials.TokenCredential
8888
:keyword api_version: The API version to use for this operation. Default value is
89-
"2023-10-31-preview". Note that overriding this default value may result in unsupported
89+
"2024-02-29-preview". Note that overriding this default value may result in unsupported
9090
behavior.
9191
:paramtype api_version: str
9292
"""
9393

9494
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
95-
api_version: str = kwargs.pop("api_version", "2023-10-31-preview")
95+
api_version: str = kwargs.pop("api_version", "2024-02-29-preview")
9696

9797
if endpoint is None:
9898
raise ValueError("Parameter 'endpoint' must not be None.")

sdk/documentintelligence/azure-ai-documentintelligence/azure/ai/documentintelligence/_model_base.py

Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# license information.
66
# --------------------------------------------------------------------------
77
# pylint: disable=protected-access, arguments-differ, signature-differs, broad-except
8-
# pyright: reportGeneralTypeIssues=false
98

109
import calendar
1110
import decimal
@@ -16,9 +15,11 @@
1615
import re
1716
import copy
1817
import typing
19-
import email
18+
import enum
19+
import email.utils
2020
from datetime import datetime, date, time, timedelta, timezone
2121
from json import JSONEncoder
22+
from typing_extensions import Self
2223
import isodate
2324
from azure.core.exceptions import DeserializationError
2425
from azure.core import CaseInsensitiveEnumMeta
@@ -35,6 +36,7 @@
3536
__all__ = ["SdkJSONEncoder", "Model", "rest_field", "rest_discriminator"]
3637

3738
TZ_UTC = timezone.utc
39+
_T = typing.TypeVar("_T")
3840

3941

4042
def _timedelta_as_isostr(td: timedelta) -> str:
@@ -242,7 +244,7 @@ def _deserialize_date(attr: typing.Union[str, date]) -> date:
242244
# This must NOT use defaultmonth/defaultday. Using None ensure this raises an exception.
243245
if isinstance(attr, date):
244246
return attr
245-
return isodate.parse_date(attr, defaultmonth=None, defaultday=None)
247+
return isodate.parse_date(attr, defaultmonth=None, defaultday=None) # type: ignore
246248

247249

248250
def _deserialize_time(attr: typing.Union[str, time]) -> time:
@@ -375,8 +377,12 @@ def get(self, key: str, default: typing.Any = None) -> typing.Any:
375377
except KeyError:
376378
return default
377379

378-
@typing.overload # type: ignore
379-
def pop(self, key: str) -> typing.Any: # pylint: disable=no-member
380+
@typing.overload
381+
def pop(self, key: str) -> typing.Any:
382+
...
383+
384+
@typing.overload
385+
def pop(self, key: str, default: _T) -> _T:
380386
...
381387

382388
@typing.overload
@@ -397,8 +403,8 @@ def clear(self) -> None:
397403
def update(self, *args: typing.Any, **kwargs: typing.Any) -> None:
398404
self._data.update(*args, **kwargs)
399405

400-
@typing.overload # type: ignore
401-
def setdefault(self, key: str) -> typing.Any:
406+
@typing.overload
407+
def setdefault(self, key: str, default: None = None) -> None:
402408
...
403409

404410
@typing.overload
@@ -438,6 +444,8 @@ def _serialize(o, format: typing.Optional[str] = None): # pylint: disable=too-m
438444
return _serialize_bytes(o, format)
439445
if isinstance(o, decimal.Decimal):
440446
return float(o)
447+
if isinstance(o, enum.Enum):
448+
return o.value
441449
try:
442450
# First try datetime.datetime
443451
return _serialize_datetime(o, format)
@@ -462,7 +470,13 @@ def _get_rest_field(
462470

463471

464472
def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any:
465-
return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None)
473+
if not rf:
474+
return _serialize(value, None)
475+
if rf._is_multipart_file_input:
476+
return value
477+
if rf._is_model:
478+
return _deserialize(rf._type, value)
479+
return _serialize(value, rf._format)
466480

467481

468482
class Model(_MyMutableMapping):
@@ -498,7 +512,7 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
498512
def copy(self) -> "Model":
499513
return Model(self.__dict__)
500514

501-
def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> "Model": # pylint: disable=unused-argument
515+
def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Self: # pylint: disable=unused-argument
502516
# we know the last three classes in mro are going to be 'Model', 'dict', and 'object'
503517
mros = cls.__mro__[:-3][::-1] # ignore model, dict, and object parents, and reverse the mro order
504518
attr_to_rest_field: typing.Dict[str, _RestField] = { # map attribute name to rest_field property
@@ -540,7 +554,7 @@ def _deserialize(cls, data, exist_discriminators):
540554
return cls(data)
541555
discriminator = cls._get_discriminator(exist_discriminators)
542556
exist_discriminators.append(discriminator)
543-
mapped_cls = cls.__mapping__.get(data.get(discriminator), cls) # pylint: disable=no-member
557+
mapped_cls = cls.__mapping__.get(data.get(discriminator), cls) # pyright: ignore # pylint: disable=no-member
544558
if mapped_cls == cls:
545559
return cls(data)
546560
return mapped_cls._deserialize(data, exist_discriminators) # pylint: disable=protected-access
@@ -557,17 +571,24 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing.
557571
if exclude_readonly:
558572
readonly_props = [p._rest_name for p in self._attr_to_rest_field.values() if _is_readonly(p)]
559573
for k, v in self.items():
560-
if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable]
574+
if exclude_readonly and k in readonly_props: # pyright: ignore
561575
continue
562-
result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly)
576+
is_multipart_file_input = False
577+
try:
578+
is_multipart_file_input = next(
579+
rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k
580+
)._is_multipart_file_input
581+
except StopIteration:
582+
pass
583+
result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly)
563584
return result
564585

565586
@staticmethod
566587
def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any:
567588
if v is None or isinstance(v, _Null):
568589
return None
569590
if isinstance(v, (list, tuple, set)):
570-
return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v]
591+
return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v)
571592
if isinstance(v, dict):
572593
return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()}
573594
return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v
@@ -605,29 +626,22 @@ def _deserialize_model(model_deserializer: typing.Optional[typing.Callable], obj
605626
return obj
606627
return _deserialize(model_deserializer, obj)
607628

608-
return functools.partial(_deserialize_model, annotation)
629+
return functools.partial(_deserialize_model, annotation) # pyright: ignore
609630
except Exception:
610631
pass
611632

612633
# is it a literal?
613634
try:
614-
if sys.version_info >= (3, 8):
615-
from typing import (
616-
Literal,
617-
) # pylint: disable=no-name-in-module, ungrouped-imports
618-
else:
619-
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports
620-
621-
if annotation.__origin__ == Literal:
635+
if annotation.__origin__ is typing.Literal: # pyright: ignore
622636
return None
623637
except AttributeError:
624638
pass
625639

626640
# is it optional?
627641
try:
628-
if any(a for a in annotation.__args__ if a == type(None)):
642+
if any(a for a in annotation.__args__ if a == type(None)): # pyright: ignore
629643
if_obj_deserializer = _get_deserialize_callable_from_annotation(
630-
next(a for a in annotation.__args__ if a != type(None)), module, rf
644+
next(a for a in annotation.__args__ if a != type(None)), module, rf # pyright: ignore
631645
)
632646

633647
def _deserialize_with_optional(if_obj_deserializer: typing.Optional[typing.Callable], obj):
@@ -640,7 +654,13 @@ def _deserialize_with_optional(if_obj_deserializer: typing.Optional[typing.Calla
640654
pass
641655

642656
if getattr(annotation, "__origin__", None) is typing.Union:
643-
deserializers = [_get_deserialize_callable_from_annotation(arg, module, rf) for arg in annotation.__args__]
657+
# initial ordering is we make `string` the last deserialization option, because it is often them most generic
658+
deserializers = [
659+
_get_deserialize_callable_from_annotation(arg, module, rf)
660+
for arg in sorted(
661+
annotation.__args__, key=lambda x: hasattr(x, "__name__") and x.__name__ == "str" # pyright: ignore
662+
)
663+
]
644664

645665
def _deserialize_with_union(deserializers, obj):
646666
for deserializer in deserializers:
@@ -653,8 +673,10 @@ def _deserialize_with_union(deserializers, obj):
653673
return functools.partial(_deserialize_with_union, deserializers)
654674

655675
try:
656-
if annotation._name == "Dict":
657-
value_deserializer = _get_deserialize_callable_from_annotation(annotation.__args__[1], module, rf)
676+
if annotation._name == "Dict": # pyright: ignore
677+
value_deserializer = _get_deserialize_callable_from_annotation(
678+
annotation.__args__[1], module, rf # pyright: ignore
679+
)
658680

659681
def _deserialize_dict(
660682
value_deserializer: typing.Optional[typing.Callable],
@@ -671,8 +693,8 @@ def _deserialize_dict(
671693
except (AttributeError, IndexError):
672694
pass
673695
try:
674-
if annotation._name in ["List", "Set", "Tuple", "Sequence"]:
675-
if len(annotation.__args__) > 1:
696+
if annotation._name in ["List", "Set", "Tuple", "Sequence"]: # pyright: ignore
697+
if len(annotation.__args__) > 1: # pyright: ignore
676698

677699
def _deserialize_multiple_sequence(
678700
entry_deserializers: typing.List[typing.Optional[typing.Callable]],
@@ -686,10 +708,13 @@ def _deserialize_multiple_sequence(
686708
)
687709

688710
entry_deserializers = [
689-
_get_deserialize_callable_from_annotation(dt, module, rf) for dt in annotation.__args__
711+
_get_deserialize_callable_from_annotation(dt, module, rf)
712+
for dt in annotation.__args__ # pyright: ignore
690713
]
691714
return functools.partial(_deserialize_multiple_sequence, entry_deserializers)
692-
deserializer = _get_deserialize_callable_from_annotation(annotation.__args__[0], module, rf)
715+
deserializer = _get_deserialize_callable_from_annotation(
716+
annotation.__args__[0], module, rf # pyright: ignore
717+
)
693718

694719
def _deserialize_sequence(
695720
deserializer: typing.Optional[typing.Callable],
@@ -769,6 +794,7 @@ def __init__(
769794
visibility: typing.Optional[typing.List[str]] = None,
770795
default: typing.Any = _UNSET,
771796
format: typing.Optional[str] = None,
797+
is_multipart_file_input: bool = False,
772798
):
773799
self._type = type
774800
self._rest_name_input = name
@@ -778,6 +804,11 @@ def __init__(
778804
self._is_model = False
779805
self._default = default
780806
self._format = format
807+
self._is_multipart_file_input = is_multipart_file_input
808+
809+
@property
810+
def _class_type(self) -> typing.Any:
811+
return getattr(self._type, "args", [None])[0]
781812

782813
@property
783814
def _rest_name(self) -> str:
@@ -823,8 +854,16 @@ def rest_field(
823854
visibility: typing.Optional[typing.List[str]] = None,
824855
default: typing.Any = _UNSET,
825856
format: typing.Optional[str] = None,
857+
is_multipart_file_input: bool = False,
826858
) -> typing.Any:
827-
return _RestField(name=name, type=type, visibility=visibility, default=default, format=format)
859+
return _RestField(
860+
name=name,
861+
type=type,
862+
visibility=visibility,
863+
default=default,
864+
format=format,
865+
is_multipart_file_input=is_multipart_file_input,
866+
)
828867

829868

830869
def rest_discriminator(

0 commit comments

Comments
 (0)