python: several typing and style improvements (#16378)

* python: several typing and style improvements

The generated (python) code fails with several standard validation tools,
including `flake8`, `mypy`, and `autoflake`. While fixing every possible
violation -- especially wrto typing -- woudl be a project, some of the
changes are fairly easy.

 - The `autoflake` tool picks up on unused imports. These can just be removed.

 - The `mypy` tool picks up on numerious typing violations, especially if set
   to its strictest mode. As a starting point, all functions ought to annotate
   a return type, including constructors, even if the return type is `None`
   because otherwise the functions are omitted from type checking and it's
   impossible to make incremental progress towards adding types.

 - The `flake8` tool mostly finds whitespace and line-length issues; while
   line-length standards very, the source already includes several flake8
   ignores, so it seems safe to add a few more.

* Add generated files

* Restore imports used by `AbstractPythonCodegen.java`

* Update generated files
This commit is contained in:
jessemyers-lettuce
2023-09-01 10:03:02 -07:00
committed by GitHub
parent c0abeceb85
commit 40731ed52d
61 changed files with 910 additions and 807 deletions

View File

@@ -19,7 +19,7 @@ class OpenApiException(Exception):
class ApiTypeError(OpenApiException, TypeError):
def __init__(self, msg, path_to_item=None, valid_classes=None,
key_type=None):
key_type=None) -> None:
""" Raises an exception for TypeErrors
Args:
@@ -47,7 +47,7 @@ class ApiTypeError(OpenApiException, TypeError):
class ApiValueError(OpenApiException, ValueError):
def __init__(self, msg, path_to_item=None):
def __init__(self, msg, path_to_item=None) -> None:
"""
Args:
msg (str): the exception message
@@ -65,7 +65,7 @@ class ApiValueError(OpenApiException, ValueError):
class ApiAttributeError(OpenApiException, AttributeError):
def __init__(self, msg, path_to_item=None):
def __init__(self, msg, path_to_item=None) -> None:
"""
Raised when an attribute reference or assignment fails.
@@ -84,7 +84,7 @@ class ApiAttributeError(OpenApiException, AttributeError):
class ApiKeyError(OpenApiException, KeyError):
def __init__(self, msg, path_to_item=None):
def __init__(self, msg, path_to_item=None) -> None:
"""
Args:
msg (str): the exception message
@@ -102,7 +102,7 @@ class ApiKeyError(OpenApiException, KeyError):
class ApiException(OpenApiException):
def __init__(self, status=None, reason=None, http_resp=None):
def __init__(self, status=None, reason=None, http_resp=None) -> None:
if http_resp:
self.status = http_resp.status
self.reason = http_resp.reason
@@ -129,30 +129,30 @@ class ApiException(OpenApiException):
class BadRequestException(ApiException):
def __init__(self, status=None, reason=None, http_resp=None):
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(BadRequestException, self).__init__(status, reason, http_resp)
class NotFoundException(ApiException):
def __init__(self, status=None, reason=None, http_resp=None):
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(NotFoundException, self).__init__(status, reason, http_resp)
class UnauthorizedException(ApiException):
def __init__(self, status=None, reason=None, http_resp=None):
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(UnauthorizedException, self).__init__(status, reason, http_resp)
class ForbiddenException(ApiException):
def __init__(self, status=None, reason=None, http_resp=None):
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(ForbiddenException, self).__init__(status, reason, http_resp)
class ServiceException(ApiException):
def __init__(self, status=None, reason=None, http_resp=None):
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(ServiceException, self).__init__(status, reason, http_resp)