[python-experimental] Raise builtin AttributeError instead of custom ApiKeyError (#6229)

* Use AttributeError instead of ApiKeyError because that's what the hasattr builtin function uses

* Use AttributeError instead of ApiKeyError because that's what the hasattr builtin function uses

* fix unit tests

* create ApiAttributeError exception

* fix formatting

* run samples scripts
This commit is contained in:
Sebastien Rosset
2020-05-10 19:02:41 -07:00
committed by GitHub
parent 44b51a136f
commit fa37a696a8
24 changed files with 237 additions and 55 deletions

View File

@@ -31,6 +31,7 @@ from petstore_api.exceptions import OpenApiException
from petstore_api.exceptions import ApiTypeError
from petstore_api.exceptions import ApiValueError
from petstore_api.exceptions import ApiKeyError
from petstore_api.exceptions import ApiAttributeError
from petstore_api.exceptions import ApiException
# import models into sdk package
from petstore_api.models.additional_properties_any_type import AdditionalPropertiesAnyType

View File

@@ -64,6 +64,25 @@ class ApiValueError(OpenApiException, ValueError):
super(ApiValueError, self).__init__(full_msg)
class ApiAttributeError(OpenApiException, AttributeError):
def __init__(self, msg, path_to_item=None):
"""
Raised when an attribute reference or assignment fails.
Args:
msg (str): the exception message
Keyword Args:
path_to_item (None/list) the path to the exception in the
received_data dict
"""
self.path_to_item = path_to_item
full_msg = msg
if path_to_item:
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
super(ApiAttributeError, self).__init__(full_msg)
class ApiKeyError(OpenApiException, KeyError):
def __init__(self, msg, path_to_item=None):
"""