Skip to content

Commit 4cc9005

Browse files
iscai-msftiscai-msft
andauthored
[python] fix sphinx documentation for errors thrown from methods (microsoft#5640)
fixes Azure/autorest.python#2955 --------- Co-authored-by: iscai-msft <[email protected]>
1 parent 556fa23 commit 4cc9005

File tree

3 files changed

+37
-33
lines changed

3 files changed

+37
-33
lines changed

packages/http-client-python/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 0.6.6
44

5+
### Bug Fixes
6+
7+
- Fix sphinx typing for raising documentation
8+
59
### Other Changes
610

711
- Order keyword-only args overload first in generated operations

packages/http-client-python/generator/pygen/codegen/models/code_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def lookup_type(self, schema_id: int) -> BaseType:
313313
:param int schema_id: The yaml id of the schema
314314
:return: If created, we return the created schema, otherwise, we throw.
315315
:rtype: ~autorest.models.BaseType
316-
:raises: KeyError if schema is not found
316+
:raises KeyError: if schema is not found
317317
"""
318318
try:
319319
return next(type for id, type in self.types_map.items() if id == schema_id)

packages/http-client-python/generator/pygen/codegen/templates/serialization.py.jinja2

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ class Model:
389389
:param str data: A str using RestAPI structure. JSON by default.
390390
:param str content_type: JSON by default, set application/xml if XML.
391391
:returns: An instance of this model
392-
:raises: DeserializationError if something went wrong
392+
:raises DeserializationError: if something went wrong
393393
:rtype: ModelType
394394
"""
395395
deserializer = Deserializer(cls._infer_class_models())
@@ -412,7 +412,7 @@ class Model:
412412
:param function key_extractors: A key extractor function.
413413
:param str content_type: JSON by default, set application/xml if XML.
414414
:returns: An instance of this model
415-
:raises: DeserializationError if something went wrong
415+
:raises DeserializationError: if something went wrong
416416
:rtype: ModelType
417417
"""
418418
deserializer = Deserializer(cls._infer_class_models())
@@ -559,7 +559,7 @@ class Serializer: # pylint: disable=too-many-public-methods
559559
:param object target_obj: The data to be serialized.
560560
:param str data_type: The type to be serialized from.
561561
:rtype: str, dict
562-
:raises: SerializationError if serialization fails.
562+
:raises SerializationError: if serialization fails.
563563
:returns: The serialized data.
564564
"""
565565
key_transformer = kwargs.get("key_transformer", self.key_transformer)
@@ -669,8 +669,8 @@ class Serializer: # pylint: disable=too-many-public-methods
669669
:param object data: The data to be serialized.
670670
:param str data_type: The type to be serialized from.
671671
:rtype: dict
672-
:raises: SerializationError if serialization fails.
673-
:raises: ValueError if data is None
672+
:raises SerializationError: if serialization fails.
673+
:raises ValueError: if data is None
674674
:returns: The serialized request body
675675
"""
676676

@@ -714,8 +714,8 @@ class Serializer: # pylint: disable=too-many-public-methods
714714
:param str data_type: The type to be serialized from.
715715
:rtype: str
716716
:returns: The serialized URL path
717-
:raises: TypeError if serialization fails.
718-
:raises: ValueError if data is None
717+
:raises TypeError: if serialization fails.
718+
:raises ValueError: if data is None
719719
"""
720720
try:
721721
output = self.serialize_data(data, data_type, **kwargs)
@@ -738,8 +738,8 @@ class Serializer: # pylint: disable=too-many-public-methods
738738
:param object data: The data to be serialized.
739739
:param str data_type: The type to be serialized from.
740740
:rtype: str, list
741-
:raises: TypeError if serialization fails.
742-
:raises: ValueError if data is None
741+
:raises TypeError: if serialization fails.
742+
:raises ValueError: if data is None
743743
:returns: The serialized query parameter
744744
"""
745745
try:
@@ -768,8 +768,8 @@ class Serializer: # pylint: disable=too-many-public-methods
768768
:param object data: The data to be serialized.
769769
:param str data_type: The type to be serialized from.
770770
:rtype: str
771-
:raises: TypeError if serialization fails.
772-
:raises: ValueError if data is None
771+
:raises TypeError: if serialization fails.
772+
:raises ValueError: if data is None
773773
:returns: The serialized header
774774
"""
775775
try:
@@ -788,9 +788,9 @@ class Serializer: # pylint: disable=too-many-public-methods
788788

789789
:param object data: The data to be serialized.
790790
:param str data_type: The type to be serialized from.
791-
:raises: AttributeError if required data is None.
792-
:raises: ValueError if data is None
793-
:raises: SerializationError if serialization fails.
791+
:raises AttributeError: if required data is None.
792+
:raises ValueError: if data is None
793+
:raises SerializationError: if serialization fails.
794794
:returns: The serialized data.
795795
:rtype: str, int, float, bool, dict, list
796796
"""
@@ -1125,7 +1125,7 @@ class Serializer: # pylint: disable=too-many-public-methods
11251125

11261126
:param Datetime attr: Object to be serialized.
11271127
:rtype: str
1128-
:raises: TypeError if format invalid.
1128+
:raises TypeError: if format invalid.
11291129
:return: serialized rfc
11301130
"""
11311131
try:
@@ -1151,7 +1151,7 @@ class Serializer: # pylint: disable=too-many-public-methods
11511151

11521152
:param Datetime attr: Object to be serialized.
11531153
:rtype: str
1154-
:raises: SerializationError if format invalid.
1154+
:raises SerializationError: if format invalid.
11551155
:return: serialized iso
11561156
"""
11571157
if isinstance(attr, str):
@@ -1184,7 +1184,7 @@ class Serializer: # pylint: disable=too-many-public-methods
11841184

11851185
:param Datetime attr: Object to be serialized.
11861186
:rtype: int
1187-
:raises: SerializationError if format invalid
1187+
:raises SerializationError: if format invalid
11881188
:return: serialied unix
11891189
"""
11901190
if isinstance(attr, int):
@@ -1421,7 +1421,7 @@ class Deserializer:
14211421
:param str target_obj: Target data type to deserialize to.
14221422
:param requests.Response response_data: REST response object.
14231423
:param str content_type: Swagger "produces" if available.
1424-
:raises: DeserializationError if deserialization fails.
1424+
:raises DeserializationError: if deserialization fails.
14251425
:return: Deserialized object.
14261426
:rtype: object
14271427
"""
@@ -1435,7 +1435,7 @@ class Deserializer:
14351435

14361436
:param str target_obj: Target data type to deserialize to.
14371437
:param object data: Object to deserialize.
1438-
:raises: DeserializationError if deserialization fails.
1438+
:raises DeserializationError: if deserialization fails.
14391439
:return: Deserialized object.
14401440
:rtype: object
14411441
"""
@@ -1650,7 +1650,7 @@ class Deserializer:
16501650

16511651
:param str data: The response string to be deserialized.
16521652
:param str data_type: The type to deserialize to.
1653-
:raises: DeserializationError if deserialization fails.
1653+
:raises DeserializationError: if deserialization fails.
16541654
:return: Deserialized object.
16551655
:rtype: object
16561656
"""
@@ -1732,7 +1732,7 @@ class Deserializer:
17321732
:param dict attr: Dictionary to be deserialized.
17331733
:return: Deserialized object.
17341734
:rtype: dict
1735-
:raises: TypeError if non-builtin datatype encountered.
1735+
:raises TypeError: if non-builtin datatype encountered.
17361736
"""
17371737
if attr is None:
17381738
return None
@@ -1778,7 +1778,7 @@ class Deserializer:
17781778
:param str data_type: deserialization data type.
17791779
:return: Deserialized basic type.
17801780
:rtype: str, int, float or bool
1781-
:raises: TypeError if string format is not valid.
1781+
:raises TypeError: if string format is not valid.
17821782
"""
17831783
# If we're here, data is supposed to be a basic type.
17841784
# If it's still an XML node, take the text
@@ -1869,7 +1869,7 @@ class Deserializer:
18691869
:param str attr: response string to be deserialized.
18701870
:return: Deserialized bytearray
18711871
:rtype: bytearray
1872-
:raises: TypeError if string format invalid.
1872+
:raises TypeError: if string format invalid.
18731873
"""
18741874
if isinstance(attr, ET.Element):
18751875
attr = attr.text
@@ -1882,7 +1882,7 @@ class Deserializer:
18821882
:param str attr: response string to be deserialized.
18831883
:return: Deserialized base64 string
18841884
:rtype: bytearray
1885-
:raises: TypeError if string format invalid.
1885+
:raises TypeError: if string format invalid.
18861886
"""
18871887
if isinstance(attr, ET.Element):
18881888
attr = attr.text
@@ -1897,7 +1897,7 @@ class Deserializer:
18971897

18981898
:param str attr: response string to be deserialized.
18991899
:return: Deserialized decimal
1900-
:raises: DeserializationError if string format invalid.
1900+
:raises DeserializationError: if string format invalid.
19011901
:rtype: decimal
19021902
"""
19031903
if isinstance(attr, ET.Element):
@@ -1915,7 +1915,7 @@ class Deserializer:
19151915
:param str attr: response string to be deserialized.
19161916
:return: Deserialized int
19171917
:rtype: long or int
1918-
:raises: ValueError if string format invalid.
1918+
:raises ValueError: if string format invalid.
19191919
"""
19201920
if isinstance(attr, ET.Element):
19211921
attr = attr.text
@@ -1928,7 +1928,7 @@ class Deserializer:
19281928
:param str attr: response string to be deserialized.
19291929
:return: Deserialized duration
19301930
:rtype: TimeDelta
1931-
:raises: DeserializationError if string format invalid.
1931+
:raises DeserializationError: if string format invalid.
19321932
"""
19331933
if isinstance(attr, ET.Element):
19341934
attr = attr.text
@@ -1946,7 +1946,7 @@ class Deserializer:
19461946
:param str attr: response string to be deserialized.
19471947
:return: Deserialized date
19481948
:rtype: Date
1949-
:raises: DeserializationError if string format invalid.
1949+
:raises DeserializationError: if string format invalid.
19501950
"""
19511951
if isinstance(attr, ET.Element):
19521952
attr = attr.text
@@ -1962,7 +1962,7 @@ class Deserializer:
19621962
:param str attr: response string to be deserialized.
19631963
:return: Deserialized time
19641964
:rtype: datetime.time
1965-
:raises: DeserializationError if string format invalid.
1965+
:raises DeserializationError: if string format invalid.
19661966
"""
19671967
if isinstance(attr, ET.Element):
19681968
attr = attr.text
@@ -1977,7 +1977,7 @@ class Deserializer:
19771977
:param str attr: response string to be deserialized.
19781978
:return: Deserialized RFC datetime
19791979
:rtype: Datetime
1980-
:raises: DeserializationError if string format invalid.
1980+
:raises DeserializationError: if string format invalid.
19811981
"""
19821982
if isinstance(attr, ET.Element):
19831983
attr = attr.text
@@ -2000,7 +2000,7 @@ class Deserializer:
20002000
:param str attr: response string to be deserialized.
20012001
:return: Deserialized ISO datetime
20022002
:rtype: Datetime
2003-
:raises: DeserializationError if string format invalid.
2003+
:raises DeserializationError: if string format invalid.
20042004
"""
20052005
if isinstance(attr, ET.Element):
20062006
attr = attr.text
@@ -2038,7 +2038,7 @@ class Deserializer:
20382038
:param int attr: Object to be serialized.
20392039
:return: Deserialized datetime
20402040
:rtype: Datetime
2041-
:raises: DeserializationError if format invalid
2041+
:raises DeserializationError: if format invalid
20422042
"""
20432043
if isinstance(attr, ET.Element):
20442044
attr = int(attr.text) # type: ignore

0 commit comments

Comments
 (0)